Chore: make db.taskEx private
This commit is contained in:
parent
081957c957
commit
64e07fa8bd
2 changed files with 10 additions and 10 deletions
|
|
@ -9,13 +9,13 @@ const extendedQueries = require('./extendedQueries')
|
||||||
const pgp = Pgp({
|
const pgp = Pgp({
|
||||||
pgNative: true,
|
pgNative: true,
|
||||||
extend (obj, dbContext) {
|
extend (obj, dbContext) {
|
||||||
obj.taskEx = function () {
|
obj._taskEx = function () {
|
||||||
const args = pgp.utils.taskArgs(arguments)
|
const args = pgp.utils.taskArgs(arguments)
|
||||||
const { schema } = args.options
|
const { schema } = args.options
|
||||||
delete args.options.schema
|
delete args.options.schema
|
||||||
if (schema) {
|
if (schema) {
|
||||||
return obj.task.call(this, args.options, t => {
|
return obj.task.call(this, args.options, t => {
|
||||||
return t.none('SET search_path to $1:name', [schema])
|
return t.none('SET search_path TO $1:name', [schema])
|
||||||
.then(args.cb.bind(t, t))
|
.then(args.cb.bind(t, t))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ const stripDefaultDbFuncs = dbCtx => {
|
||||||
const any = (obj, query, variables) => {
|
const any = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.any(query, variables).then(res => {
|
return t.any(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -43,7 +43,7 @@ const any = (obj, query, variables) => {
|
||||||
const none = (obj, query, variables) => {
|
const none = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.none(query, variables).then(res => {
|
return t.none(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -55,7 +55,7 @@ const none = (obj, query, variables) => {
|
||||||
const one = (obj, query, variables) => {
|
const one = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.one(query, variables).then(res => {
|
return t.one(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -67,7 +67,7 @@ const one = (obj, query, variables) => {
|
||||||
const oneOrNone = (obj, query, variables) => {
|
const oneOrNone = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.oneOrNone(query, variables).then(res => {
|
return t.oneOrNone(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -79,7 +79,7 @@ const oneOrNone = (obj, query, variables) => {
|
||||||
const manyOrNone = (obj, query, variables) => {
|
const manyOrNone = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.manyOrNone(query, variables).then(res => {
|
return t.manyOrNone(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -91,7 +91,7 @@ const manyOrNone = (obj, query, variables) => {
|
||||||
const many = (obj, query, variables) => {
|
const many = (obj, query, variables) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.many(query, variables).then(res => {
|
return t.many(query, variables).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -103,7 +103,7 @@ const many = (obj, query, variables) => {
|
||||||
const result = (obj, query, variables, cb, thisArg) => {
|
const result = (obj, query, variables, cb, thisArg) => {
|
||||||
const schema = getSchema()
|
const schema = getSchema()
|
||||||
if (!schema) throw new Error(schemaNotFound(query))
|
if (!schema) throw new Error(schemaNotFound(query))
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.result(query, variables, cb, thisArg).then(res => {
|
return t.result(query, variables, cb, thisArg).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
@ -118,7 +118,7 @@ const query = (obj, query, variables, qrm, throwOnError) => {
|
||||||
if (throwOnError) throw new Error(schemaNotFound(query))
|
if (throwOnError) throw new Error(schemaNotFound(query))
|
||||||
return Promise.resolve(schemaNotFound(query))
|
return Promise.resolve(schemaNotFound(query))
|
||||||
}
|
}
|
||||||
return obj.taskEx({ schema }, t => {
|
return obj._taskEx({ schema }, t => {
|
||||||
return t.query(query, variables, qrm).then(res => {
|
return t.query(query, variables, qrm).then(res => {
|
||||||
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
return t.none('set search_path to $1~', [getDefaultSchema()]).then(() => {
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue