Kysely

K

Kysely

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

Join

help

query-showcase

announcements

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

Issue Getting TypeScript to work with nested query

Hi there 👋 . I'm experiencing an issue with getting typescript to play nice with Kysely. I should add that I'm still a newbie to Kysely and typescript in general. Here's the code: ```typescript await db.selectFrom((eb) => { return eb.selectFrom("faqs")...
No description

How can one make `jsonObjectFrom` respect nullability of underlying subquery?

Hello, I am getting a type error when using the jsonObjectFrom helper on a subquery where the base table type of a field is not null, but all fields returned by jsonObjectFrom are nullable. We are passing the eb with the jsonObjectFrom helper inline in our query and were wondering if there a way to specify that a field will not be null?...

Filtering data based on relationship value

Hello, I'm using subqueries to fetch and return related data from a resource table. I am using the jsonObjectFrom helper which is working perfectly. My question now is how can I filter the final data based on a field present in the relation data. For example if my main table is User and the related data is Account, how can I fetch Users where the account is active all in the same query? Im already sing the expression builder (eb) for the subquery, do I need to add a separate join expression...

How can I write a query that does multiple insertions at once?

I have an array of Ids that I want to assign to a single id in a "bridging" table for a many to many relationship: ie: singleId: id1 singleId: id2 singleId: id3...

How to "generate" or "store" a query result type?

Hello, I was wondering how can I extract or store the type resulting from a query so that I ca use said type in other parts of my code without it depending on a specific function or implementation location in code.