I am using pg-promise for my project. I have a scenario, where I have to insert in two tables, where the 2nd table needs the pk of 1st table as fk. How to do this using pg-promise transaction ? In docs I could only see non relational operations, is there any way to do this ?
Asked
Active
Viewed 40 times
0
-
It's all in the docs: https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#tasks. Switching from `.task` to `.tx` makes it a transaction. – vitaly-t May 13 '17 at 17:51
-
The answer here is exactly what you need: http://stackoverflow.com/questions/43797917/pg-promise-use-result-of-one-query-in-next-query-within-a-transaction. Even more examples: http://stackoverflow.com/questions/37051683/optional-insert-statement-in-transaction-chain-using-nodejs-and-postgres – vitaly-t May 13 '17 at 17:55