Skip to content Skip to sidebar Skip to footer

Sqlalchemy Add Comment To Every Query

I'm trying to make SQLAlchemy add a comment to every single query that I'm submitting. I know from the docs I can do something like this: from sqlalchemy.sql.expression import Ins

Solution 1:

I would use events. There is an example in SQLAlchemy documentation:

from sqlalchemy.engine import Engine
from sqlalchemy import event

@event.listens_for(Engine, "before_cursor_execute", retval=True)
def comment_sql_calls(conn, cursor, statement, parameters,
                                    context, executemany):
    statement = statement + " -- some comment"
    return statement, parameters

Post a Comment for "Sqlalchemy Add Comment To Every Query"