Gaspero
Gaspero
KKysely
Created by Gaspero on 5/21/2023 in #help
What is the suggested way of adding/removing methods to expression builders?
Context: I am building a custom dialect for YDB https://github.com/Gaspero/kysely-ydb YDB is slightly different from standart dialects. E.g. create/drop index expressions are a part of alter table expression (ALTER TABLE ... ADD/DROP INDEX) https://ydb.tech/en/docs/yql/reference/syntax/alter_table#secondary-index There are also other differences that are not as critical, but I am thinking of the ways how I can protect library users from writing broken SQL queries. E.g. Insert/Replace/Update/Upsert do not support returning values and thus do not support RETURNING expression; CREATE TABLE expression only supports primary key constraint. I've read extending Kysely section of docs https://kysely.dev/docs/recipes/extending-kysely and it looks like both options (Extending using inheritance and Extending using module augmentation) are not advised. I was wondering, may be there is some recommended way of modifying existing expression builders? Regarding CREATE INDEX issue - i've managed to solve the problem not in a very elegant way but it might be non-intuitive for users familiar with YDB syntax. So I still keep looking for the idiomatic way of adding addIndex/dropIndex methods to CreateTableBuilder/AlterTableBuilder and removing .reateIndex/dropIndex from SchemaModule. I've modified Query Compiler visitCreateIndex method protected override visitCreateIndex(node: CreateIndexNode): void { if (node.table) { this.append('alter table ') this.visitNode(node.table) } this.append(' add ') this.append('index ') this.visitNode(node.name) if (node.expression) { this.append(' global on (') this.visitNode(node.expression) this.append(')') } } then running await db.schema .createIndex('user_email_index') .on('users_test') .column('email') .execute() results to expected sql statement alter table users_test add index user_email_index global on (email)
12 replies
KKysely
Created by Gaspero on 4/27/2023 in #help
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?
10 replies