Typesafe where? argument possible?
I have a service class containing:
now I want to add a
where? argument to this findAll function.
Is there a type I can use from Drizzle to make this where? arg it typesafe?5 Replies
I don't think there is something built-in :/
We can recreate the expected type:
demo: https://drizzle.run/k0swqddotuays16lyweqzbj9
Drizzle Run
Typed where - Drizzle Run
Thx for your help!
I’m going to look into this, however it looks quite overwhelming.
Would there be a chance that drizzle could provide something like this out of the box?
Yeah I think it could. Maybe @Andrew Sherman have plans about that
How would you like those types to look? @Raphaël M (@rphlmr) ⚡ sent a pretty good example of how to structure types for 'where'. If you have any better options, I'd love to implement those
I came up with this for now:
this now basically delegates the
findAll to drizzle's findMany.
Maybe this looks akward, but this findAll is part of service class with other methods like findById whichi e.g. first looks in a cache before doing the query. So this service class encapsulates my database access implementation.
But back to the original question, my original findAll looked like:
and ideally I would like it to look like:
and then call it like:
in the method signature I put in <???> for the where and orderBy arguments as I don't know how to type them; and that's exactly the thing I would like to do, that these args are typed.
Hope it is clear what I mean...
Note I'm using drizzle with the Cloudflare D1 adapter.
Maybe that is what is confusing me, as @Raphaël M (@rphlmr) ⚡ example (and many thx for that!) is using PostgreSQL it seems to define that Where type: