简体   繁体   中英

Conversion of an sql query to sequelize

I am trying to convert this sql query to sequelize. The sequelize query should have the same result as the sql query.

SELECT * FROM logs 
    WHERE createdAt >= '2020-06-24 00:00:00' 
        AND createdAt <= '2020-06-26 23:59:59'
        AND targetId = 192
        AND `type` = 1

#My current implementation

query = {
        [Op.and]: [
          { createdAt: { [Op.gte]: startDate } },
          { createdAt: { [Op.lte]: endDate } },
          { targetId: userId },
          { type: 1 },
        ],
      };

To make a query like yours, you need something like the following:

{
    where: {
        createdAt: {
          [Op.gte]: startDate,
          [Op.lte]: endDate
        },
        targetId: userId,
        type: 1
    }
}

More details in the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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