pg-promise: use result of one query in next query within a transaction

不想你离开。 提交于 2019-12-06 01:33:08

Method sequence is there to run infinite sequences, which got nothing to do with what you are trying to achieve - a standard / trivial transaction:

db.tx(t => {
    return t.one('INSERT INTO table1(a, b) VALUES($1, $2) RETURNING id', [1, 2], x=>+x.id)
        .then(id => {
            return t.none('INSERT INTO table2(id, a_id) VALUES($1, $2)', [1, id]);
        });
})
    .then(data => {
        // success, data = null
    })
    .catch(error => {
        // error
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!