Is there a better way to extract Typescript types for use in function args than what I'm doing here?
It works well enough, but this seems like something which should be exposed on a library level, maybe? I need it in order to e.g. write a function which takes in a transaction and performs operations on it, such that multiple functions can be called on a single transaction and then the transaction either committed or rolled back as one unit (so the client cannot be passed in instead).
6 Replies
example:
that tx object is a class that extends the db class, depending on your dialect
PGDatabase
or something like that
So you could do:
You would only be missing the tx.rollback()
method, but you don't really need it, you can just throw an error and get the same functionalitywhile true, I would like the ability to force the functions to be called with a transaction rather than a client interface. (and also, my client is an RLS client proxy with select, etc intentionally removed 😉 )
so I'm guessing that means there is no simpler way to get the types? I'll leave this question here for posterity in case anyone else has a similar problem and searches for it
Yeah, my solution is just the type, at runtime they would use whatever you want, a transaction would just fit the type
If you want to use the actual type, I guess you could do:
In case you are using postgres.js as driver
yep. the computed type I get from Intellisense is:
(to be clear, my Parameters mess works, it just looks bad and feels like there must be a better way that doesn't involve typing it manually in such a way that a drizzle library update might break it 😉 )
Yeah, your solution is totally fine, I don't think you'll have issues, the API is very likely staying the same