This change proposes a new Comment(string) method and ContextWithComment(context.Context, string) function for prepending a comment to a SQL query.
Here's simple example:
// using the query API
err := db.NewSelect().
Model(&products).
Where("description like ?", d).
Comment("customer:"+customerID).
Scan(ctx)
// using a context
qctx := bun.ContextWithComment(ctx, "customer:"+customerID)
err := db.NewSelect().
Model(&products).
Where("description LIKE ?", d).
Scan(qctx)
This would produce a query that looks like:
/*customer:01J1P97P3AP7V287B57P7055CZ*/ SELECT * FROM products WHERE description LIKE '%red%'
This may warrant a bit of discussion first, but I wanted to include the code with the proposal. I have had this code running in production since April with no problems. It appears that others may be interested in this as well: https://github.com/uptrace/bun/issues/998
My immediate use case for this is to add a comment to a query with tracing/debug information that will show up in the process list/pg_stat_activity, but there are certainly other uses for this functionality.
This change proposes a new
Comment(string)
method andContextWithComment(context.Context, string)
function for prepending a comment to a SQL query.Here's simple example:
This would produce a query that looks like:
This may warrant a bit of discussion first, but I wanted to include the code with the proposal. I have had this code running in production since April with no problems. It appears that others may be interested in this as well: https://github.com/uptrace/bun/issues/998
My immediate use case for this is to add a comment to a query with tracing/debug information that will show up in the process list/
pg_stat_activity
, but there are certainly other uses for this functionality.