鍍金池/ 問答/數(shù)據(jù)庫  HTML/ sequelize between用法問題

sequelize between用法問題

sequelize between不好用,代碼這么寫,但是打印出來的sql語句不對

const aaa = await DailyInfo.findAll({ // 
  where: {
    user_id: query.user_id,
    created_at: {
      $between: ['2018-03-01', '2018-03-15']
    }
  }
});    

clipboard.png

回答
編輯回答
尐潴豬

說明 between 這個 operator 沒有生效,有可能是 http://docs.sequelizejs.com/m... 的原因。
把 operatorsAliases 加上試試:

const Sequelize = require('sequelize');

const Op = Sequelize.Op;      
const operatorsAliases = {
    $eq: Op.eq,
    $ne: Op.ne,
    $gte: Op.gte,
    $gt: Op.gt,
    $lte: Op.lte,
    $lt: Op.lt,
    $not: Op.not,
    $in: Op.in,
    $notIn: Op.notIn,
    $is: Op.is,
    $like: Op.like,
    $notLike: Op.notLike,
    $iLike: Op.iLike,
    $notILike: Op.notILike,
    $regexp: Op.regexp,
    $notRegexp: Op.notRegexp,
    $iRegexp: Op.iRegexp,
    $notIRegexp: Op.notIRegexp,
    $between: Op.between,
    $notBetween: Op.notBetween,
    $overlap: Op.overlap,
    $contains: Op.contains,
    $contained: Op.contained,
    $adjacent: Op.adjacent,
    $strictLeft: Op.strictLeft,
    $strictRight: Op.strictRight,
    $noExtendRight: Op.noExtendRight,
    $noExtendLeft: Op.noExtendLeft,
    $and: Op.and,
    $or: Op.or,
    $any: Op.any,
    $all: Op.all,
    $values: Op.values,
    $col: Op.col
};

const sequelize = new Sequelize('db', 'user', 'pass', {
   
    host: 'localhost',
    dialect: 'mysql',
    pool: {},

    operatorsAliases: operatorsAliases,  //操作符安全
});
2017年1月7日 06:15