node.jspostgresqltransactionssails.jssails-postgresql

How can I use PostgreSQL transactions in SailsJs?


My problem is that i have a complex chain of queries and it make rollback if someone of this transactions fail. I've read about transactions in Sails and, for default, Sails don't support transactions because each transaction make a new connection with Postgres, so, one query have a new connection. So, how i can use transactions with Sails?


Solution

  • Currently transactions are not supported by waterline. You can join the discussion here https://github.com/balderdashy/waterline/issues/755.

    Transactions are on the roadmap but are not expected in near future: https://github.com/balderdashy/waterline/blob/master/ROADMAP.md#pending-proposals

    As a workaround you might try https://github.com/Shyp/pg-transactions however you will loose the flexibility of waterline because your code will not be database agnostic any more.

    Also check Sails.js best practice in using transactions with promises (Postgres) and Sails.js + Postgres: issue with transactions