{"action":"created","issue":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/33","labels_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/33/comments","events_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/33/events","html_url":"https://github.com/vitaly-t/pg-promise/issues/33","id":94027313,"number":33,"title":"Detached transaction using results from one query for remainder queries","user":{"login":"Maximization","id":9811142,"avatar_url":"https://avatars.githubusercontent.com/u/9811142?v=3","gravatar_id":"","url":"https://api.github.com/users/Maximization","html_url":"https://github.com/Maximization","followers_url":"https://api.github.com/users/Maximization/followers","following_url":"https://api.github.com/users/Maximization/following{/other_user}","gists_url":"https://api.github.com/users/Maximization/gists{/gist_id}","starred_url":"https://api.github.com/users/Maximization/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maximization/subscriptions","organizations_url":"https://api.github.com/users/Maximization/orgs","repos_url":"https://api.github.com/users/Maximization/repos","events_url":"https://api.github.com/users/Maximization/events{/privacy}","received_events_url":"https://api.github.com/users/Maximization/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-09T11:54:49Z","updated_at":"2015-07-09T12:38:47Z","closed_at":null,"body":"Hi Vitaly,\r\n\r\nFirst of all let me say a big thank you to you for the time and effort you've spend creating this library. The documentation is well-written. I'm surprised to see so few stars but I'm sure it will gain a lot of traction in the near future.\r\n\r\nI have one specific use case which I can't seem to resolve. I have a detached transaction starting with a query returning one result and several subsequent queries which make use of that result. It seems like a simple task but I couldn't find guidance in any of the examples. I'm not a promise expert either so that doesn't help. Here's an example of what I have:\r\n\r\n```javascript\r\ndb.tx(function (t) {\r\n    return t.one('INSERT INTO table1(col1) VALUES($1) RETURNING id', [123])\r\n        .then(function (data) {\r\n            return promise.all([\r\n                t.none('INSERT INTO table2(col1, col2) VALUES($1, $2)', [data.id, \"John\"]),\r\n                t.none('INSERT INTO table2(col1, col2) VALUES($1, $2)', [data.id, \"Mary\"])\r\n            ]);\r\n        });\r\n})\r\n    .then(function (data) {\r\n        // Success, do something with data...\r\n        return res.status(200).json(data);\r\n    }, function (reason) {\r\n        // Error\r\n        return res.json(reason);\r\n    });\r\n```\r\n\r\nAs you can use I use the result from the first query in subsequent queries. I also use this result after the transaction resolves successfully. What am I doing wrong here?"},"comment":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/comments/119948126","html_url":"https://github.com/vitaly-t/pg-promise/issues/33#issuecomment-119948126","issue_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/33","id":119948126,"user":{"login":"Maximization","id":9811142,"avatar_url":"https://avatars.githubusercontent.com/u/9811142?v=3","gravatar_id":"","url":"https://api.github.com/users/Maximization","html_url":"https://github.com/Maximization","followers_url":"https://api.github.com/users/Maximization/followers","following_url":"https://api.github.com/users/Maximization/following{/other_user}","gists_url":"https://api.github.com/users/Maximization/gists{/gist_id}","starred_url":"https://api.github.com/users/Maximization/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maximization/subscriptions","organizations_url":"https://api.github.com/users/Maximization/orgs","repos_url":"https://api.github.com/users/Maximization/repos","events_url":"https://api.github.com/users/Maximization/events{/privacy}","received_events_url":"https://api.github.com/users/Maximization/received_events","type":"User","site_admin":false},"created_at":"2015-07-09T12:38:47Z","updated_at":"2015-07-09T12:38:47Z","body":"You're right, the success promise does execute.\r\n\r\nHowever, I get undefined for console.log(data). That's preventing returning a success status back to the client. I was manipulating the data which I didn't have. Do you know how I could get the result from the first query passed all the way to the end? "}}