Kysely

K

Kysely

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

Join

help

query-showcase

announcements

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

How can I cast a jsonb value to a float8 in query?

I have a query that has a jsonb value in the db that will always be a number, and I want to sum it. how can I change this value to a number fn.sum<number>('value') what I want is:...

`InsertId` type for UUIDs

Hello, we use UUIDs as our primary IDs so when running insertInto statements we expected the insertId to be a string, but we are getting a bigint | undefined type. How can we get the correct type?...

How to access error events -- Is there a best/good practice for error handling

I'm writing my methods and associated tests for db access and when trying to validate error events. I get a SQL event log but nothing is caught in my try-catch block. When I log the response it is either empty or undefined. *Example ```typescript...

`createTable` function with dynamic column array

Hey folks, I'm trying to create a create table function; I feel like this should be straight forward and just work. But, I'm obviously missing something. Please let me know if more details are required. Thank you for your time.  🙏 ```typescript...