Kysely

K

Kysely

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

Join

help

query-showcase

announcements

what is this error, i started getting it randomly

``` error: syntax error at or near ")" at /Users/username/Workspace/company/project/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async PostgresConnection.executeQuery (file:///Users/username/Workspace/company/project/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/dialect/postgres/postgres-driver.js:69:28)...

Kysely doesn't work in jest/test environment

For some reason Kysely does not work when I'm running test via Jest. I have a simple Express application and all db.selectFrom(... commands just times out. I tried to log things via: ``` log(event) { console.log(event);...

Is there a plan to add "NULLS NOT DISTINCT" (postgresql v15) option to unique constraints/indexes?

In postgresql version 15.0 "NULLS NOT DISTINCT" statement was introduced. How to include this statement? BTW in version 16 it was disallowed for primary keys.

How to work with window function ROW_NUMBER correctly?

How to type correctly something like this? I struggle with the ROW_NUMBER... `` const query = WITH ranked_licenses AS (...

executeTakeFirst does not add limit(1). Why?

If my understanding is correct, there is never any reason not to limit(1) when you do an executeTakeFirst.

How do you formulate a custom type argument?

I would like to pass a record type to a postgres function with kysely. How do I do that? I get "malformed record literal" when I try the obvious things. I'm sure I can raw-sql it together but I'd like to do it as properly as possible.

How do I type the arguments to a function?

I am calling a stored proc with parameters (we have very few, but some make the client's life a lot easier and make transactions shorter). I get an error that it can't find the function given the types:
function my_favorite_function(unknown, unknown, unknown)
function my_favorite_function(unknown, unknown, unknown)
...

InsertInto with all default values?

How do I run the equivalent of
INSERT INTO test DEFAULT VALUES returning
INSERT INTO test DEFAULT VALUES returning
in kysely?

Can this query translate to kysely?

``sql sqlSELECT frr.reimbursement_request_id, frr.reference_no, frrt.request_type,...

Deferred Join

Hi - I'm experimenting with adding deferred join capability (as described here: (https://planetscale.com/learn/courses/mysql-for-developers/examples/deferred-joins) to a limit/offset query. The premise is to apply the order by, limit and offset values to the inner join query but I'm having trouble finding a way syntactically to apply this to the inner join. Do I need to use the sql escape hatch? If so, I'm also struggling with where I'd apply that too! Any pointers appreciated as always, thanks...

Stumped - sqlite kysely no data from select query

I have an electron app with node-sqlite3 and kysely. I'm able to post data, but for some reason select comes up empty. I feel like I'm missing something low-level here. Thank you in advance. I've been banging my head on this off and on for 2 days. db.ts ```ts import sqlite3 from 'sqlite3';...

MySQL Returning Statement Alternative

A while back I read online that MySQL does not support RETURNING statements at all. If that's the case how do I handle a situation in which I insert a new row and then get the inserted row back? Do I depend on the row being inserted to have some unique identifier I can use to fetch it after insertion or is there another way (in the event in which the only unique id is the primary key -- which is autogenerated)

Issue running migrations against MySQL database

Previously I had to make the switch from Postgres to MySQL because the database I had in production was MySQL. After making the switch, I noticed that my migrations started failing (understandably because of the slight difference in syntax between pg and mysql). I worked to fix those differences and then run the migrations but this time the migrations just hang there... for what seems like forever.
No description

Deno usage

Hey, has anyone by any chance trie using Kysely with deno using the postgresjs library? https://github.com/porsager/postgres
Solution:
Hey! I was also searching for any examples of postgres-js usage in deno. Didn't find any but managed to set it up using https://github.com/igalklebanov/kysely-postgres-js adapter `// import_map.json { "imports": {...

Returning numeric fields as float

Hello, we're migrating from Supabase to Kysely and we have some queries failing in our client because it seems Kysely is returning columns marked as numeric in string format. How can one setup Kysely to parse those numeric columns to float ?

how to convert bigint to text in select statement?

In raw sql we do this cursor_id::text. How to perform this in kysely?

Subquery on same table

I'm experimenting with how to improve the performance of some queries against a PlanetScale MySQL DB. I have a fulltext index on a field in a table, then some other indexes on various other fields. MySQL can't use two indexes for a query so I'd like to try including the section of the query that uses the fulltext column in a subquery but I'm struggling with the syntax The primary key of the table is activityId....

How to return last inserted ID ?

``` export async function createCommands(deviceId: number, commands: string[]) { return db .insertInto("commands") .values(commands.map((c) => ({ deviceId, content: c })))...

hi, how do i make a select with a where that searches within a json? I'm using postgres

inside the json there is an id that I want to use to do the search, but I didn't understand how to do it, could you help me?

CASE example in docs?

Hello, where can one find an example of how to properly use CASE for query building? We want to use it inside a Where clause at the moment....