用于sequelize orm查询更改的SQL

时间:2017-07-07 15:18:06

标签: sql sequelize.js

SQL查询工作正常但在节点js中使用suquelize orm查询无效。

SQL:Woking Fine

select message from tbl_chat where (userId=1 or userId=98) and (receiverId=1 or receiverId=98) and isgroupChat=0;

Sequelize ORM:不工作

             let result = await Chat.findAll<Chat>({

            where: {
                isgroupChat: 0,
                $and: {
                    $or: [
                        {
                            userId: userId
                        },
                        {
                            userId: userId
                        }
                    ],
                    $or: [
                        {
                            receiverId: receiverId
                        },
                        {
                            receiverId: receiverId
                        }
                    ]
                }
            }
        });

1 个答案:

答案 0 :(得分:0)

不确定为什么这不起作用。打开日志记录,查看ORM为查询生成的内容。但是,我也尝试稍微更改一下查询:

CREATE OR REPLACE FUNCTION f_example(p_table, p_column)
BEGIN
FOR v_iter in (EXECUTE IMMEDIATE 'select ' || p_column || ' from ' || p_table) LOOP
DBMS_OUTPUT.PUTLINE(v_iter.p_column);
END LOOP;
END;