K
Kysely

help

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

Solution
GGaspero5/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 table users_test add index user_email_index global on (email)
Solution:
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. ...
Jump to solution
GitHub
GitHub - Gaspero/kysely-ydb
Contribute to Gaspero/kysely-ydb development by creating an account on GitHub.
Extending kysely | Kysely
In many cases Kysely doesn't provide a built-in type-safe method for a feature. It's often because adding
ALTER TABLE
Using the ALTER TABLE command, you can change the composition of columns and additional table parameters. You can specify several actions in one command. In general, the ALTER TABLE command looks like this:
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. adding/dropping indexes is also supported in MySQL's alter table. Wanna submit an issue?
GGaspero5/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.
GGaspero5/21/2023
Ok. I will submit two issues and I am ready to contribute if this issues will get ‘greenlit’ label
GGaspero5/21/2023
GitHub
[Feature] Allow creating indexes using ALTER TABLE ... ADD INDEX · ...
Currently the only way of creating indexes using Kysely is using createIndex method e.g.: await db.schema .createIndex('user_email_index') .on('users_test') .column('email')...
GitHub
[Feature] Allow removing indexes using ALTER TABLE ... DROP INDEX ·...
Currently the only way of removing indexes using Kysely is using dropIndex method e.g.: await db.schema .dropIndex('user_email_index') .on('users_test') .execute() But MySQL and som...
IIgal5/21/2023
I actually meant an issue for create table, and an issue for alter table haha 😅 thanks! also, looks like they're greenlit

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Running database agnostic queries (MySQL)As part of my test suite, I drop/create databases programmatically. Is it possible to have a Kysely Asserting type of .countAll() (MySQL)I've noticed that the return type from the result of aggregation functions like `countAll()` and `suCoalesce return empty arrayHey is there a way to return an empty array rather than `null` when an array column is empty? I alrkysely-codegen for multiple databasesI have two MySQL 'databases' within the same instance. From the documentation, it doesn't look like Using MySQL functions in SELECT statementHi! Just trying to migrate over from Knex. Skimmed over the documentation but still unsure of how tExtract OrderBy TS KeysHey I have the following query ```ts const getBaseQuery = ({ offset, pageSize, slug }: GetBaseQuerinsert into with mix of static and table valuesHow might I execute an insert into that combines JS-side values with a select, like: ``` INSERT INTOMigration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"I am trying to run a migration using Kysely, and its returning this error: ``` file:///Users/brunocrwhere clause with lengthHow do I have a where clause with a length, e.g. `select * from data where length(prodcode) = 3`show generated sqlhow can i see what the generated sql is for a kysely query? e.g. ``` result = await db.selectFrom("Property does not exist on typeHello. I'm trying to run the following query: ```javascript result = await db.selectFrom("data") Correct type definitions for function receiving builderI have something like this and I was wondering if it's the correct way to type my helper function. Transform Postgres array into JS arrayHey, I was wondering if there's a helper or something to transform Postgres arrays `{one, two}` intoNoob Question: SQL INSERT that combines static values with a SELECT statementHey Kysely community! I'm just getting into Kysely and I have a question about how I could run the fIs there a way to execute an ExpressionBuilder?Using the expression hasDogNamed example from the docs ``` const eb = expressionBuilder<DB, 'personArgument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.The following statement, is giving me the error on the title ```ts fn("round", [fn.min("ld.price_btcHow do Date columns works?I am learning Kysely from the website, at the getting started section I can see the following line: converting result.insertedId to numberwhen using INT as PK i can safe convert `result.insertedId` from `bigInt` to `Int` using `Number(resAdvice on building plugin for working with parametersI am currently working on a driver for YDB https://github.com/Gaspero/kysely-ydb YDB dialect expectMysql Query execution never endsHello, I have a question regarding my new integration of kysely in trpc. I wanted to port my prisma