K
Kysely•2y ago
Gaspero

Advice on building plugin for working with parameters

I am currently working on a driver for YDB https://github.com/Gaspero/kysely-ydb YDB dialect expects query parameters to be explicitly declared as a part of the query using DECLARE statement (reference https://ydb.tech/en/docs/yql/reference/syntax/declare ) I want to build a custom plugin that would automatically add DECLARE statements for each parameter in query Take a look at the following example query https://kyse.link/?p=s&i=lEJ4rdYMqPWYE5jrEcQE Expected output would be: DECLARE $1 AS String; DECLARE $2 AS String; DECLARE $3 AS String; SELECT "id", "last_name" FROM "user" WHERE "id" IN ($1, $2, $3) *Please ignore type differences between native JS objects and database types. This is out of the scope of the question. I have checked https://github.com/kysely-org/kysely/tree/master/src/plugin as reference and read documentation but could not figure out how I could access query parameters from OperationNodeTransformer instance. Could you please give me some advice?
GitHub
GitHub - Gaspero/kysely-ydb
Contribute to Gaspero/kysely-ydb development by creating an account on GitHub.
DECLARE
Declares a typed named expression whose value will be passed separately from the query text. With parameterization, you can separately develop an analytical solution and then launch it sequentially with different input values.
GitHub
kysely/src/plugin at master · kysely-org/kysely
A type-safe typescript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.
Solution:
I am currently working on a driver for YDB https://github.com/Gaspero/kysely-ydb YDB dialect expects query parameters to be explicitly declared as a part of the query using DECLARE statement (reference https://ydb.tech/en/docs/yql/reference/syntax/declare ) I want to build a custom plugin that would automatically add DECLARE statements for each parameter in query ...
GitHub
GitHub - Gaspero/kysely-ydb
Contribute to Gaspero/kysely-ydb development by creating an account on GitHub.
DECLARE
Declares a typed named expression whose value will be passed separately from the query text. With parameterization, you can separately develop an analytical solution and then launch it sequentially with different input values.
GitHub
kysely/src/plugin at master · kysely-org/kysely
A type-safe typescript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.
Jump to solution
4 Replies
Igal
Igal•2y ago
Hey 👋 I had a similar constraint when creating the surreal db dialect Had to prepend a bunch of let statements before the main query
Igal
Igal•2y ago
GitHub
kysely-surrealdb/shared.ts at main · igalklebanov/kysely-surrealdb
Kysely dialects, plugins and other goodies for SurrealDB - kysely-surrealdb/shared.ts at main · igalklebanov/kysely-surrealdb
Igal
Igal•2y ago
if this is possible in YDB, it'll be easier than altering the AST and better ergonomically than forcing a plugin on consumers in general, Kysely's parameters sit in ValueNode and other ValueX nodes
Gaspero
GasperoOP•2y ago
Thanks a lot!
Want results from more Discord servers?
Add your server