Kysely

K

Kysely

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

Join

help

query-showcase

announcements

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

Raw query for RLS not working

I am trying to migrate a raw query from TypeORM's builtin query builder to Kysely. It's required to be raw as Kysely unfortunately does not fully implement Postgres's SQL language. Original query: `` const query = ...

Problems typing a generic withPerson helper

First I want to say that I'm in love with Kysely! It's amazing. I could use some help getting the types right for a helper function I'm creating. I'm trying to follow the relations recipe (the withPets and withMom example from the docs), but I want to make it slightly more reusable. I have a withPerson method...

Rollback transaction

Hi, I'm trying to figure out if it's possible to intentionally rollback a transaction, the idea is that if one insert into the database ends with certain return value, the whole transaction should end and the insert rolled back. Knex has trx.rollback on the callback parameter, but I couldn't find anything like that on Kysely, am I missing something or is this not yet implemented?
Solution:
await sql<void>`rollback`.execute(trx)
await sql<void>`rollback`.execute(trx)
Okay I was doing raw sql badly, this does work at least...

Trouble running migrations

I am trying to use Kysely on a svelte-kit project, I set up the migration script like the example shown in the docs, but when trying to run the script with ts-node --esm "path/to/script" I receive failed to migrate
CustomError: ERR_INVALID_MODULE_SPECIFIER src\lib\server\db\migrations\540540540_create_db.ts is not a valid package name E:\Code\Web\portfolio-projects\spotify-cp\node_modules\.pnpm\[email protected]\node_modules\kysely\dist\esm\migration\file-migration-provider.js
CustomError: ERR_INVALID_MODULE_SPECIFIER src\lib\server\db\migrations\540540540_create_db.ts is not a valid package name E:\Code\Web\portfolio-projects\spotify-cp\node_modules\.pnpm\[email protected]\node_modules\kysely\dist\esm\migration\file-migration-provider.js
I tried changin the migration file name, making it a JS file instead of TS but still get the same error, I am not sure what I am doing wrong, the scripts are the same as the examples in the docs....

Suggestions on implementing SQLite as DocumentDB or GraphDN

Would love recommendations on using Kysely to implement something similar to the following. https://github.com/dpapathanasiou/simple-graph https://dgl.cx/2020/06/sqlite-json-support Video in case it's helpful - https://www.hytradboi.com/2022/simple-graph-sqlite-as-probably-the-only-graph-database-youll-ever-need It seems like a perhaps using sql.raw helpers and abstracting in plugins, then perhaps some TS magic to make the QueryBuilder and other types to work....

open source examples

Do you know of a mid-large size open source codebase that has integrated kysely? Size isn’t most important here, but I’m curious to see edge cases and sophisticated use cases may arise in a sufficiently complex system....

Types for use with leftJoin

Hiya! I'm attempting to do a leftJoin and return the result: ``` const result = await db .selectFrom("accounts")...

mysql InsertResult always empty

my app is heavy id/transaction user and i need the id of created register to insert another register but InsertResult always is empty

RawBuilder is not "Compilable"

How one should execute RawBuilders coming from (for example)
```
since they're not "Compilable" things? I know you can pass from
```
since they're not "Compilable" things? I know you can pass from
sqlcustomsql.execute({ getExecutor: () => executor })...

Query with ANDs and ORs - struggling with syntax

I want to be able to create a query that looks like this - i.e. has a first WHERE section that must be true then an either/or but struggling to get the syntax right SELECT * FROM user WHERE ...

Subquery type error when using generics

I have the following simple query being generated by my function f: ``typescript const f = () => queryBuilder .deleteFrom(table as t1) .whereExists(qb => qb.selectFrom(table as t2`)...

Extacting where clause generation into dedicated function

I'm building up a query dynamically and need to use some of the logic embedded in where clauses from multiple functions. Therefore, I'd like to encapulate this in a separate function that can be reused but I'm struggling with the type signatures for that function. An example of a query that I'd like to encapsulate is: ```ts query = query.where((qb) => {...