K
Join ServerKysely
help
Advice on building plugin for working with parameters
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
Take a look at the following example query https://kyse.link/?p=s&i=lEJ4rdYMqPWYE5jrEcQE
Expected output would be:
*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?
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?
Hey 👋
I had a similar constraint when creating the surreal db dialect
I had a similar constraint when creating the surreal db dialect
Had to prepend a bunch of
let
statements before the main queryif 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
nodesThanks a lot!