I have seen pg-promise tasks and tx to reuse same connection we can use
db.task(t => {
return t.one('SELECT id FROM Users WHERE name = $1', 'John')
.then(user => {
return t.any('SELECT * from Events WHERE userId = $1', user.id);
});}).then(events => {// success
}).catch(error => {
// error
});
But what if I have two different files and e.g. UsersModel.getUser(username) and EvenModel.getUserEvent(userId). Is there any way I can pass transaction or task objects.
thanks
via dev123
No comments:
Post a Comment