I have some functions where I need to make sure I call .$primary() in my database (specifically because I'm using INSERT ... RETURNING, so I need to manually overwrite $queryRaw to hit the primary), but if I call .$primary() it returns the main client rather than the expected transaction client. In the context of a transaction, it makes sense for txn.$primary() to return itself idempotently, so that write-facing code can be agnostic to whether the Prisma client is transactional or not.
I have some functions where I need to make sure I call
.$primary()
in my database (specifically because I'm usingINSERT ... RETURNING
, so I need to manually overwrite$queryRaw
to hit the primary), but if I call.$primary()
it returns the main client rather than the expected transaction client. In the context of a transaction, it makes sense fortxn.$primary()
to return itself idempotently, so that write-facing code can be agnostic to whether the Prisma client is transactional or not.That's to say:
Should run within the context of the transaction, rather than outside of it.