Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Basic go-pg SQL Comments #1914

Unanswered
firesidemdb asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 1 comment

Comment options

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()

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /