Is it possible to add comments to all queries? #2167
zom-yoshidan
started this conversation in
General
Replies: 1 comment 3 replies
-
I recommend using Database#with_comments for this: DB = Sequel.connect(opts)
DB.extension :sql_comments
DB.with_comments('trace_id'=>'foo') do
DB.fetch('SELECT 1 AS v')
end
# SELECT 1 AS v -- trace_id:foo |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my product, we use Sequel to access Postgres, and this product is running on Kubernetes. We are trying to embed traceparent as a comment in every SQL statement for distributed tracing.
However, unfortunately, the usage of Sequel is not unified among the multiple developers, and in some code, the model is used, in some code, SQL is written to a file and read, and in some code, Dataset is used.
For example, as follows:
These are all written in separate files, so dealing with each one individually takes a significant amount of time.
But the requirement to add comments is the same for any pattern.
Is there any method to ensure comments are always added in any case?
What I tried
I created a class to override the behavior of the connection, calling comment every time right before calling something of Dataset.
However, we abandoned this method because when calling dataset.limit(limit, offset).all, sql became nil.
What I readed
Beta Was this translation helpful? Give feedback.
All reactions