Kysely

K

Kysely

Join the community to ask questions about Kysely and get answers from other members.

Join

help

query-showcase

announcements

Migration 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/brunocruz/code/look-manager/node_modules/kysely/dist/esm/raw-builder/raw-builder.js:61 : executorProvider.getExecutor(); ^...

where clause with length

How do I have a where clause with a length, e.g. select * from data where length(prodcode) = 3...

show generated sql

how can i see what the generated sql is for a kysely query? e.g. ``` result = await db.selectFrom("data") .select(['partner_cd', 'reporter_cd', 'product_cd', 'period'])...

Property does not exist on type

Hello. I'm trying to run the following query: ```javascript...
Solution:
Hey 👋 What kysely version are you using? cmpr (and other cool new expression builder stuff) is only available from 0.24.x...

Correct type definitions for function receiving builder

I have something like this and I was wondering if it's the correct way to type my helper function. ```ts // ----- Helper function I want to type const addCategoriesWhere = (...

Transform Postgres array into JS array

Hey, I was wondering if there's a helper or something to transform Postgres arrays {one, two} into JS arrays ['one', 'two']. Right I know the Postgres array is turned into a string when executing queries
Solution:
So you'd do
.select(sql<string[]>`categories::text[]`.as('categories'))
.select(sql<string[]>`categories::text[]`.as('categories'))
You can cast it to any type you want....
Message Not Public
Sign In & Join Server To View

Noob Question: SQL INSERT that combines static values with a SELECT statement

Hey Kysely community! I'm just getting into Kysely and I have a question about how I could run the following query with Kysely: ```sql INSERT INTO employees (employee_id, first_name, last_name, department_id) VALUES (1234, 'John', 'Doe', ...

Is there a way to execute an ExpressionBuilder?

Using the expression hasDogNamed example from the docs ``` const eb = expressionBuilder<DB, 'person'>() ...

Argument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.

The following statement, is giving me the error on the title
fn("round", [fn.min("ld.price_btc"), sql.lit(5)]).as("floor_price"),
fn("round", [fn.min("ld.price_btc"), sql.lit(5)]).as("floor_price"),
...

How do Date columns works?

I am learning Kysely from the website, at the getting started section I can see the following line:
modified_at: ColumnType<Date, string | undefined, never>
modified_at: ColumnType<Date, string | undefined, never>
...

converting result.insertedId to number

when using INT as PK i can safe convert result.insertedId from bigInt to Int using Number(result.insertedID)?

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 ...
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 ...

Mysql Query execution never ends

Hello, I have a question regarding my new integration of kysely in trpc. I wanted to port my prisma code to kysely and found that queries are indeed firing to db, but they never end the execution. Anyone knows why this is happening? Connection is taken from pool and mysql workbench also shows connection to db. Just the data is not returning. Same code is working with Prisma. Not sure where its going wrong. ...
Solution:
Hey 👋 Try importing createPool from mysql2 and not mysql2/promise....

How to do join with raw sql snippets?

How can I do this join with kysely? left join videos on videos.id = CAST(highlights_content.item AS INT) AND highlights_content.collection = 'videos' I tried using the provided sql helper but can't really figure out which parts I need to replace with raw SQL for this to be possible....
Solution:

More elegant way to handle nested relations?

Can someone come up with more elegant solution for handling relations than this? I've modified the examples a bit so that I can customize the selected fields and add filters when calling withSomething but it becomes quite verbose and not easy to read. Here's one of my relation helper functions: ```ts export function withLinks<T>( eb: ExpressionBuilder<DB, 'banners'>, fn: (...

Join DATE_TRUNC

Hey, sorry if this is already answered somewhere. I couldn't find anything 😦 I want to translate this part of a SQL query into Kysely ```sql...

Why does kysely-codegen generate the schema in node_modules?

Like probably many people here, I use https://github.com/RobinBlomberg/kysely-codegen . By default, the DB schema file is generated inside the node_modules. It can be changed of course, but I wonder why that is the default? I was expecting that file to be something you keep in versioning....

Any plan to complete the Postgres dialect?

Hey there, Is there any plan (or a tracking issue) to complete the Postgres dialect with its specific words like CREATE/ENABLE POLICY, SET, SET LOCAL..?...

Convert date to timestamptz

Hello. I'm trying to convert the following query from TypeORM querybuilder to Kysely: itemRepository .createQueryBuilder() .select() .where({ id })...

Shorthand way to pass the entire update object inside of doUpdateSet when updating multiple values.

Greetings! Thanks for developing Kysely, some of the stuff that it does actually blows my mind. I only started using it a few days ago, and I love it so far. Anyway, I have a quick and simple question. I am trying to update (upsert ) multiple values into a table like this:...