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

阅读 8.5k
1 个回答

说明 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,  //操作符安全
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题