Repository navigation
How to receive the transactionID of a TransactionClient inside an interactive transaction? #17959
|
Hello, i'am currently playing around with multiple transactions in several ways and would like to know, if it is possible to receive the transactionId of a TransactionClient used in interactive transactions. Initial issue was an error like: So there is this kind of transaction id iam looking for. I assume the prisma engine is creating/getting this kind of transaction id when creating the transaction on a database level (on my side postgres). In order to evaluate the error it would be great to have this transaction id available in order to differentiate different transactional clients. Note that this is not about fixing the error. I am working with several transaction Clients and need some kind of identifier for each txClient in the Application. Any idea? Thanks a lot for your help and best regards |
Replies: 2 comments
|
Hi @andreasvh-conceto 👋 One way to get the transactionId of a TransactionClient inside an interactive transaction will be to do something like await prisma.$transaction(async (tx) => {
const txId = await prisma.$executeRaw`SELECT txid_current()`;
console.log('Transaction ID:', txId);
});The output is prisma:query BEGIN
prisma:query SELECT txid_current()
Transaction ID: 1
prisma:query COMMITThis code uses the txid_current() function provided by PostgreSQL to get the current transaction ID. The SELECT statement is executed within the transaction context using $executeRaw(), and the resulting ID is logged to the console. You can also open a feature request to add support for getting transactionId via a method on the transaction object. |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
Hi @andreasvh-conceto 👋
One way to get the transactionId of a TransactionClient inside an interactive transaction will be to do something like
The output is
This code uses the txid_current() function provided by PostgreSQL to get the current transaction ID. The SELECT statement is executed within the transaction context using $executeRaw(), and the resulting ID is logged to the console.
You can also open a feature request to add support for getting tr…