不要怂,就是干,撸起袖子干!

Commit 4ba7beac by Sushant Committed by GitHub

change(operators): use symbol operators (#9278)

1 parent 8e2517fb
Showing with 192 additions and 262 deletions
...@@ -25,9 +25,6 @@ With v5 ...@@ -25,9 +25,6 @@ With v5
- You can still use string operators by passing an operators map in `operatorsAliases` - You can still use string operators by passing an operators map in `operatorsAliases`
- Op.$raw is removed - Op.$raw is removed
__DEV__: _Incomplete, deprecated_
### Model ### Model
**Attributes** **Attributes**
...@@ -38,7 +35,7 @@ __Note__: _Please dont confuse this with `options.attributes`, they are still va ...@@ -38,7 +35,7 @@ __Note__: _Please dont confuse this with `options.attributes`, they are still va
**Paranoid Mode** **Paranoid Mode**
With v5 if `deletedAt` is set, record will be considered as deleted. So `paranoid` option will only use `deletedAt` as flag. With v5 if `deletedAt` is set, record will be considered as deleted. `paranoid` option will only use `deletedAt` as flag.
In v4 it used to compare current time with `deletedAt`. [#8496](https://github.com/sequelize/sequelize/issues/8496) In v4 it used to compare current time with `deletedAt`. [#8496](https://github.com/sequelize/sequelize/issues/8496)
......
...@@ -81,69 +81,4 @@ const Op = { ...@@ -81,69 +81,4 @@ const Op = {
join: Symbol.for('join') join: Symbol.for('join')
}; };
const Aliases = {
$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,
};
const LegacyAliases = { //deprecated remove by v5.0
'ne': Op.ne,
'not': Op.not,
'in': Op.in,
'notIn': Op.notIn,
'gte': Op.gte,
'gt': Op.gt,
'lte': Op.lte,
'lt': Op.lt,
'like': Op.like,
'ilike': Op.iLike,
'$ilike': Op.iLike,
'nlike': Op.notLike,
'$notlike': Op.notLike,
'notilike': Op.notILike,
'..': Op.between,
'between': Op.between,
'!..': Op.notBetween,
'notbetween': Op.notBetween,
'nbetween': Op.notBetween,
'overlap': Op.overlap,
'&&': Op.overlap,
'@>': Op.contains,
'<@': Op.contained
};
Op.Aliases = Aliases;
Op.LegacyAliases = Object.assign({}, LegacyAliases, Aliases);
module.exports = Op; module.exports = Op;
\ No newline at end of file
...@@ -238,10 +238,9 @@ class Sequelize { ...@@ -238,10 +238,9 @@ class Sequelize {
this.dialect = new Dialect(this); this.dialect = new Dialect(this);
this.dialect.QueryGenerator.typeValidation = options.typeValidation; this.dialect.QueryGenerator.typeValidation = options.typeValidation;
if (this.options.operatorsAliases === true) {
Utils.deprecate('String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators'); if (_.isPlainObject(this.options.operatorsAliases)) {
this.dialect.QueryGenerator.setOperatorsAliases(Op.LegacyAliases); //Op.LegacyAliases should be removed and replaced by Op.Aliases by v5.0 use Utils.deprecate('String based operators are deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators');
} else {
this.dialect.QueryGenerator.setOperatorsAliases(this.options.operatorsAliases); this.dialect.QueryGenerator.setOperatorsAliases(this.options.operatorsAliases);
} }
...@@ -331,9 +330,7 @@ class Sequelize { ...@@ -331,9 +330,7 @@ class Sequelize {
* *
* sequelize.models.modelName // The model will now be available in models under the name given to define * sequelize.models.modelName // The model will now be available in models under the name given to define
*/ */
define(modelName, attributes, options) { define(modelName, attributes, options = {}) {
options = options || {};
options.modelName = modelName; options.modelName = modelName;
options.sequelize = this; options.sequelize = this;
...@@ -366,8 +363,7 @@ class Sequelize { ...@@ -366,8 +363,7 @@ class Sequelize {
* @return {Boolean} * @return {Boolean}
*/ */
isDefined(modelName) { isDefined(modelName) {
const models = this.modelManager.models; return !!this.modelManager.models.find(model => model.name === modelName);
return models.filter(model => model.name === modelName).length !== 0;
} }
/** /**
...@@ -1046,21 +1042,6 @@ class Sequelize { ...@@ -1046,21 +1042,6 @@ class Sequelize {
return res; return res;
} }
/*
* Getter/setter for `Sequelize.cls`
* To maintain backward compatibility with Sequelize v3.x
* Calling the
*/
static get cls() {
Utils.deprecate('Sequelize.cls is deprecated and will be removed in a future version. Keep track of the CLS namespace you use in your own code.');
return this._cls;
}
static set cls(ns) {
Utils.deprecate('Sequelize.cls should not be set directly. Use Sequelize.useCLS().');
this.useCLS(ns);
}
log() { log() {
let options; let options;
let args = Utils.sliceArgs(arguments); let args = Utils.sliceArgs(arguments);
......
...@@ -9,6 +9,7 @@ const chai = require('chai'), ...@@ -9,6 +9,7 @@ const chai = require('chai'),
sinon = require('sinon'), sinon = require('sinon'),
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
current = Support.sequelize, current = Support.sequelize,
Op = current.Op,
dialect = Support.getTestDialect(); dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('BelongsToMany'), () => { describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...@@ -110,7 +111,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -110,7 +111,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return john.getTasks({ return john.getTasks({
where: { where: {
title: { title: {
not: ['Get rich'] [Op.not]: ['Get rich']
} }
} }
}); });
...@@ -130,7 +131,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -130,7 +131,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return john.getTasks({ return john.getTasks({
where: { where: {
id: { id: {
not: [self.tasks[0].get('id')] [Op.not]: [self.tasks[0].get('id')]
} }
} }
}); });
...@@ -2039,7 +2040,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2039,7 +2040,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
model: self.Task, model: self.Task,
where: { where: {
title: { title: {
$ne: 'task' [Op.ne]: 'task'
} }
} }
}] }]
......
...@@ -10,6 +10,7 @@ const chai = require('chai'), ...@@ -10,6 +10,7 @@ const chai = require('chai'),
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
current = Support.sequelize, current = Support.sequelize,
_ = require('lodash'), _ = require('lodash'),
Op = current.Op,
dialect = Support.getTestDialect(); dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('HasMany'), () => { describe(Support.getTestDialectTeaser('HasMany'), () => {
...@@ -1036,7 +1037,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1036,7 +1037,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
this.article = article; this.article = article;
return article.setLabels([label1, label2]); return article.setLabels([label1, label2]);
}).then(function() { }).then(function() {
return this.article.getLabels({where: {until: {$gt: moment('2014-01-02').toDate()}}}); return this.article.getLabels({where: {until: {[Op.gt]: moment('2014-01-02').toDate()}}});
}).then(labels => { }).then(labels => {
expect(labels).to.be.instanceof(Array); expect(labels).to.be.instanceof(Array);
expect(labels).to.have.length(1); expect(labels).to.have.length(1);
......
...@@ -4,6 +4,7 @@ const chai = require('chai'), ...@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
Sequelize = Support.Sequelize, Sequelize = Support.Sequelize,
Op = Sequelize.Op,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
DataTypes = require(__dirname + '/../../../../lib/data-types'), DataTypes = require(__dirname + '/../../../../lib/data-types'),
...@@ -504,10 +505,10 @@ if (dialect.match(/^postgres/)) { ...@@ -504,10 +505,10 @@ if (dialect.match(/^postgres/)) {
return User.findAll({ return User.findAll({
where: { where: {
type: { type: {
$in: ['A', 'C'] [Op.in]: ['A', 'C']
}, },
permissions: { permissions: {
$contains: ['write'] [Op.contains]: ['write']
} }
} }
}); });
......
...@@ -4,6 +4,7 @@ const chai = require('chai'), ...@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
Sequelize = Support.Sequelize, Sequelize = Support.Sequelize,
Op = Sequelize.Op,
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
DataTypes = require(__dirname + '/../../../../lib/data-types'); DataTypes = require(__dirname + '/../../../../lib/data-types');
...@@ -39,7 +40,7 @@ if (dialect === 'sqlite') { ...@@ -39,7 +40,7 @@ if (dialect === 'sqlite') {
return user.save().then(() => { return user.save().then(() => {
return this.User.create({ username: 'new user' }).then(() => { return this.User.create({ username: 'new user' }).then(() => {
return this.User.findAll({ return this.User.findAll({
where: { createdAt: { $gt: new Date(2012, 1, 1) } } where: { createdAt: { [Op.gt]: new Date(2012, 1, 1) } }
}).then(users => { }).then(users => {
expect(users).to.have.length(1); expect(users).to.have.length(1);
}); });
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
...@@ -1310,7 +1311,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1310,7 +1311,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{model: Tag, as: 'Category'}, {model: Tag, as: 'Category'},
{model: Price, where: { {model: Price, where: {
value: { value: {
gt: 15 [Op.gt]: 15
} }
}} }}
]} ]}
...@@ -1575,7 +1576,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1575,7 +1576,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{model: self.models.Company}, {model: self.models.Company},
{model: self.models.Tag}, {model: self.models.Tag},
{model: self.models.Price, where: { {model: self.models.Price, where: {
value: {gt: 5} value: { [Op.gt]: 5}
}} }}
], ],
limit: 6, limit: 6,
......
...@@ -4,6 +4,7 @@ const chai = require('chai'), ...@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
sinon = require('sinon'), sinon = require('sinon'),
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
Op = Support.Sequelize.Op,
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
Promise = require('bluebird'); Promise = require('bluebird');
...@@ -332,10 +333,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -332,10 +333,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
include: [ include: [
{ {
model: Project, model: Project,
where: { '$and': [{ m: 'A' }] }, where: { [Op.and]: [{ m: 'A' }] },
include: [{ include: [{
model: User, model: User,
where: { '$and': [{ name: 'user-name-2' }] } where: { [Op.and]: [{ name: 'user-name-2' }] }
} }
] ]
}, },
...@@ -381,15 +382,15 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -381,15 +382,15 @@ describe(Support.getTestDialectTeaser('Include'), () => {
limit: 1, limit: 1,
offset: 1, offset: 1,
where: sequelize.or( where: sequelize.or(
{ first_name: { like: '%user-fname%' } }, { first_name: { [Op.like]: '%user-fname%' } },
{ last_name: { like: '%user-lname%' } } { last_name: { [Op.like]: '%user-lname%' } }
), ),
include: [ include: [
{ {
model: Project, model: Project,
required: true, required: true,
where: { name: { where: { name: {
$in: ['naam-satya', 'guru-satya'] [Op.in]: ['naam-satya', 'guru-satya']
}} }}
} }
] ]
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
...@@ -1027,7 +1028,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ...@@ -1027,7 +1028,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
{model: Tag, as: 'Category'}, {model: Tag, as: 'Category'},
{model: Price, where: { {model: Price, where: {
value: { value: {
gt: 15 [Op.gt]: 15
} }
}} }}
]} ]}
...@@ -1124,7 +1125,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ...@@ -1124,7 +1125,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
{model: self.models.Company}, {model: self.models.Company},
{model: self.models.Tag}, {model: self.models.Tag},
{model: self.models.Price, where: { {model: self.models.Price, where: {
value: {gt: 5} value: { [Op.gt]: 5}
}} }}
], ],
limit: 6, limit: 6,
......
...@@ -11,6 +11,7 @@ const chai = require('chai'), ...@@ -11,6 +11,7 @@ const chai = require('chai'),
moment = require('moment'), moment = require('moment'),
Promise = require('bluebird'), Promise = require('bluebird'),
current = Support.sequelize, current = Support.sequelize,
Op = Sequelize.Op,
semver = require('semver'); semver = require('semver');
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
...@@ -125,7 +126,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -125,7 +126,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
{aNumber: 10}, {aNumber: 10},
{aNumber: 12} {aNumber: 12}
]).then(() => { ]).then(() => {
return UserTable.findAll({where: {aNumber: { gte: 10 }}}).then(users => { return UserTable.findAll({where: {aNumber: { [Op.gte]: 10 }}}).then(users => {
expect(moment(user.createdAt).format('YYYY-MM-DD')).to.equal('2012-01-01'); expect(moment(user.createdAt).format('YYYY-MM-DD')).to.equal('2012-01-01');
expect(moment(user.updatedAt).format('YYYY-MM-DD')).to.equal('2012-01-02'); expect(moment(user.updatedAt).format('YYYY-MM-DD')).to.equal('2012-01-02');
users.forEach(u => { users.forEach(u => {
...@@ -1884,7 +1885,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1884,7 +1885,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const self = this; const self = this;
return this.User.create({username: 'user1'}).then(() => { return this.User.create({username: 'user1'}).then(() => {
return self.User.create({username: 'foo'}).then(() => { return self.User.create({username: 'foo'}).then(() => {
return self.User.count({where: {username: {$like: '%us%'}}}).then(count => { return self.User.count({where: {username: {[Op.like]: '%us%'}}}).then(count => {
expect(count).to.equal(1); expect(count).to.equal(1);
}); });
}); });
...@@ -2693,7 +2694,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -2693,7 +2694,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.sequelize.or({ username: 'leia' }, { username: 'luke' }), this.sequelize.or({ username: 'leia' }, { username: 'luke' }),
this.sequelize.and( this.sequelize.and(
{ id: [1, 2, 3] }, { id: [1, 2, 3] },
this.sequelize.or({ deletedAt: null }, { deletedAt: { gt: new Date(0) } }) this.sequelize.or({ deletedAt: null }, { deletedAt: { [Op.gt]: new Date(0) } })
) )
] ]
}) })
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
...@@ -57,7 +58,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -57,7 +58,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({ return self.User.find({
where: { where: {
name: { name: {
$regexp: '^Foo' [Op.regexp]: '^Foo'
} }
} }
}); });
...@@ -75,7 +76,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -75,7 +76,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({ return self.User.find({
where: { where: {
name: { name: {
$notRegexp: '^Foo' [Op.notRegexp]: '^Foo'
} }
} }
}); });
...@@ -94,7 +95,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -94,7 +95,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({ return self.User.find({
where: { where: {
name: { name: {
$iRegexp: '^foo' [Op.iRegexp]: '^foo'
} }
} }
}); });
...@@ -112,7 +113,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -112,7 +113,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({ return self.User.find({
where: { where: {
name: { name: {
$notIRegexp: '^foo' [Op.notIRegexp]: '^foo'
} }
} }
}); });
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
...@@ -88,7 +89,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -88,7 +89,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return User.findAll({ return User.findAll({
where: { where: {
updatedAt: { updatedAt: {
ne: null [Op.ne]: null
} }
} }
}).then(users => { }).then(users => {
......
...@@ -8,6 +8,7 @@ const chai = require('chai'), ...@@ -8,6 +8,7 @@ const chai = require('chai'),
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
Op = Sequelize.Op,
_ = require('lodash'), _ = require('lodash'),
assert = require('assert'), assert = require('assert'),
current = Support.sequelize; current = Support.sequelize;
...@@ -150,7 +151,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -150,7 +151,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
.then(() => User.create({ username: 'gottlieb' })) .then(() => User.create({ username: 'gottlieb' }))
.then(() => User.findOrCreate({ .then(() => User.findOrCreate({
where: { where: {
$or: [{ [Op.or]: [{
objectId: 'asdasdasd1' objectId: 'asdasdasd1'
}, { }, {
objectId: 'asdasdasd2' objectId: 'asdasdasd2'
...@@ -686,7 +687,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -686,7 +687,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return User.findOne({ return User.findOne({
where: { where: {
updatedAt: { updatedAt: {
ne: null [Op.ne]: null
} }
} }
}).then(user => { }).then(user => {
......
...@@ -5,6 +5,7 @@ const chai = require('chai'), ...@@ -5,6 +5,7 @@ const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
Op = Sequelize.Op,
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
config = require(__dirname + '/../../config/config'), config = require(__dirname + '/../../config/config'),
...@@ -103,7 +104,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -103,7 +104,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
username: { username: {
like: '%2' [Op.like]: '%2'
} }
} }
}).then(users => { }).then(users => {
...@@ -118,7 +119,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -118,7 +119,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
username: { username: {
nlike: '%2' [Op.notLike]: '%2'
} }
} }
}).then(users => { }).then(users => {
...@@ -134,7 +135,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -134,7 +135,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
username: { username: {
ilike: '%2' [Op.iLike]: '%2'
} }
} }
}).then(users => { }).then(users => {
...@@ -149,7 +150,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -149,7 +150,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
username: { username: {
notilike: '%2' [Op.notILike]: '%2'
} }
} }
}).then(users => { }).then(users => {
...@@ -165,7 +166,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -165,7 +166,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
'..': ['2013-01-02', '2013-01-11'] [Op.between]: ['2013-01-02', '2013-01-11']
} }
} }
}).then(users => { }).then(users => {
...@@ -178,7 +179,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -178,7 +179,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
intVal: { intVal: {
'!..': [8, 10] [Op.notBetween]: [8, 10]
} }
} }
}).then(users => { }).then(users => {
...@@ -303,7 +304,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -303,7 +304,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
between: ['2013-01-02', '2013-01-11'] [Op.between]: ['2013-01-02', '2013-01-11']
} }
} }
}).then(users => { }).then(users => {
...@@ -316,7 +317,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -316,7 +317,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
between: ['2013-01-02', '2013-01-11'] [Op.between]: ['2013-01-02', '2013-01-11']
}, },
intVal: 10 intVal: 10
} }
...@@ -330,7 +331,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -330,7 +331,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
intVal: { intVal: {
nbetween: [8, 10] [Op.notBetween]: [8, 10]
} }
} }
}).then(users => { }).then(users => {
...@@ -343,8 +344,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -343,8 +344,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
between: ['2012-12-10', '2013-01-02'], [Op.between]: ['2012-12-10', '2013-01-02'],
nbetween: ['2013-01-04', '2013-01-20'] [Op.notBetween]: ['2013-01-04', '2013-01-20']
} }
} }
}).then(users => { }).then(users => {
...@@ -357,8 +358,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -357,8 +358,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
between: [new Date('2012-12-10'), new Date('2013-01-02')], [Op.between]: [new Date('2012-12-10'), new Date('2013-01-02')],
nbetween: [new Date('2013-01-04'), new Date('2013-01-20')] [Op.notBetween]: [new Date('2013-01-04'), new Date('2013-01-20')]
} }
} }
}).then(users => { }).then(users => {
...@@ -371,7 +372,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -371,7 +372,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
theDate: { theDate: {
gte: new Date('2013-01-09') [Op.gte]: new Date('2013-01-09')
} }
} }
}).then(users => { }).then(users => {
...@@ -384,7 +385,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -384,7 +385,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({ return this.User.find({
where: { where: {
intVal: { intVal: {
gte: 6 [Op.gte]: 6
} }
} }
}).then(user => { }).then(user => {
...@@ -397,7 +398,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -397,7 +398,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({ return this.User.find({
where: { where: {
intVal: { intVal: {
gt: 5 [Op.gt]: 5
} }
} }
}).then(user => { }).then(user => {
...@@ -410,7 +411,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -410,7 +411,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({ return this.User.find({
where: { where: {
intVal: { intVal: {
lte: 5 [Op.lte]: 5
} }
} }
}).then(user => { }).then(user => {
...@@ -423,7 +424,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -423,7 +424,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({ return this.User.find({
where: { where: {
intVal: { intVal: {
lt: 6 [Op.lt]: 6
} }
} }
}).then(user => { }).then(user => {
...@@ -436,8 +437,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -436,8 +437,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
intVal: { intVal: {
lt: 6, [Op.lt]: 6,
gt: 4 [Op.gt]: 4
} }
} }
}).then(users => { }).then(users => {
...@@ -450,7 +451,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -450,7 +451,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({ return this.User.find({
where: { where: {
intVal: { intVal: {
ne: 10 [Op.ne]: 10
} }
} }
}).then(user => { }).then(user => {
...@@ -463,7 +464,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -463,7 +464,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({ return this.User.findAll({
where: { where: {
intVal: { intVal: {
lte: 10 [Op.lte]: 10
} }
} }
}).then(users => { }).then(users => {
...@@ -1033,7 +1034,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1033,7 +1034,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({ return this.Kingdom.findAll({
include: [{ include: [{
model: this.Animal, model: this.Animal,
where: { age: { $gte: 29 } }, where: { age: { [Op.gte]: 29 } },
attributes: [] attributes: []
}] }]
}).then(kingdoms => { }).then(kingdoms => {
...@@ -1049,7 +1050,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1049,7 +1050,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({ return this.Kingdom.findAll({
include: [{ include: [{
model: this.Animal, model: this.Animal,
where: { age: { $gte: 29 } }, where: { age: { [Op.gte]: 29 } },
through: { through: {
attributes: [] attributes: []
} }
...@@ -1067,7 +1068,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1067,7 +1068,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({ return this.Kingdom.findAll({
include: [{ include: [{
model: this.Animal, model: this.Animal,
where: { age: { $gte: 29 } }, where: { age: { [Op.gte]: 29 } },
attributes: [], attributes: [],
through: { through: {
attributes: ['mutation'] attributes: ['mutation']
...@@ -1494,7 +1495,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1494,7 +1495,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
it('handles where clause {only}', function() { it('handles where clause {only}', function() {
return this.User.findAndCountAll({where: {id: {$ne: this.users[0].id}}}).then(info => { return this.User.findAndCountAll({where: {id: {[Op.ne]: this.users[0].id}}}).then(info => {
expect(info.count).to.equal(2); expect(info.count).to.equal(2);
expect(Array.isArray(info.rows)).to.be.ok; expect(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2); expect(info.rows.length).to.equal(2);
...@@ -1502,7 +1503,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1502,7 +1503,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('handles where clause with ordering {only}', function() { it('handles where clause with ordering {only}', function() {
return this.User.findAndCountAll({where: {id: {$ne: this.users[0].id}}, order: [['id', 'ASC']]}).then(info => { return this.User.findAndCountAll({where: {id: {[Op.ne]: this.users[0].id}}, order: [['id', 'ASC']]}).then(info => {
expect(info.count).to.equal(2); expect(info.count).to.equal(2);
expect(Array.isArray(info.rows)).to.be.ok; expect(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2); expect(info.rows.length).to.equal(2);
...@@ -1580,7 +1581,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1580,7 +1581,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('handles attributes', function() { it('handles attributes', function() {
return this.User.findAndCountAll({where: {id: {$ne: this.users[0].id}}, attributes: ['data']}).then(info => { return this.User.findAndCountAll({where: {id: {[Op.ne]: this.users[0].id}}, attributes: ['data']}).then(info => {
expect(info.count).to.equal(2); expect(info.count).to.equal(2);
expect(Array.isArray(info.rows)).to.be.ok; expect(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2); expect(info.rows.length).to.equal(2);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
moment = require('moment'), moment = require('moment'),
expect = chai.expect, expect = chai.expect,
...@@ -281,7 +282,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -281,7 +282,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
json: { json: {
lastLogin: {$between: [before, after]} lastLogin: {[Op.between]: [before, after]}
} }
} }
}).then(events => { }).then(events => {
...@@ -324,7 +325,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -324,7 +325,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
json: { json: {
active: {$in: [true, false]} active: {[Op.in]: [true, false]}
} }
} }
}).then(events => { }).then(events => {
...@@ -364,7 +365,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -364,7 +365,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
where: { where: {
data: { data: {
age: { age: {
$gt: 38 [Op.gt]: 38
} }
} }
} }
...@@ -515,7 +516,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -515,7 +516,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
last: 'Simpson' last: 'Simpson'
}, },
employment: { employment: {
$ne: 'None' [Op.ne]: 'None'
} }
} }
}, },
......
...@@ -5,7 +5,9 @@ const chai = require('chai'), ...@@ -5,7 +5,9 @@ const chai = require('chai'),
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
current = Support.sequelize, current = Support.sequelize,
Op = current.Op,
Promise = current.Promise; Promise = current.Promise;
const SCHEMA_ONE = 'schema_one'; const SCHEMA_ONE = 'schema_one';
const SCHEMA_TWO = 'schema_two'; const SCHEMA_TWO = 'schema_two';
...@@ -101,7 +103,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -101,7 +103,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
}); });
describe('Get associated data in public schema via include', () => { describe('Get associated data in public schema via include', () => {
beforeEach(function() { beforeEach(function() {
return Promise.all([ return Promise.all([
...@@ -290,7 +292,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -290,7 +292,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(restaurant.bar).to.contain('one'); expect(restaurant.bar).to.contain('one');
}); });
return self.RestaurantOne.findAll({ return self.RestaurantOne.findAll({
where: {bar: {$like: '%.1'}} where: {bar: {[Op.like]: '%.1'}}
}); });
}).then(restaurantsOne => { }).then(restaurantsOne => {
expect(restaurantsOne).to.not.be.null; expect(restaurantsOne).to.not.be.null;
...@@ -318,7 +320,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -318,7 +320,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(restaurant.bar).to.contain('two'); expect(restaurant.bar).to.contain('two');
}); });
return self.RestaurantTwo.findAll({ return self.RestaurantTwo.findAll({
where: {bar: {$like: '%.3'}} where: {bar: {[Op.like]: '%.3'}}
}); });
}).then(restaurantsTwo => { }).then(restaurantsTwo => {
expect(restaurantsTwo).to.not.be.null; expect(restaurantsTwo).to.not.be.null;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'); Support = require(__dirname + '/../support');
...@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
attributes: ['other_value', 'access_level'], attributes: ['other_value', 'access_level'],
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
}, },
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
Promise = require(__dirname + '/../../../../lib/promise'); Promise = require(__dirname + '/../../../../lib/promise');
...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
} }
}, },
...@@ -30,7 +31,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -30,7 +31,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: { lowAccess: {
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
}, },
...@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to override default scope', function() { it('should be able to override default scope', function() {
return expect(this.ScopeMe.aggregate( '*', 'count', { where: { access_level: { gt: 5 }}})).to.eventually.equal(1); return expect(this.ScopeMe.aggregate( '*', 'count', { where: { access_level: { [Op.gt]: 5 }}})).to.eventually.equal(1);
}); });
it('should be able to unscope', function() { it('should be able to unscope', function() {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
} }
}, },
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Promise = require(__dirname + '/../../../../lib/promise'), Promise = require(__dirname + '/../../../../lib/promise'),
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
}, },
attributes: ['id', 'username', 'email', 'access_level'] attributes: ['id', 'username', 'email', 'access_level']
...@@ -31,7 +32,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -31,7 +32,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: { lowAccess: {
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
}, },
...@@ -98,7 +99,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -98,7 +99,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to override default scope', function() { it('should be able to override default scope', function() {
return expect(this.ScopeMe.count({ where: { access_level: { gt: 5 }}})).to.eventually.equal(1); return expect(this.ScopeMe.count({ where: { access_level: { [Op.gt]: 5 }}})).to.eventually.equal(1);
}); });
it('should be able to unscope', function() { it('should be able to unscope', function() {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
...@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
} }
}, },
...@@ -26,7 +27,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -26,7 +27,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: { lowAccess: {
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
} }
...@@ -55,7 +56,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -55,7 +56,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to override default scope', function() { it('should be able to override default scope', function() {
return this.ScopeMe.destroy({ where: { access_level: { lt: 5 }}}).bind(this).then(function() { return this.ScopeMe.destroy({ where: { access_level: { [Op.lt]: 5 }}}).bind(this).then(function() {
return this.ScopeMe.unscoped().findAll(); return this.ScopeMe.unscoped().findAll();
}).then(users => { }).then(users => {
expect(users).to.have.length(2); expect(users).to.have.length(2);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
expect = chai.expect, expect = chai.expect,
Op = Sequelize.Op,
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
...@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
} }
}, },
...@@ -26,16 +27,16 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -26,16 +27,16 @@ describe(Support.getTestDialectTeaser('Model'), () => {
highValue: { highValue: {
where: { where: {
other_value: { other_value: {
gte: 10 [Op.gte]: 10
} }
} }
}, },
andScope: { andScope: {
where: { where: {
$and: [ [Op.and]: [
{ {
email: { email: {
like: '%@sequelizejs.com' [Op.like]: '%@sequelizejs.com'
} }
}, },
{ access_level: 3 } { access_level: 3 }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
...@@ -20,7 +21,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -20,7 +21,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
}, },
attributes: ['username', 'email', 'access_level'] attributes: ['username', 'email', 'access_level']
...@@ -29,7 +30,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -29,7 +30,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: { lowAccess: {
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
}, },
...@@ -58,7 +59,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -58,7 +59,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to override default scope', function() { it('should be able to override default scope', function() {
return this.ScopeMe.findAndCount({ where: { access_level: { gt: 5 }}}) return this.ScopeMe.findAndCount({ where: { access_level: { [Op.gt]: 5 }}})
.then(result => { .then(result => {
expect(result.count).to.equal(1); expect(result.count).to.equal(1);
expect(result.rows.length).to.equal(1); expect(result.rows.length).to.equal(1);
......
...@@ -4,6 +4,7 @@ const chai = require('chai'), ...@@ -4,6 +4,7 @@ const chai = require('chai'),
_ = require('lodash'), _ = require('lodash'),
Sequelize = require('../../../../index'), Sequelize = require('../../../../index'),
expect = chai.expect, expect = chai.expect,
Op = Sequelize.Op,
Support = require(__dirname + '/../../support'); Support = require(__dirname + '/../../support');
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
...@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: { defaultScope: {
where: { where: {
access_level: { access_level: {
gte: 5 [Op.gte]: 5
} }
} }
}, },
...@@ -27,7 +28,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -27,7 +28,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: { lowAccess: {
where: { where: {
access_level: { access_level: {
lte: 5 [Op.lte]: 5
} }
} }
} }
...@@ -56,7 +57,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -56,7 +57,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be able to override default scope', function() { it('should be able to override default scope', function() {
return this.ScopeMe.update({ username: 'ruben' }, { where: { access_level: { lt: 5 }}}).bind(this).then(function() { return this.ScopeMe.update({ username: 'ruben' }, { where: { access_level: { [Op.lt]: 5 }}}).bind(this).then(function() {
return this.ScopeMe.unscoped().findAll({ where: { username: 'ruben' }}); return this.ScopeMe.unscoped().findAll({ where: { username: 'ruben' }});
}).then(users => { }).then(users => {
expect(users).to.have.length(2); expect(users).to.have.length(2);
...@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should be able to apply other scopes', function() { it('should be able to apply other scopes', function() {
return this.ScopeMe.scope('lowAccess').update({ username: 'ruben' }, { where: {}}).bind(this).then(function() { return this.ScopeMe.scope('lowAccess').update({ username: 'ruben' }, { where: {}}).bind(this).then(function() {
return this.ScopeMe.unscoped().findAll({ where: { username: { $ne: 'ruben' }}}); return this.ScopeMe.unscoped().findAll({ where: { username: { [Op.ne]: 'ruben' }}});
}).then(users => { }).then(users => {
expect(users).to.have.length(1); expect(users).to.have.length(1);
expect(users[0].get('email')).to.equal('tobi@fakeemail.com'); expect(users[0].get('email')).to.equal('tobi@fakeemail.com');
......
...@@ -4,6 +4,7 @@ const chai = require('chai'); ...@@ -4,6 +4,7 @@ const chai = require('chai');
const expect = chai.expect; const expect = chai.expect;
const Support = require(__dirname + '/../support'); const Support = require(__dirname + '/../support');
const DataTypes = require(__dirname + '/../../../lib/data-types'); const DataTypes = require(__dirname + '/../../../lib/data-types');
const Op = Support.Sequelize.Op;
const SEARCH_PATH_ONE = 'schema_one,public'; const SEARCH_PATH_ONE = 'schema_one,public';
const SEARCH_PATH_TWO = 'schema_two,public'; const SEARCH_PATH_TWO = 'schema_two,public';
...@@ -225,7 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -225,7 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return restaurauntModel.save({searchPath: SEARCH_PATH_TWO}); return restaurauntModel.save({searchPath: SEARCH_PATH_TWO});
}).then(() => { }).then(() => {
return Restaurant.findAll({ return Restaurant.findAll({
where: {bar: {$like: 'one%'}}, where: {bar: {[Op.like]: 'one%'}},
searchPath: SEARCH_PATH_ONE searchPath: SEARCH_PATH_ONE
}); });
}).then(restaurantsOne => { }).then(restaurantsOne => {
...@@ -239,7 +240,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -239,7 +240,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(count).to.not.be.null; expect(count).to.not.be.null;
expect(count).to.equal(2); expect(count).to.equal(2);
return Restaurant.findAll({ return Restaurant.findAll({
where: {bar: {$like: 'two%'}}, where: {bar: {[Op.like]: 'two%'}},
searchPath: SEARCH_PATH_TWO searchPath: SEARCH_PATH_TWO
}); });
}).then(restaurantsTwo => { }).then(restaurantsTwo => {
......
...@@ -60,17 +60,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -60,17 +60,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
expect(sequelize.config.host).to.equal('127.0.0.1'); expect(sequelize.config.host).to.equal('127.0.0.1');
}); });
it('should log deprecated warning if operators aliases were not set', () => {
sinon.stub(Utils, 'deprecate');
Support.createSequelizeInstance();
expect(Utils.deprecate.calledOnce).to.be.true;
expect(Utils.deprecate.args[0][0]).to.be.equal('String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators');
Utils.deprecate.reset();
Support.createSequelizeInstance({ operatorsAliases: {} });
expect(Utils.deprecate.called).to.be.false;
});
it('should set operators aliases on dialect QueryGenerator', () => { it('should set operators aliases on dialect QueryGenerator', () => {
const operatorsAliases = { fake: true }; const operatorsAliases = { fake: true };
const sequelize = Support.createSequelizeInstance({ operatorsAliases }); const sequelize = Support.createSequelizeInstance({ operatorsAliases });
......
...@@ -5,7 +5,8 @@ const chai = require('chai'), ...@@ -5,7 +5,8 @@ const chai = require('chai'),
Utils = require(__dirname + '/../../lib/utils'), Utils = require(__dirname + '/../../lib/utils'),
Support = require(__dirname + '/support'), Support = require(__dirname + '/support'),
DataTypes = require(__dirname + '/../../lib/data-types'), DataTypes = require(__dirname + '/../../lib/data-types'),
Sequelize = require('../../index'); Sequelize = require('../../index'),
Op = Sequelize.Op;
describe(Support.getTestDialectTeaser('Utils'), () => { describe(Support.getTestDialectTeaser('Utils'), () => {
describe('removeCommentsFromFunctionString', () => { describe('removeCommentsFromFunctionString', () => {
...@@ -265,9 +266,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => { ...@@ -265,9 +266,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => {
engines: 1 engines: 1
}, type)), 'count-engines'], }, type)), 'count-engines'],
[Sequelize.fn('SUM', Sequelize.cast({ [Sequelize.fn('SUM', Sequelize.cast({
$or: { [Op.or]: {
engines: { engines: {
$gt: 1 [Op.gt]: 1
}, },
wings: 4 wings: 4
} }
...@@ -290,9 +291,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => { ...@@ -290,9 +291,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => {
engines: 1 engines: 1
}), 'count-engines'], }), 'count-engines'],
[Sequelize.fn('SUM', { [Sequelize.fn('SUM', {
$or: { [Op.or]: {
engines: { engines: {
$gt: 1 [Op.gt]: 1
}, },
wings: 4 wings: 4
} }
......
...@@ -19,7 +19,7 @@ describe('QueryGenerator', () => { ...@@ -19,7 +19,7 @@ describe('QueryGenerator', () => {
.should.be.equal('(test IS NULL OR testSame IS NULL)'); .should.be.equal('(test IS NULL OR testSame IS NULL)');
}); });
it('should not parse any strings as aliases operators', function() { it('should not parse any strings as aliases operators', function() {
const QG = getAbstractQueryGenerator(this.sequelize); const QG = getAbstractQueryGenerator(this.sequelize);
expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}])) expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}]))
.to.throw('Invalid value { test: 5 }'); .to.throw('Invalid value { test: 5 }');
...@@ -86,7 +86,6 @@ describe('QueryGenerator', () => { ...@@ -86,7 +86,6 @@ describe('QueryGenerator', () => {
expect(() => QG.whereItemQuery('test', {$in: [4]})) expect(() => QG.whereItemQuery('test', {$in: [4]}))
.to.throw('Invalid value { \'$in\': [ 4 ] }'); .to.throw('Invalid value { \'$in\': [ 4 ] }');
}); });
}); });
}); });
...@@ -5,7 +5,7 @@ const chai = require('chai'), ...@@ -5,7 +5,7 @@ const chai = require('chai'),
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
_ = require('lodash'), _ = require('lodash'),
Operators = require('../../../../lib/operators'), Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/mysql/query-generator'); QueryGenerator = require('../../../../lib/dialects/mysql/query-generator');
if (dialect === 'mysql') { if (dialect === 'mysql') {
...@@ -320,7 +320,7 @@ if (dialect === 'mysql') { ...@@ -320,7 +320,7 @@ if (dialect === 'mysql') {
return { return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']], attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
group: ['creationYear', 'title'], group: ['creationYear', 'title'],
having: { creationYear: { gt: 2002 } } having: { creationYear: { [Op.gt]: 2002 } }
}; };
}], }],
expectation: 'SELECT *, YEAR(`createdAt`) AS `creationYear` FROM `myTable` GROUP BY `creationYear`, `title` HAVING `creationYear` > 2002;', expectation: 'SELECT *, YEAR(`createdAt`) AS `creationYear` FROM `myTable` GROUP BY `creationYear`, `title` HAVING `creationYear` > 2002;',
...@@ -332,7 +332,7 @@ if (dialect === 'mysql') { ...@@ -332,7 +332,7 @@ if (dialect === 'mysql') {
return { return {
where: sequelize.and( where: sequelize.and(
{ archived: null}, { archived: null},
sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { in: ['Lost', 'Found'] }) sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { [Op.in]: ['Lost', 'Found'] })
) )
}; };
}], }],
...@@ -389,32 +389,32 @@ if (dialect === 'mysql') { ...@@ -389,32 +389,32 @@ if (dialect === 'mysql') {
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use != if ne !== null', title: 'use != if ne !== null',
arguments: ['myTable', {where: {field: {ne: 0}}}], arguments: ['myTable', {where: {field: {[Op.ne]: 0}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 0;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 0;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use IS NOT if ne === null', title: 'use IS NOT if ne === null',
arguments: ['myTable', {where: {field: {ne: null}}}], arguments: ['myTable', {where: {field: {[Op.ne]: null}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use IS NOT if not === BOOLEAN', title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}], arguments: ['myTable', {where: {field: {[Op.not]: true}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT true;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT true;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use != if not !== BOOLEAN', title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}], arguments: ['myTable', {where: {field: {[Op.not]: 3}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'Regular Expression in where clause', title: 'Regular Expression in where clause',
arguments: ['myTable', {where: {field: {$regexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.regexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` REGEXP '^[h|a|t]';", expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` REGEXP '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'Regular Expression negation in where clause', title: 'Regular Expression negation in where clause',
arguments: ['myTable', {where: {field: {$notRegexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.notRegexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` NOT REGEXP '^[h|a|t]';", expectation: "SELECT * FROM `myTable` WHERE `myTable`.`field` NOT REGEXP '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, { }, {
...@@ -433,7 +433,7 @@ if (dialect === 'mysql') { ...@@ -433,7 +433,7 @@ if (dialect === 'mysql') {
return { return {
subQuery: true, subQuery: true,
tableAs: 'test', tableAs: 'test',
having: { creationYear: { [Operators.gt]: 2002 } } having: { creationYear: { [Op.gt]: 2002 } }
}; };
}], }],
expectation: 'SELECT `test`.* FROM (SELECT * FROM `myTable` AS `test` HAVING `creationYear` > 2002) AS `test`;', expectation: 'SELECT `test`.* FROM (SELECT * FROM `myTable` AS `test` HAVING `creationYear` > 2002) AS `test`;',
...@@ -625,7 +625,6 @@ if (dialect === 'mysql') { ...@@ -625,7 +625,6 @@ if (dialect === 'mysql') {
// Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly // Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly
this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {}); this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {});
this.queryGenerator.setOperatorsAliases(Operators.LegacyAliases);
const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments); const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments);
expect(conditions).to.deep.equal(test.expectation); expect(conditions).to.deep.equal(test.expectation);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
const chai = require('chai'), const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Operators = require('../../../../lib/operators'), Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/postgres/query-generator'), QueryGenerator = require('../../../../lib/dialects/postgres/query-generator'),
Support = require(__dirname + '/../../support'), Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
...@@ -356,12 +356,12 @@ if (dialect.match(/^postgres/)) { ...@@ -356,12 +356,12 @@ if (dialect.match(/^postgres/)) {
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
}, { }, {
title: 'Combination of sequelize.fn, sequelize.col and { in: ... }', title: 'Combination of sequelize.fn, sequelize.col and { Op.in: ... }',
arguments: ['myTable', function(sequelize) { arguments: ['myTable', function(sequelize) {
return { return {
where: sequelize.and( where: sequelize.and(
{ archived: null}, { archived: null},
sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { in: ['Lost', 'Found'] }) sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { [Op.in]: ['Lost', 'Found'] })
) )
}; };
}], }],
...@@ -403,7 +403,7 @@ if (dialect.match(/^postgres/)) { ...@@ -403,7 +403,7 @@ if (dialect.match(/^postgres/)) {
return { return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']], attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
group: ['creationYear', 'title'], group: ['creationYear', 'title'],
having: { creationYear: { gt: 2002 } } having: { creationYear: { [Op.gt]: 2002 } }
}; };
}], }],
expectation: 'SELECT *, YEAR(\"createdAt\") AS \"creationYear\" FROM \"myTable\" GROUP BY \"creationYear\", \"title\" HAVING \"creationYear\" > 2002;', expectation: 'SELECT *, YEAR(\"createdAt\") AS \"creationYear\" FROM \"myTable\" GROUP BY \"creationYear\", \"title\" HAVING \"creationYear\" > 2002;',
...@@ -432,7 +432,7 @@ if (dialect.match(/^postgres/)) { ...@@ -432,7 +432,7 @@ if (dialect.match(/^postgres/)) {
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'string in array should escape \' as \'\'', title: 'string in array should escape \' as \'\'',
arguments: ['myTable', {where: { aliases: {$contains: ['Queen\'s']} }}], arguments: ['myTable', {where: { aliases: {[Op.contains]: ['Queen\'s']} }}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"aliases\" @> ARRAY['Queen''s'];" expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"aliases\" @> ARRAY['Queen''s'];"
}, },
...@@ -503,43 +503,43 @@ if (dialect.match(/^postgres/)) { ...@@ -503,43 +503,43 @@ if (dialect.match(/^postgres/)) {
expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name = 'foo'';DROP TABLE mySchema.myTable;';", expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name = 'foo'';DROP TABLE mySchema.myTable;';",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
title: 'use != if ne !== null', title: 'use != if Op.ne !== null',
arguments: ['myTable', {where: {field: {ne: 0}}}], arguments: ['myTable', {where: {field: {[Op.ne]: 0}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 0;', expectation: 'SELECT * FROM myTable WHERE myTable.field != 0;',
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
title: 'use IS NOT if ne === null', title: 'use IS NOT if Op.ne === null',
arguments: ['myTable', {where: {field: {ne: null}}}], arguments: ['myTable', {where: {field: {[Op.ne]: null}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;', expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;',
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
title: 'use IS NOT if not === BOOLEAN', title: 'use IS NOT if Op.not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}], arguments: ['myTable', {where: {field: {[Op.not]: true}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;', expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;',
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
title: 'use != if not !== BOOLEAN', title: 'use != if Op.not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}], arguments: ['myTable', {where: {field: {[Op.not]: 3}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;', expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;',
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
title: 'Regular Expression in where clause', title: 'Regular Expression in where clause',
arguments: ['myTable', {where: {field: {$regexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.regexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" ~ '^[h|a|t]';", expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" ~ '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'Regular Expression negation in where clause', title: 'Regular Expression negation in where clause',
arguments: ['myTable', {where: {field: {$notRegexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.notRegexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" !~ '^[h|a|t]';", expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" !~ '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'Case-insensitive Regular Expression in where clause', title: 'Case-insensitive Regular Expression in where clause',
arguments: ['myTable', {where: {field: {$iRegexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.iRegexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" ~* '^[h|a|t]';", expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" ~* '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'Case-insensitive Regular Expression negation in where clause', title: 'Case-insensitive Regular Expression negation in where clause',
arguments: ['myTable', {where: {field: {$notIRegexp: '^[h|a|t]'}}}], arguments: ['myTable', {where: {field: {[Op.notIRegexp]: '^[h|a|t]'}}}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" !~* '^[h|a|t]';", expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" !~* '^[h|a|t]';",
context: QueryGenerator context: QueryGenerator
} }
...@@ -1001,7 +1001,6 @@ if (dialect.match(/^postgres/)) { ...@@ -1001,7 +1001,6 @@ if (dialect.match(/^postgres/)) {
// Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly // Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly
this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {}); this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {});
this.queryGenerator.setOperatorsAliases(Operators.LegacyAliases);
const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments); const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments);
expect(conditions).to.deep.equal(test.expectation); expect(conditions).to.deep.equal(test.expectation);
......
...@@ -7,7 +7,7 @@ const chai = require('chai'), ...@@ -7,7 +7,7 @@ const chai = require('chai'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
_ = require('lodash'), _ = require('lodash'),
moment = require('moment'), moment = require('moment'),
Operators = require('../../../../lib/operators'), Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/sqlite/query-generator'); QueryGenerator = require('../../../../lib/dialects/sqlite/query-generator');
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
...@@ -294,7 +294,7 @@ if (dialect === 'sqlite') { ...@@ -294,7 +294,7 @@ if (dialect === 'sqlite') {
return { return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']], attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
group: ['creationYear', 'title'], group: ['creationYear', 'title'],
having: { creationYear: { gt: 2002 } } having: { creationYear: { [Op.gt]: 2002 } }
}; };
}], }],
expectation: 'SELECT *, YEAR(`createdAt`) AS `creationYear` FROM `myTable` GROUP BY `creationYear`, `title` HAVING `creationYear` > 2002;', expectation: 'SELECT *, YEAR(`createdAt`) AS `creationYear` FROM `myTable` GROUP BY `creationYear`, `title` HAVING `creationYear` > 2002;',
...@@ -340,22 +340,22 @@ if (dialect === 'sqlite') { ...@@ -340,22 +340,22 @@ if (dialect === 'sqlite') {
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use != if ne !== null', title: 'use != if ne !== null',
arguments: ['myTable', {where: {field: {ne: 0}}}], arguments: ['myTable', {where: {field: {[Op.ne]: 0}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 0;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 0;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use IS NOT if ne === null', title: 'use IS NOT if ne === null',
arguments: ['myTable', {where: {field: {ne: null}}}], arguments: ['myTable', {where: {field: {[Op.ne]: null}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT NULL;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use IS NOT if not === BOOLEAN', title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}], arguments: ['myTable', {where: {field: {[Op.not]: true}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT 1;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` IS NOT 1;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'use != if not !== BOOLEAN', title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}], arguments: ['myTable', {where: {field: {[Op.not]: 3}}}],
expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;', expectation: 'SELECT * FROM `myTable` WHERE `myTable`.`field` != 3;',
context: QueryGenerator context: QueryGenerator
} }
...@@ -556,7 +556,6 @@ if (dialect === 'sqlite') { ...@@ -556,7 +556,6 @@ if (dialect === 'sqlite') {
// Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly // Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly
this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {}); this.queryGenerator.options = Object.assign({}, this.queryGenerator.options, test.context && test.context.options || {});
this.queryGenerator.setOperatorsAliases(Operators.LegacyAliases);
const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments); const conditions = this.queryGenerator[suiteTitle].apply(this.queryGenerator, test.arguments);
expect(conditions).to.deep.equal(test.expectation); expect(conditions).to.deep.equal(test.expectation);
......
...@@ -4,6 +4,7 @@ const chai = require('chai'), ...@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
current = Support.sequelize, current = Support.sequelize,
Op = current.Op,
sinon = require('sinon'), sinon = require('sinon'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
Promise = require('bluebird'); Promise = require('bluebird');
...@@ -62,7 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -62,7 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should add limit when using { $ gt on the primary key', function() { it('should add limit when using { $ gt on the primary key', function() {
const Model = current.define('model'); const Model = current.define('model');
return Model.findOne({ where: { id: { $gt: 42 }}}).bind(this).then(function() { return Model.findOne({ where: { id: { [Op.gt]: 42 }}}).bind(this).then(function() {
expect(this.stub.getCall(0).args[0]).to.be.an('object').to.have.property('limit'); expect(this.stub.getCall(0).args[0]).to.be.an('object').to.have.property('limit');
}); });
}); });
......
...@@ -6,6 +6,7 @@ const chai = require('chai'), ...@@ -6,6 +6,7 @@ const chai = require('chai'),
Sequelize = require(__dirname + '/../../../index'), Sequelize = require(__dirname + '/../../../index'),
Support = require(__dirname + '/../support'), Support = require(__dirname + '/../support'),
current = Support.sequelize, current = Support.sequelize,
Op = current.Op,
Promise = current.Promise, Promise = current.Promise,
config = require(__dirname + '/../../config/config'); config = require(__dirname + '/../../config/config');
...@@ -355,8 +356,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -355,8 +356,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return expect(User.all({ return expect(User.all({
where: { where: {
name: { name: {
$like: { [Op.like]: {
$any: ['foo%', 'bar%'] [Op.any]: ['foo%', 'bar%']
} }
} }
} }
...@@ -367,7 +368,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -367,7 +368,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return expect(User.all({ return expect(User.all({
where: { where: {
uid: { uid: {
$like: '12345678%' [Op.like]: '12345678%'
} }
} }
})).not.to.be.rejected; })).not.to.be.rejected;
......
...@@ -4,6 +4,7 @@ const Support = require(__dirname + '/../support'); ...@@ -4,6 +4,7 @@ const Support = require(__dirname + '/../support');
const current = Support.sequelize; const current = Support.sequelize;
const expectsql = Support.expectsql; const expectsql = Support.expectsql;
const sql = current.dialect.QueryGenerator; const sql = current.dialect.QueryGenerator;
const Op = current.Op;
const expect = require('chai').expect; const expect = require('chai').expect;
const sinon = require('sinon'); const sinon = require('sinon');
...@@ -61,9 +62,9 @@ if (current.dialect.supports.constraints.addConstraint) { ...@@ -61,9 +62,9 @@ if (current.dialect.supports.constraints.addConstraint) {
name: 'check_mycolumn_where', name: 'check_mycolumn_where',
where: { where: {
myColumn: { myColumn: {
$and: { [Op.and]: {
$gt: 50, [Op.gt]: 50,
$lt: 100 [Op.lt]: 100
} }
} }
} }
......
'use strict'; 'use strict';
const Support = require(__dirname + '/../support'), const Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'), DataTypes = require(__dirname + '/../../../lib/data-types'),
Sequelize = require(__dirname + '/../../../lib/sequelize'), Sequelize = require(__dirname + '/../../../lib/sequelize'),
util = require('util'), util = require('util'),
_ = require('lodash'), _ = require('lodash'),
expectsql = Support.expectsql, expectsql = Support.expectsql,
current = Support.sequelize, current = Support.sequelize,
sql = current.dialect.QueryGenerator; sql = current.dialect.QueryGenerator,
Op = current.Op;
// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation // Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation
...@@ -279,8 +280,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -279,8 +280,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
include: [ include: [
{ {
association: User.Tasks, on: { association: User.Tasks, on: {
$or: [ [Op.or]: [
{ '$User.id_user$': { $col: 'Tasks.user_id' } }, { '$User.id_user$': { [Op.col]: 'Tasks.user_id' } },
{ '$Tasks.user_id$': 2 } { '$Tasks.user_id$': 2 }
] ]
} }
...@@ -296,7 +297,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -296,7 +297,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
include: [ include: [
{ {
association: User.Tasks, association: User.Tasks,
on: { 'user_id': { $col: 'User.alternative_id' } } on: { 'user_id': { [Op.col]: 'User.alternative_id' } }
} }
] ]
}, { default: 'LEFT OUTER JOIN [task] AS [Tasks] ON [Tasks].[user_id] = [User].[alternative_id]' } }, { default: 'LEFT OUTER JOIN [task] AS [Tasks] ON [Tasks].[user_id] = [User].[alternative_id]' }
...@@ -314,8 +315,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -314,8 +315,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
{ {
association: Company.Owner, association: Company.Owner,
on: { on: {
$or: [ [Op.or]: [
{ '$Company.owner_id$': { $col: 'Company.Owner.id_user'} }, { '$Company.owner_id$': { [Op.col]: 'Company.Owner.id_user'} },
{ '$Company.Owner.id_user$': 2 } { '$Company.Owner.id_user$': 2 }
] ]
} }
......
...@@ -5,6 +5,7 @@ const current = Support.sequelize; ...@@ -5,6 +5,7 @@ const current = Support.sequelize;
const expectsql = Support.expectsql; const expectsql = Support.expectsql;
const sql = current.dialect.QueryGenerator; const sql = current.dialect.QueryGenerator;
const expect = require('chai').expect; const expect = require('chai').expect;
const Op = current.Op;
describe(Support.getTestDialectTeaser('SQL'), () => { describe(Support.getTestDialectTeaser('SQL'), () => {
describe('getConstraintSnippet', () => { describe('getConstraintSnippet', () => {
...@@ -61,9 +62,9 @@ describe(Support.getTestDialectTeaser('SQL'), () => { ...@@ -61,9 +62,9 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
name: 'check_mycolumn_where', name: 'check_mycolumn_where',
where: { where: {
myColumn: { myColumn: {
$and: { [Op.and]: {
$gt: 50, [Op.gt]: 50,
$lt: 100 [Op.lt]: 100
} }
} }
} }
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
const Support = require(__dirname + '/../support'), const Support = require(__dirname + '/../support'),
expectsql = Support.expectsql, expectsql = Support.expectsql,
current = Support.sequelize, current = Support.sequelize,
sql = current.dialect.QueryGenerator; sql = current.dialect.QueryGenerator,
Op = current.Op;
// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation // Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation
...@@ -103,7 +104,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -103,7 +104,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
fields: ['type'], fields: ['type'],
where: { where: {
type: { type: {
$or: [ [Op.or]: [
'group', 'group',
'private' 'private'
] ]
...@@ -119,7 +120,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -119,7 +120,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
fields: ['type'], fields: ['type'],
where: { where: {
type: { type: {
$ne: null [Op.ne]: null
} }
} }
}), { }), {
......
...@@ -8,7 +8,8 @@ const Support = require(__dirname + '/../support'), ...@@ -8,7 +8,8 @@ const Support = require(__dirname + '/../support'),
expect = chai.expect, expect = chai.expect,
expectsql = Support.expectsql, expectsql = Support.expectsql,
current = Support.sequelize, current = Support.sequelize,
sql = current.dialect.QueryGenerator; sql = current.dialect.QueryGenerator,
Op = current.Op;
// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation // Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation
...@@ -170,7 +171,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => { ...@@ -170,7 +171,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
], ],
where: { where: {
age: { age: {
$gte: 21 [Op.gte]: 21
} }
}, },
groupedLimit: { groupedLimit: {
......
...@@ -7,6 +7,7 @@ const DataTypes = require(__dirname + '/../../lib/data-types'); ...@@ -7,6 +7,7 @@ const DataTypes = require(__dirname + '/../../lib/data-types');
const Utils = require(__dirname + '/../../lib/utils'); const Utils = require(__dirname + '/../../lib/utils');
const tedious = require('tedious'); const tedious = require('tedious');
const tediousIsolationLevel = tedious.ISOLATION_LEVEL; const tediousIsolationLevel = tedious.ISOLATION_LEVEL;
const Op = Support.sequelize.Op;
suite(Support.getTestDialectTeaser('Utils'), () => { suite(Support.getTestDialectTeaser('Utils'), () => {
suite('merge', () => { suite('merge', () => {
...@@ -147,7 +148,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -147,7 +148,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$or where', () => { test('$or where', () => {
expect(Utils.mapOptionFieldNames({ expect(Utils.mapOptionFieldNames({
where: { where: {
$or: { [Op.or]: {
firstName: 'Paul', firstName: 'Paul',
lastName: 'Atreides' lastName: 'Atreides'
} }
...@@ -163,7 +164,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -163,7 +164,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
} }
}))).to.eql({ }))).to.eql({
where: { where: {
$or: { [Op.or]: {
first_name: 'Paul', first_name: 'Paul',
last_name: 'Atreides' last_name: 'Atreides'
} }
...@@ -174,7 +175,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -174,7 +175,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$or[] where', () => { test('$or[] where', () => {
expect(Utils.mapOptionFieldNames({ expect(Utils.mapOptionFieldNames({
where: { where: {
$or: [ [Op.or]: [
{firstName: 'Paul'}, {firstName: 'Paul'},
{lastName: 'Atreides'} {lastName: 'Atreides'}
] ]
...@@ -190,7 +191,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -190,7 +191,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
} }
}))).to.eql({ }))).to.eql({
where: { where: {
$or: [ [Op.or]: [
{first_name: 'Paul'}, {first_name: 'Paul'},
{last_name: 'Atreides'} {last_name: 'Atreides'}
] ]
...@@ -201,7 +202,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -201,7 +202,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$and where', () => { test('$and where', () => {
expect(Utils.mapOptionFieldNames({ expect(Utils.mapOptionFieldNames({
where: { where: {
$and: { [Op.and]: {
firstName: 'Paul', firstName: 'Paul',
lastName: 'Atreides' lastName: 'Atreides'
} }
...@@ -217,7 +218,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -217,7 +218,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
} }
}))).to.eql({ }))).to.eql({
where: { where: {
$and: { [Op.and]: {
first_name: 'Paul', first_name: 'Paul',
last_name: 'Atreides' last_name: 'Atreides'
} }
...@@ -258,7 +259,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => { ...@@ -258,7 +259,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('accepts condition object (auto casting)', () => { test('accepts condition object (auto casting)', () => {
expectsql(run(sql.fn('SUM', sql.cast({ expectsql(run(sql.fn('SUM', sql.cast({
$or: { [Op.or]: {
foo: 'foo', foo: 'foo',
bar: 'bar' bar: 'bar'
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!