PostgreSQL void 函数的 pg-promise 方法
pg-promise method for PostgreSQL void function
当执行 RETURNS void
的 PostgreSQL 函数时,db.none()
拒绝 "No return data was expected."
。
然后我使用 db.one()
方法,该方法解析为对象 { PS_name: '' }
。
我应该期望 PostgreSQL void 函数实际上 return 一个空对象吗?使用 pg-promise
处理 void 函数的最合适方法是什么?
下面的答案不再有效,因为 PostgreSQL v11 添加了对正确存储过程的支持,方法 proc 现在只能调用存储过程,使用新的 CALL
语法。
What would be the most appropriate way of handling void functions with pg-promise?
数据库方法proc.
db.proc('proc_name', [param1, param2,...])
.then(data => {
/* data = either null or an object */
})
.catch(error => {
/* error */
});
更新
How do you specify the parameter types when using proc
? i.e., to fix function foo(unknown) does not exist
? If I do db.proc('foo(::int2[])', x)
, then it throws syntax error at or near "("
.
您不能使用方法 proc 来完成此操作,创建该方法是为了让事情变得非常简单。如果您的调用需要 SQL 类型转换,您需要将其作为常规查询执行,并在模板内进行转换:
db.oneOrNone('SELECT * FROM proc_name(::int2[], , ...)', [param1, param2,...])
.then(data => {
/* data = either null or an object */
})
.catch(error => {
/* error */
});
当执行 RETURNS void
的 PostgreSQL 函数时,db.none()
拒绝 "No return data was expected."
。
然后我使用 db.one()
方法,该方法解析为对象 { PS_name: '' }
。
我应该期望 PostgreSQL void 函数实际上 return 一个空对象吗?使用 pg-promise
处理 void 函数的最合适方法是什么?
下面的答案不再有效,因为 PostgreSQL v11 添加了对正确存储过程的支持,方法 proc 现在只能调用存储过程,使用新的 CALL
语法。
What would be the most appropriate way of handling void functions with pg-promise?
数据库方法proc.
db.proc('proc_name', [param1, param2,...])
.then(data => {
/* data = either null or an object */
})
.catch(error => {
/* error */
});
更新
How do you specify the parameter types when using
proc
? i.e., to fixfunction foo(unknown) does not exist
? If I dodb.proc('foo(::int2[])', x)
, then it throwssyntax error at or near "("
.
您不能使用方法 proc 来完成此操作,创建该方法是为了让事情变得非常简单。如果您的调用需要 SQL 类型转换,您需要将其作为常规查询执行,并在模板内进行转换:
db.oneOrNone('SELECT * FROM proc_name(::int2[], , ...)', [param1, param2,...])
.then(data => {
/* data = either null or an object */
})
.catch(error => {
/* error */
});