Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize invalid value Symbol(ne)

I have the following two files running on an Express Node.js server:

home.js

var express = require('express')
var sequelize = require('sequelize')
var db = require('../../shared/db.js')

var op = sequelize.Op

var router = express.Router()

router.get('/home', function(req, res, next) {
    db.shared.person.findAll({
        where: {
            email: {
                [op.ne]: null
            }
        },
        order: ['id']
    }).then(function (person) {
        res.locals = {
            person: person
        }
        res.render('home')
    })
})

module.exports = router

db.js

var sequelize = require('sequelize')

var config = {
  host: 'localhost',
  port: 5432,
  username: '...',
  password: '...',
  database: 'postgres',
  dialect: 'postgres',
  operatorsAliases: false
}
var db = new sequelize(config)

module.exports = {
  shared: {
    person: db.define('person', {
      id: {
        type: sequelize.INTEGER,
        primaryKey: true
      },
      name: sequelize.STRING,
      email: sequelize.INTEGER
    }, { freezeTableName: true , timestamps: false, schema: 'shared' }),
  }
}

When I try to run this query, I get an error claiming Unhandled rejection Error: Invalid value { [Symbol(ne)]: null }

What am I doing wrong? I can use $ne and even ne just fine but they've been deprecated and are not entirely safe to use. Furthermore, it's not just [op.ne] - I get this error when I use any conditional like this.

I'm basing this all on this guide so I'm not really sure what I could be doing wrong here.

like image 236
undefined Avatar asked Oct 27 '25 05:10

undefined


1 Answers

Unhandled rejection Error: Invalid value might also appear if you didn't setup string aliases like this:

const Op = Sequelize.Op;
const operatorsAliases = {
  $eq: Op.eq,
  $ne: Op.ne,
  ...
  $any: Op.any,
  $all: Op.all,
  $values: Op.values,
  $col: Op.col
};

const connection = new Sequelize(db, user, pass, { operatorsAliases });

But, better to remove String based aliases from code and use [Op.ne] for example, Sequlize is planning to deprecate them soon.

like image 138
Marko Balažic Avatar answered Oct 28 '25 19:10

Marko Balažic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!