Complex Query Builder from dynamic input - Typescript issue
Hi, it's me - again 🙂
I'm currently trying to migrate our current query builder.
It seems that everything is working as expected, but I get some type errors and I'm not sure how to fix this - Maybe you have an idea how to fix this / what the rootcause is.
The query is compiled and I can see it in my vitest & in the playground ( you have to open the web console 😉 )
Playground link: https://kyse.link/8cA4l
It's based on:
* https://kysely.dev/docs/recipes/expressions#creating-reusable-helpers
* https://kysely.dev/docs/recipes/expressions#conditional-expressions
Expressions | Kysely
An Expression is the basic type-safe query building block in Kysely. Pretty much all methods accept expressions as inputs. Most internal classes like SelectQueryBuilder and RawBuilder (the return value of the sql tag) are expressions themselves.
Solution:Jump to solution
Hey 👋
This is a bit harder to grok.
What's immediate is that
conditionBuilder
might return undefined
and .where
expects something....3 Replies
Solution
Hey 👋
This is a bit harder to grok.
What's immediate is that
conditionBuilder
might return undefined
and .where
expects something.
Also, .flatMap(identity)
could be changed to .flat()
.
conditionBuilder
should return ExpressionWrapper<KyselyDatabase<TableDefinition>, "tablename", SqlBool>
.
filters
should be of type ExpressionWrapper<KyselyDatabase<TableDefinition>, "tablename", SqlBool>[]
getFieldQuery
should also return ExpressionWrapper<KyselyDatabase<TableDefinition>, "tablename", SqlBool>
You can as any
getFieldQuery
's return values.
https://kyse.link/FIsu8Thanks igal - will give it a try
Hi @Igal - just want you to know that everything works now.
I just changed the
as any
to as ExpressionWrapper<KyselyDatabase<TableDefinition>, "tablename", SqlBool>
Thanks again for spending your free time to solve this challenge.
Let's see if I can find something more challenging 😉