JK36
JK36

Reputation: 853

Sequelize Deprecated Error Message

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.

Upvotes: 14

Views: 36958

Answers (3)

BartusZak
BartusZak

Reputation: 1253

Updating to version:

"sequelize": "^5.8.6"

and removing operatorsAliases param from

new Sequelize()

removed depreciation warning

Upvotes: 10

Frank HN
Frank HN

Reputation: 535

const sequelize = new Sequelize({
  username: process.env.DBUSERNAME,
  host: process.env.DBHOST,
  database: process.env.DBNAME,
  password: process.env.DBPASSWORD,
  dialect: 'postgres',
  define: {
    timestamps: false,
  },
  operatorsAliases: false,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },

});

Upvotes: -2

user3139574
user3139574

Reputation: 1169

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 [email protected] 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
    }
  }
)

Upvotes: 36

Related Questions