Sequelize 已弃用的错误消息 [英] Sequelize Deprecated Error Message

查看:43
本文介绍了Sequelize 已弃用的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Node 非常陌生,我正在了解 ORM 和 Sequelize 的工作原理.我一直在 Sequelize 网站上复制连接字符串并将其更改为与我的数据库一起使用.当我执行文件时,它似乎在我的数据库中创建表执行正常,但是我收到错误基于字符串的运算符现在已弃用.请使用基于符号的运算符以获得更好的安全性....node_modules/sequelize/lib/sequelize.js:236:13" 我理解为什么不推荐使用运算符,但是因为我已将其安装为新软件包并使用文档中的连接字符串,从而避免使用任何非法运算符,我假设此错误消息是正确的仅供参考,未反映在我刚刚使用的代码中.

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.

我包含了导致错误的 for app 文件,是不是可能导致此错误的密码.

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 ****

我已经想通了,我会留下这个答案,以防其他人遇到问题.您需要包含 { operatorsAliases: false } 以消除连接中的错误消息.

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.

推荐答案

这些是我为这个弃用警告找到的最好的解释:

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

添加operatorsAliases: false"确实覆盖了我的应用程序中的警告消息.

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
  }
)

注意:从 sequelize@4.20.1 开始,我开始收到来自 Sequelize 的无效值"错误.我心软并使用以下代码启用符号运算符:

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
    }
  }
)

这篇关于Sequelize 已弃用的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆