Transaction Type
Is there a type to use for passing a transaction into a function? I would like to do something like
but the type of
tx
is super long and not convenient at all.13 Replies
recent update changed the types and now I cant fit a Drizzle Transaction type into a normal Drizzle type. I'm not sure how aware the team is about it
Yea I used to be able to just do
typeof db
and that was good enough but now the new update has changed the types. It doesn't seem there has ever been a proper way to represent that type, just work arounds.did you guys ever find a solution?
i had this same problem today, solved it this way
i personally prefer option 1 since getting it from the params seems a bit janky
(im on mobile so excuse the formatting and typos)
While this does work for me, it's obviously not how we should be getting the type. It seems crazy to me that this isn't something exposed by the library. Is it really that uncommon to need the type of a transaction? Do you know if they are planning on adding this at any point to the library itself?
i completely agree, i looked through the source code to see if such a type was exposed but nopes
that’s why i had to use these helpers but yeah not ideal
Plus, who knows if either of these will work after the next update.
and i dont work for drizzle so idk if it’s planned
option 2 will, it just takes the return type. it’s just ugly
option 1 should, since i’m just creating the PgTransaction type the same way it’s done internally in drizzle
Well, hopefully they just expose an actual type in the future. For now though your solution works, so thank you lol
does anyone know if it has been exposed by the team or if there is an issue created for this?
I use this:
It seems to work. I think I'm using drizzle-orm 0.38.0. But it's awkward.
basically, the trick is to use
typeof db.transaction
Here's the proper way to type
db
and tx
:
The above would look like this for PG with the postgres.js driver (just to give an example):
thanks for the reply.
I am using postgres as a db. what driver does drizzle use by default? is it pg or postgres or postgres.js?
thanks for the reply. it never occurred to me i could use
typeof db.transaction