pg-promise - 程序示例
pg-promise - Example with procedure
我在几个项目中使用 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 的示例(可以 fail/sucess 的人)...
谢谢
由于PostgreSQL只支持函数,所以过程被认为是这样一种函数,即returns没有数据或简单的响应,例如操作摘要。
因此 pg-promise implements method proc 不需要数据或只有一个 row/object 数据。
const res = await db.proc('procName', [123, new Date()]);
//=> either null or a single object with OUT properties
更新
自从PostgreSQL v11 出来后,支持适当的存储过程。 pg-promise has been updated where method proc 现在仅支持新的 CALL
语法。
我在几个项目中使用 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 的示例(可以 fail/sucess 的人)...
谢谢
由于PostgreSQL只支持函数,所以过程被认为是这样一种函数,即returns没有数据或简单的响应,例如操作摘要。
因此 pg-promise implements method proc 不需要数据或只有一个 row/object 数据。
const res = await db.proc('procName', [123, new Date()]);
//=> either null or a single object with OUT properties
更新
自从PostgreSQL v11 出来后,支持适当的存储过程。 pg-promise has been updated where method proc 现在仅支持新的 CALL
语法。