Exposed
Exposed copied to clipboard
Support for sqlcommenter
I'm interested in feedback on whether this could be done, likely as a plugin or related library.
https://google.github.io/sqlcommenter/ https://cloud.google.com/sql/docs/postgres/using-query-insights#adding-tags-to-sql-queries
Sqlcomenter is a specification out of Google that their CloudSQL databases process, and allows tagged metadata to be included in queries, for things like tracing and performance management. Functionally it is adding comments to the sql queries, in a similar way to how logback can pull metadata from the logging context.
Its supported in Spring/Hibernate, but I don't know how difficult or desirable to have it available in Exposed.
This could be done in similar way, as in https://github.com/JetBrains/Exposed/issues/632 – through interceptors. But interceptors can not modify sql statement, which is needed by sqlcommenter
to insert comment at the end of the query.
Other way is to inject sql comment into Query
object, but it hard to wrap it into proxy object, because some fields (namely groupedByColumns
, having
, forUpdate
and where
) have private setters. But if they were protected (like distinct
) – then we could define extension function comment
, that returns TracedQuery
with overriden prepareSQL
.
I would love to hear back from maintainers – is it possible to add such functionality in Exposed?
Both these approaches will become possible in upcoming version 0.53.0.
A new extension function comment()
has been added to the Query
class in PR #2088 .
And the Query
class has been made more extensible by making copyTo()
public in PR #2173 . An example of how this can be taken advantage of will be added to the site documentation, which will be synced with the upcoming release.