Shyp / pg-transactions

Library for doing Postgres transactions in Javascript
MIT License
25 stars 2 forks source link

Nested Transactions? #1

Closed vitaly-t closed 8 years ago

vitaly-t commented 8 years ago

Why publish a separate module for transactions, and not even support nested transactions?

The thing about many nested calls though, this is a perfect example of running into the callback hell. Use of promises in this case is so much better. See this example of nested transactions.

kevinburkeshyp commented 8 years ago

Hey, thanks for writing. It's not a feature we've needed, which is why it's not in here. Transactions are pretty tricky to get right so we went with the simplest feature set we needed.

kevinburke commented 8 years ago

Also - I'm a little confused, I've been reading a fair amount and it seems like Postgres does not support nested transactions ? http://sqlblog.com/blogs/alexander_kuznetsov/archive/2013/11/25/learning-postgresql-no-nested-transactions-no-transactions-in-pl-pgsql.aspx

vitaly-t commented 8 years ago

@kevinburke that article was written by someone equally confused :)

Postgres does support nested transactions, but not the same way other SQL servers do.

On the first level you have your typical begin/commit/rollback, while on the nested levels you have to use their equivalents:

It gets more complicated because for this to work you need to track the nested level of all your transactions, in order to auto-generate unique level-names, not to mention support for name injection for transactions themselves - for easier debugging.

pg-promise, for example, does all that. It tracks the nested levels, it executes nested transactions correctly on any level, it provides automatic transaction naming for easy debugging. In fact, I do not know another library that can do all that today. If you find - please let me know :)

And it nicely hides from you all that ungodly complexity :)