Sequelize Deprecated Error Message

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I'm very new to Node and I'm getting my head around how ORM and Sequelize works. I've been on the Sequelize website and copied the connection string and altered it to work with my database. When I execute the file, it seems to execute OK creating the table in my database however I get the error "String based operators are now deprecated.Please use Symbol based operators for better security ....node_modules/sequelize/lib/sequelize.js:236:13" I understand why the operators have been deprecated, however as I've installed this as a new package and used the connection string from the documentation, thus avoiding using any illegal operators am I right in assuming this error message is for info only and not reflected in the code I have just used.

I include my for app file that is bringing up the error, is it the password that maybe causing this.

const express = require('express'); const app = express();  const Sequelize = require('sequelize');  const db = new Sequelize('myDBName', 'mYuSeRnAmE', 'mYpAsSw!ORd$', { host: 'mySqlserverName',   dialect: 'mssql',    pool: {     max: 5,     min: 0,     idle: 10000   },  });   var Article = db.define('Article', {     title: Sequelize.STRING,     body: Sequelize.TEXT });  db.sync();  module.exports = app; 

**** Edit ****

I've figured it out, I'll leave this answer up just incase someone else runs into the problem. You need to include { operatorsAliases: false } to get rid of the error message in the connection.

回答1:

These were the best explanations that I found for this deprecation warning:

https://github.com/sequelize/sequelize/issues/8417

http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliases

Adding "operatorsAliases: false" did override the warning message in my application.

const Sequelize = require('sequelize') const sequelize = new Sequelize(   DB_NAME,   USERNAME,    PASSWORD,   {     host: HOSTNAME,     dialect: 'mysql',     logging: false,     freezeTableName: true,     operatorsAliases: false   } ) 

Note: as of sequelize@4.20.1 I started receiving "Invalid value" errors from Sequelize. I relented and used the following code to enable symbol operators:

const Sequelize = require('sequelize') const Op = Sequelize.Op const sequelize = new Sequelize(   DB_NAME,   USERNAME,    PASSWORD,   {     host: HOSTNAME,     dialect: 'mysql',     logging: false,     freezeTableName: true,     operatorsAliases: {       $and: Op.and,       $or: Op.or,       $eq: Op.eq,       $gt: Op.gt,       $lt: Op.lt,       $lte: Op.lte,       $like: Op.like     }   } ) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!