Replies: 1 comment 1 reply
-
How would someone construct a query? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey @gajus - an idea I've been mulling over that I think could fit nicely into slonik is an ability to "name" queries. Honeycomb have written a good blog about some of the advantages: Show your query you love it by naming it. It enables recording performance metrics for a given query easily, even if the query itself changes over time - which would complicate any automatic query id generation techniques.
The change in slonik would be very small:
export type SqlSqlTokenType = { readonly sql: string, readonly type: typeof tokens.SqlToken, readonly values: readonly PrimitiveValueExpressionType[], + readonly name?: string };
Then the
name
property could be passed toexecuteQuery
and added tooriginalQuery
so it reaches the various interceptors:const originalQuery = { sql: rawSql, values, + name, };
From there end-users can do what they like with it, including logging timing/success metrics, etc.
To use it, there could be a helper function:
With that in place, it may be possible to do some clever stuff using @slonik/typegen to infer the correct type based on the name.
I'd be happy to open a PR along those lines if you'd be open to it?
Beta Was this translation helpful? Give feedback.
All reactions