K
Kysely•2y ago
sirhype

Types for use with leftJoin

Hiya! I'm attempting to do a leftJoin and return the result:
const result = await db
.selectFrom("accounts")
.leftJoin("applications", "accounts.id", "applications.accountId")
.where("accounts.sessionId", "=", sessionId)
.executeTakeFirst();
const result = await db
.selectFrom("accounts")
.leftJoin("applications", "accounts.id", "applications.accountId")
.where("accounts.sessionId", "=", sessionId)
.executeTakeFirst();
I'd like to have the result be a type, like Selectable<Account & Application> but I'm not sure if this is supported or what the proper way to do this is. Any help would be appreciated, thank you!
2 Replies
Igal (mobile)
Igal (mobile)•2y ago
Hey 👋 You forgot to call .select/.selectAll. You could keep the query in some global const, without .where, and use InferResult<typeof query> to get the type. Then, since Kysely is immutable, call .where in a function and execute.
sirhype
sirhypeOP•2y ago
Thanks! I ended up figuring out the answer to my question, sorry, forgot to follow up here 🙂 I really appreciate the help!
Want results from more Discord servers?
Add your server