egg icon indicating copy to clipboard operation
egg copied to clipboard

sequelize operatorsAliases

Open ctocto opened this issue 4 years ago • 8 comments

What happens?

// config.default.js
const Op = require('sequelize').Op;
// "egg-sequelize": "^5.2.1",
exports.sequelize = {
  dialect: 'mysql',
 timezone: '+08:00',
  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,
  },
};

npm start 执行报错 image npm run dev 执行正常

最小可复现仓库

请使用 npm init egg --type=simple bug 创建,并上传到你的 GitHub 仓库

复现步骤,错误日志以及相关配置

相关环境信息

  • 操作系统:macos
  • Node 版本:12.14.1
  • Egg 版本:2.24.0

ctocto avatar Mar 08 '20 13:03 ctocto

我也遇到这样的情况了!

huaiguoguo avatar Apr 13 '20 06:04 huaiguoguo

@huacnlee @pmq20 @ctocto 我也遇到这样的情况了!

huaiguoguo avatar Apr 13 '20 06:04 huaiguoguo

sequelize 自身的报错吧,看下它给的链接呗。

atian25 avatar Apr 13 '20 07:04 atian25

sequelize 自身的报错吧,看下它给的链接呗。

[egg-scripts] Save log file to /root/logs [egg-scripts] Wait Start: 1... [egg-scripts] Wait Start: 2... [egg-scripts] tail -n 100 /root/logs/master-stderr.log [egg-scripts] Got error when startup: [egg-scripts] (node:13411) [SEQUELIZE0003] DeprecationWarning: String based operators are deprecated. Please use Symbol based operators for better security, read more at https://sequelize.org/master/manual/querying.html#operators [egg-scripts] [egg-scripts] Start got error, see /root/logs/master-stderr.log [egg-scripts] Or use --ignore-stderr to ignore stderr at startup.

链接在此: https://sequelize.org/master/manual/querying.html#operators 看了以上的链接,里面也没有什么内容

huaiguoguo avatar Apr 13 '20 07:04 huaiguoguo

sequelize 自身的报错吧,看下它给的链接呗。

https://sequelize.org/master/manual/model-querying-basics.html#deprecated--operator-aliases image

官方说明了,在sequelize 4版本当中可以使用这样的$like别名,但是egg-sequelize所依赖的sequelize 版本已经是最新的了(5.21.5, sequelize最新版本为: 5.21.6);

所以..... 但是官方说了,如果真的需要是可以通过配置,使用别名的($like, $or 等等) 可是现在npm run dev没报错, npm start报错了。。。。

huaiguoguo avatar Apr 13 '20 07:04 huaiguoguo

🙁我换成了新的写法

ctocto avatar Apr 14 '20 10:04 ctocto

🙁我换成了新的写法

新的写法是什么? [Op.like]: %asdasdf% 这样吗?

huaiguoguo avatar Apr 14 '20 12:04 huaiguoguo

asdasdf

是的

ctocto avatar Apr 15 '20 00:04 ctocto