在传入参数的 sequalize 中调用存储过程 [英] Calling stored procedure in sequalize passing in a parameter
问题描述
我正在尝试调用传递参数的存储过程,如下所示.但是,我知道我的语法已关闭,而且我在文档或单元测试中都没有看到任何这样做的示例.
I'm trying to call a stored procedure passing in a parameter as shown below. However, I know my syntax is off and I don't see any examples doing this, either in the docs or unit tests.
model.sequelize.query('CALL truncate_tables(\'appuser\');')
.then(function (response) {
done();
}).error(function (err) {
done(err);
});
建议?
我开始查看此链接.在 Sequelize.js 中调用存储过程
附加信息:
这是我看到的错误
Unhandled rejection SequelizeDatabaseError: syntax error at or near "CALL"
这里是 sp
CREATE OR REPLACE FUNCTION truncate_tables(username character varying)
RETURNS void AS
$BODY$
DECLARE
statements CURSOR FOR
SELECT tablename FROM pg_tables
WHERE tableowner = username AND schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
END LOOP;
END;
$BODY$
推荐答案
我想你正在使用 PostgreSQL.
I suppose you are using PostgreSQL.
PostgreSQL 调用过程的语法与 MySQL 或 IBM Informix 等其他 DBMS 不同.它不会CALL
过程而是从存储过程中SELECT
s.可以在 https://www.postgresql.org 找到参考/message-id/41F009EA.6050401%40us.michelin.com.
PostgreSQL calls procedures with a syntax which is different from the other DBMS like MySQL or IBM Informix. It does not CALL
the procedure but instead SELECT
s from the stored procedure. A reference may be found at https://www.postgresql.org/message-id/41F009EA.6050401%40us.michelin.com.
也许这段代码可以工作:
Maybe this code would thus work:
model.sequelize.query('SELECT truncate_tables(\'appuser\');')
.then(function (response) {
done();
}).error(function (err) {
done(err);
});
这篇关于在传入参数的 sequalize 中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!