简体   繁体   English

如何使用 sequelize 在查询中创建条件?

[英]How can I make a conditional in a query using sequelize?

I need to create a conditional in the query where if enabled = 1 or enabled = 2.我需要在查询中创建一个条件,如果启用 = 1 或启用 = 2。

const existBusiness = await Business.findOne({
  where: { id, enabled: 1, enabled: 2 },
});

For example: if(enabled == 1 || enabled == 2)例如: if(enabled == 1 || enabled == 2)

const { Op } = require("sequelize");

const existBusiness = await Business.findOne({
    where: {
     [Op.or]: [
       {enabled: 1},
       {enabled: 2}
      ]
    }
  });

More information on Sequelize operators is available here .有关 Sequelize 运算符的更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM