Fix: use .finally() to change schema back to original

This commit is contained in:
csrapr 2021-06-14 16:05:51 +01:00 committed by Josh Harvey
parent eb5732003e
commit 51f9f86fa9

View file

@ -38,16 +38,7 @@ const getDefaultSchema = () => 'ERROR_SCHEMA'
const searchPathWrapper = (t, cb) => { const searchPathWrapper = (t, cb) => {
return t.none('SET search_path TO $1:name', [getSchema()]) return t.none('SET search_path TO $1:name', [getSchema()])
.then(cb.bind(t, t)) .then(cb.bind(t, t))
.then(res => { .finally(() => t.none('SET search_path TO $1:name', [getDefaultSchema()]))
return t.none('SET search_path TO $1:name', [getDefaultSchema()]).then(() => {
return res
})
})
.catch(err => {
return t.none('SET search_path TO $1:name', [getDefaultSchema()]).then(() => {
throw err
})
})
} }
const pgp = Pgp({ const pgp = Pgp({