tzezar
Explore posts from serversneed advice how to configure driver to return prefixed or drizzle style selections
Ideally I would like to get shape with a query like drizzle offers, meaning each table has its own object (eg. products joined with tax would return multiple rows as {product:{}, tax:{}}) or at least add a prefix to the columns. From what I read yesterday, this is beyond the scope of kysely, and more of a db driver task. Has anyone done something similar in combination with kysely and could give me a hint, because I don't really know how to go about it. Thanks!
5 replies
problem with nested jsonArrayFrom and jsonObjectFrom
Typescript raise error when attempt to reference to relations in nested json helpers is made. Is this syntax error or kysely limitation?
https://kyse.link/SL7ct
4 replies
Is there way to select every field from table using `select` instead of `selectAll`?
I have very wide table and writing every field by hand is time consuming.
selectAll
does the job, but I also need to populate some relations and build json_agg
s. Is there way to either select every column from table (and then build jsonObject) or extend selectAll
with some extra fields?
Using raw sql it could be done with please dont waste your time on building this query, just a little hint will be super helpfull! 😉4 replies
How to delete and insert in one query
Hey! I wonder how with kysely make for example delete and insert in one query to reduce db roundtrips.
I believe Using WITH Clause (Common Table Expressions - CTEs) might help, but how kysely syntax would looks like?
Should I simply use raw sql here?
6 replies
json object relation null problem
I am trying to make https://kysely.dev/docs/recipes/relations this helper work, but get error
I wrote code following docs example:
usage:
and helper expression?:
adding union with
null
here:
fixes problem, but it looks like it should work without null
after adding .$notNull()
as above and later after select any clue?6 replies
How to narrow type from jsonArrayFrom
Hey! I need to narrow some types from table that works as
Single Table Inheritance
table. I believe this is possible, but after some fighting with api and syntax I am not sure how to make it.
Here is my query:
(sorry for polish, Ubiquitous Language with domain masters)
6 replies
Is it possible to change type of returned value with jsonBuildObject?
I struggle typing reponse schema in fastify cuz query returns
'wartosc'
as string
but actually it returns number
. Can't simply change zod reponse schema, cuz kysely types wartosc
in query is as string, and there is type mismatch anyway. (sorry for polish, ubiquitous language with polish domain masters)
is something like this possible (simmillar to type casting with raw sql sql<number>
? if not any tip how to handle this?
I would really like to put data in proper shape in sql to avoid extra mapping on backend code16 replies
Is it possible to configure to which types database columns are introspected?
We use kysely-codegen and we would like to use those generated types, but they ofter are translated to diffrent types we want. Lets say
int id
is introspected to Generated<number>
(we would like number type) or decimals
are introspected to Numeric
(we would like just number)6 replies
transaction takes too long
I have a problem with transactions. What might be the reason that db.transaction() adds more than 10ms latency?
+ postgresql
Below I will attach code that generated those results. Transaction overhead is present in every function call. What might be the reason for the more than 10ms spent on a transaction?
7 replies
How to retrieve field name raising error in database?
I am using kysely, zod, expressjs. I need to return field error and display it to the end user in frontend form. However I am not sure how to do it with kysely. Code for backend is pretty simple:
and next(err) is catching error and sending it in response with valid status code.
However this is error generated by Kysely:
<Error in second message>
I would be super gratefull if you give me any suggestion how to extract field name raising error.
6 replies