-
-
Notifications
You must be signed in to change notification settings - Fork 415
Add Basic go-pg SQL Comments #1914
-
Looking for the final produced query to include some basic SQL comments.
SELECT * FROM blah /* table: blah, queryName: getAllBlahs */
This is used with several performance tools to track source of queries. Is go-pg capable of this?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I know this conversation has been stale for nearly a year, but just in case anybody else stumbles upon this looking for a workaround, I managed to come up with the following:
Basically, I'm adding a zero cost, or as close to zero cost as possible, arbitrary clause to my queries in order to give me a "spot" to inject my comments:
For selects, updates & deletes, you can add a where true /* comment goes here*/
. E.g.
res, err := db.Model(&Model{}).Where("column = ?", value).Where("true /*action=delete,controller=controller,framework=go-pg,application=my-application*/").Delete()
For inserts, the best I can come up with is using the Returning("*")
clause, which I'm pretty sure is not zero-cost, but it's a clause that we happen to be using in almost every case anyways, so no real harm done for us:
res, err := db.Model(&Model{}).Returning("* /*action=create,controller=controller,framework=go-pg,application=my-application*/").Insert()
Beta Was this translation helpful? Give feedback.