question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`@Transactions` decorator, Expose and accept a transaction object

See original GitHub issue

Problem

We cannot use a @Transaction decorator or access the transaction object and pass it directly to the query itself.

Suggested solution

Any thought on doing this: Returning $transaction to the user and pass it to the API interface as a argument. Something like this:

const transactionObj = prisma.createTransaction();
const user = await prisma.user.create({
  data: {
    email: 'elsa@prisma.io',
    name: 'Elsa Prisma',
  },
  { transactions: transactionObj }
})
const temp = prisma.temp.update({ where: { id: 1}, data: {f1: 1},  { transactions: transactionObj }})

TBH I do not like this approach too much (Passing extra stuff, too noisy and annoying)

Alternatives

AFAIK nothing except those listed in the doc which is not practical in most cases.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
adrian-goecommented, Sep 21, 2022

please have a look at https://github.com/prisma/prisma/issues/12975, that discusses the same topic. And also have a look at https://github.com/prisma/prisma/issues/12458

The problems discussed in https://github.com/prisma/prisma/issues/12458 regarding the test situation would also be solved with a @Transactional annotation.

As said in my other comments in the other issues, this is more or less a standart in the Spring Hibernate world.

2reactions
cesarvsprcommented, Jun 11, 2022

Can you elaborate how the current functionality of interactiveTransactions does not fit your use case? The example in your initial message would be triviial to support with this - but I assume you out some of the complexity for the feature request.

I think OP and me are talking about Prisma providing a @transaction decorator which would provide a transaction for the functions execute below. I don’t have expertise to say if this is difficult to implement.

Of course, this is not blocking, the actual $transaction works pretty well.

But a decorator would provide more readability for the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

16. Transaction Management - Spring
Global transactions enable you to work with multiple transactional resources, typically relational databases and message queues. The application server manages ...
Read more >
Transactions and Connection Management
When the transactional state is completed after a rollback or commit, the Session releases all Transaction and Connection resources, and goes back to...
Read more >
Using database transactions | LoopBack Documentation
Handling Transactions · Start a new transaction. · Perform create, read, update, and delete operations in the transaction. · Commit or rollback the...
Read more >
Transactions and db_session — Pony ORM documentation
This approach guarantees that there will be no lost updates, the situation when during the current transaction another transaction changed the same object...
Read more >
c# - Can I get a reference to a pending transaction from a ...
The command object can only be assigned a transaction object using one ... Transactions approach uses in conjunction with SQL Server 2005 a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found