virk
virk
KKysely
Created by virk on 4/11/2024 in #help
Need help improving a custom helper
Thanks a ton for looking into it 🙂
7 replies
KKysely
Created by virk on 4/11/2024 in #help
Need help improving a custom helper
I think passing eb explicitly is fine as well. Its just month('created_at') reads a little better than month(eb, 'created_at')
7 replies
KKysely
Created by virk on 4/11/2024 in #help
Need help improving a custom helper
Yeah, I suspected that.
7 replies
KKysely
Created by virk on 4/11/2024 in #help
Using raw SQL with `or` where
The trick is to set the output type of RawBuilder to a boolean. RawBuilder extends Expression, so it is acceptable by eb.or
8 replies
KKysely
Created by virk on 4/11/2024 in #help
Using raw SQL with `or` where
But still want to verify if I am correct
.where((eb) => {
return eb.or([
sql<boolean>`address ->> 'street' = ${eb.val(street)}`,
sql<boolean>`address ->> 'street' = ${eb.val(street1)}`
])
})
.where((eb) => {
return eb.or([
sql<boolean>`address ->> 'street' = ${eb.val(street)}`,
sql<boolean>`address ->> 'street' = ${eb.val(street1)}`
])
})
8 replies
KKysely
Created by virk on 4/11/2024 in #help
Using raw SQL with `or` where
Okay, I think I got it after reading the expressions doc in and out https://kysely.dev/docs/recipes/expressions
8 replies
KKysely
Created by virk on 4/8/2024 in #help
Solved: Exporting query builder classes
Would you like me to create an issue for the same? Or is it something you want to re-evaluate and do it at your own pace?
7 replies
KKysely
Created by virk on 4/8/2024 in #help
Solved: Exporting query builder classes
Okay, I get it. So basically you have been exposing interfaces publicly and keeping classes for internal runtime usage. Yeah, I would personally love to have classes exported and also become the returning types, if that doesn't change a lot of internals
7 replies
KKysely
Created by virk on 11/30/2023 in #help
Guidance to create a generic wrapper over Kysely
Hey, thanks for the reply. Cool, just wanted to make sure I am not shooting myself in foot by typecasting to any
10 replies
KKysely
Created by virk on 11/30/2023 in #help
Guidance to create a generic wrapper over Kysely
No description
10 replies
KKysely
Created by virk on 11/30/2023 in #help
Guidance to create a generic wrapper over Kysely
--- Is it too much to ask from Kysely internals to work with generic functions like this? Or you think it can work?
10 replies
KKysely
Created by virk on 11/30/2023 in #help
Guidance to create a generic wrapper over Kysely
I have another use-case, lemme ask you guys before I give up on this one. So, here I am trying to create a generic firstOrCreate helper function. This is how the implementation looks like so far.
function firstOrCreate<DB, TB extends keyof DB>(
db: Kysely<DB>,
table: TB & string,
searchAttributes: Readonly<FilterObject<DB, TB>>
) {
db.selectFrom(table).where((eb) => eb.and(searchAttributes))
}
function firstOrCreate<DB, TB extends keyof DB>(
db: Kysely<DB>,
table: TB & string,
searchAttributes: Readonly<FilterObject<DB, TB>>
) {
db.selectFrom(table).where((eb) => eb.and(searchAttributes))
}
I can execute the function with no errors.
firstOrCreate(db, 'users', { name: 'foo' })
firstOrCreate(db, 'users', { name: 'foo' })
However, the eb.and(searchAttributes) method call gives an error
10 replies
KKysely
Created by virk on 11/30/2023 in #help
Guidance to create a generic wrapper over Kysely
Ahh okay. Thanks for your reply 🙂
10 replies