types for database/transaction
Hey, I have this function:
You can see, that I get a
database
as variable. That can either be a default postgres database (easy to type) or it can be a transaction (how to type). I would like to know how to type them correctly, so I can use users
in this case?
I could do something like this:
But then I can access users
via database.query.users
:/6 Replies
solved it by just removing the database stuff and only return the config:
this is how I do it
where DrizzleClient is
ReturnType<typeof drizzle>
it's obnoxious, but it works, and lets me pass around the tx
variable
alternatively, if you have a drizzle instance bound to a schema, just use the typeof that insteadOhh starts smart. Will do that in the future. Thanks! 🙏
Hey guys, do you have this working? Because i still get an error when doing something like
trx.query.user.findFirst
where ts complains about excessive stack depth comparing types...
I modified mine a bit to get it working. Now I have it like this and it works perfectly:
ah, I don't use the query api. that must be why mine works, I just use it as a sql client