gpt4 book ai didi

node.js - pg-promise - 程序示例

转载 作者:行者123 更新时间:2023-11-29 13:50:14 27 4
gpt4 key购买 nike

我使用 pg-promise对于几个项目。我读了这个:

Functions and Procedures

In PostgreSQL stored procedures are just functions that usually do not return anything.

Suppose we want to call function findAudit to find audit records by user_id and maximum timestamp. We can make such call as shown below:

db.func('findAudit', [123, new Date()])
.then(function (data) {
console.log(data); // printing the data returned
})
.catch(function (error) {
console.log(error); // printing the error
});

文档提供了除这两个函数之外的示例。 (注意:否则会有很好的文档)

有人可以提供一个程序示例吗 pg-promise

PS:我知道什么是 Postgresql 中的存储过程,但我没有找到 pg-promise 的示例(一个可能失败/成功的人)...

谢谢

最佳答案

由于 PostgreSQL 只支持函数,过程被认为是这样一种函数,要么不返回任何数据,要么返回简单的响应,例如操作摘要。

因此 pg-promise实现方法 proc不需要数据或单行/数据对象。

const res = await db.proc('procName', [123, new Date()]);
//=> either null or a single object with OUT properties

更新

自从 PostgreSQL v11 出来后,支持适当的存储过程。和 pg-promise已更新方法proc现在仅支持新的 CALL 语法。

关于node.js - pg-promise - 程序示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42380005/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com