fed
fed
KKysely
Created by fed on 12/26/2024 in #help
[Bug] innerJoinLateral selectAll prepends schema
apologies for the hastily written bug report. i found a workaround so im not super concerned. writing this down in case it's helpful: 1. have a postgres db variable that's instantiated withSchema pointed at my_schema 2. selectFrom my_table with an innerJoinLateral on my_computed_object 3. select jsonObjectFrom(eb.selectFrom('my_computed_object').selectAll('my_computed_object')) 4. compile query and observe: (select to_json(obj) from (select "my_schema"."my_computed_object".* from "my_schema"."my_computed_object") as obj) the above results in a runtime error because "my_schema"."my_computed_object" does not exist. the prepended "my_schema". should get dropped the workaround is to instead do jsonBuildObject({ key1: ref('key1'), ... }) (feel free to close / ignore this if the above is insufficient / not helpful)
17 replies
KKysely
Created by fed on 12/24/2024 in #help
Flatten type of single column select?
Hi! I have helpers that look roughly like this:
function ownerId(organizationId: Expression<number>) {
eb.selectFrom('organization')
.where('id', '=', organizationId)
.select('ownerId')
}

function personName(id: Expression<number>) {
eb.selectFrom('person')
.where('id', '=', id)
.select('name')
}
function ownerId(organizationId: Expression<number>) {
eb.selectFrom('organization')
.where('id', '=', organizationId)
.select('ownerId')
}

function personName(id: Expression<number>) {
eb.selectFrom('person')
.where('id', '=', id)
.select('name')
}
the problem is that i cannot compose these helpers. in other words, i cannot do the following:
const orgOwnerId = ownerId(ref('organization.id'));
const orgOwnerName = personName(ownerId);
const orgOwnerId = ownerId(ref('organization.id'));
const orgOwnerName = personName(ownerId);
because the type of orgOwnerId does not match the type of the id arg required by personName any suggestions on how to solve this? somehow "flattening" the return type of ownerId to Expression<number> would be ideal, if that's possible and that 👆 should be valid, since ownerId is a single-row single-column select? i thought about using $castTo, but one concern is that $castTo gives up type safety...
4 replies
KKysely
Created by fed on 11/21/2024 in #help
Improving TS compile speed with multiple conditional selects?
Hi, I have API endpoints that query Postgres via Kysely. The API endpoints accept an include object that determines whether to include various optional fields. Some endpoints have grown to accept 5-10 optional fields. Each of these optional fields results in an additional $if branch in the Kysely query. And this seems to harm TS compile speed -- I'm now waiting 1-3min for each compilation. What are the best ways to mitigate the compile speed downsides of using many $if calls?
6 replies