What is the suggested way of adding/removing methods to expression builders?

Solution
ISIvan Shadrin5/21/2023
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 tableusers_testadd indexuser_email_indexglobal on (email)
IIgal5/21/2023
Hey πŸ‘‹

Kysely's API is dialect agnostic by design. This means we don't omit/add methods to builders based on current dialect.
IIgal5/21/2023
adding/dropping indexes is also supported in MySQL's alter table. Wanna submit an issue?
ISIvan Shadrin5/21/2023
Got it. Thank you!
IIgal5/21/2023
its actually 2 separate issues, one for alter table add/drop index, one for create table add index.
ISIvan Shadrin5/21/2023
Ok. I will submit two issues and I am ready to contribute if this issues will get β€˜greenlit’ label
IIgal5/21/2023
I actually meant an issue for create table, and an issue for alter table haha πŸ˜…
IIgal5/21/2023
thanks!
IIgal5/21/2023
also, looks like they're greenlit