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

Commit 4ba7beac by Sushant Committed by GitHub

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

1 parent 8e2517fb
Showing with 316 additions and 397 deletions
......@@ -25,9 +25,6 @@ With v5
- You can still use string operators by passing an operators map in `operatorsAliases`
- Op.$raw is removed
__DEV__: _Incomplete, deprecated_
### Model
**Attributes**
......@@ -38,7 +35,7 @@ __Note__: _Please dont confuse this with `options.attributes`, they are still va
**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)
......
......@@ -81,69 +81,4 @@ const Op = {
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;
\ No newline at end of file
......@@ -238,10 +238,9 @@ class Sequelize {
this.dialect = new Dialect(this);
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');
this.dialect.QueryGenerator.setOperatorsAliases(Op.LegacyAliases); //Op.LegacyAliases should be removed and replaced by Op.Aliases by v5.0 use
} else {
if (_.isPlainObject(this.options.operatorsAliases)) {
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');
this.dialect.QueryGenerator.setOperatorsAliases(this.options.operatorsAliases);
}
......@@ -331,9 +330,7 @@ class Sequelize {
*
* sequelize.models.modelName // The model will now be available in models under the name given to define
*/
define(modelName, attributes, options) {
options = options || {};
define(modelName, attributes, options = {}) {
options.modelName = modelName;
options.sequelize = this;
......@@ -366,8 +363,7 @@ class Sequelize {
* @return {Boolean}
*/
isDefined(modelName) {
const models = this.modelManager.models;
return models.filter(model => model.name === modelName).length !== 0;
return !!this.modelManager.models.find(model => model.name === modelName);
}
/**
......@@ -1046,21 +1042,6 @@ class Sequelize {
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() {
let options;
let args = Utils.sliceArgs(arguments);
......
......@@ -9,6 +9,7 @@ const chai = require('chai'),
sinon = require('sinon'),
Promise = Sequelize.Promise,
current = Support.sequelize,
Op = current.Op,
dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
......@@ -110,7 +111,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return john.getTasks({
where: {
title: {
not: ['Get rich']
[Op.not]: ['Get rich']
}
}
});
......@@ -130,7 +131,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return john.getTasks({
where: {
id: {
not: [self.tasks[0].get('id')]
[Op.not]: [self.tasks[0].get('id')]
}
}
});
......@@ -2039,7 +2040,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
model: self.Task,
where: {
title: {
$ne: 'task'
[Op.ne]: 'task'
}
}
}]
......
......@@ -10,6 +10,7 @@ const chai = require('chai'),
Promise = Sequelize.Promise,
current = Support.sequelize,
_ = require('lodash'),
Op = current.Op,
dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('HasMany'), () => {
......@@ -1036,7 +1037,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
this.article = article;
return article.setLabels([label1, label2]);
}).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 => {
expect(labels).to.be.instanceof(Array);
expect(labels).to.have.length(1);
......
......@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../../support'),
Sequelize = Support.Sequelize,
Op = Sequelize.Op,
Promise = Sequelize.Promise,
dialect = Support.getTestDialect(),
DataTypes = require(__dirname + '/../../../../lib/data-types'),
......@@ -504,10 +505,10 @@ if (dialect.match(/^postgres/)) {
return User.findAll({
where: {
type: {
$in: ['A', 'C']
[Op.in]: ['A', 'C']
},
permissions: {
$contains: ['write']
[Op.contains]: ['write']
}
}
});
......
......@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../../support'),
Sequelize = Support.Sequelize,
Op = Sequelize.Op,
dialect = Support.getTestDialect(),
DataTypes = require(__dirname + '/../../../../lib/data-types');
......@@ -39,7 +40,7 @@ if (dialect === 'sqlite') {
return user.save().then(() => {
return this.User.create({ username: 'new user' }).then(() => {
return this.User.findAll({
where: { createdAt: { $gt: new Date(2012, 1, 1) } }
where: { createdAt: { [Op.gt]: new Date(2012, 1, 1) } }
}).then(users => {
expect(users).to.have.length(1);
});
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
......@@ -1310,7 +1311,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{model: Tag, as: 'Category'},
{model: Price, where: {
value: {
gt: 15
[Op.gt]: 15
}
}}
]}
......@@ -1575,7 +1576,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{model: self.models.Company},
{model: self.models.Tag},
{model: self.models.Price, where: {
value: {gt: 5}
value: { [Op.gt]: 5}
}}
],
limit: 6,
......
......@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect,
sinon = require('sinon'),
Support = require(__dirname + '/../support'),
Op = Support.Sequelize.Op,
DataTypes = require(__dirname + '/../../../lib/data-types'),
Promise = require('bluebird');
......@@ -332,10 +333,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
include: [
{
model: Project,
where: { '$and': [{ m: 'A' }] },
where: { [Op.and]: [{ m: 'A' }] },
include: [{
model: User,
where: { '$and': [{ name: 'user-name-2' }] }
where: { [Op.and]: [{ name: 'user-name-2' }] }
}
]
},
......@@ -381,15 +382,15 @@ describe(Support.getTestDialectTeaser('Include'), () => {
limit: 1,
offset: 1,
where: sequelize.or(
{ first_name: { like: '%user-fname%' } },
{ last_name: { like: '%user-lname%' } }
{ first_name: { [Op.like]: '%user-fname%' } },
{ last_name: { [Op.like]: '%user-lname%' } }
),
include: [
{
model: Project,
required: true,
where: { name: {
$in: ['naam-satya', 'guru-satya']
[Op.in]: ['naam-satya', 'guru-satya']
}}
}
]
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
......@@ -1027,7 +1028,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
{model: Tag, as: 'Category'},
{model: Price, where: {
value: {
gt: 15
[Op.gt]: 15
}
}}
]}
......@@ -1124,7 +1125,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
{model: self.models.Company},
{model: self.models.Tag},
{model: self.models.Price, where: {
value: {gt: 5}
value: { [Op.gt]: 5}
}}
],
limit: 6,
......
......@@ -11,6 +11,7 @@ const chai = require('chai'),
moment = require('moment'),
Promise = require('bluebird'),
current = Support.sequelize,
Op = Sequelize.Op,
semver = require('semver');
describe(Support.getTestDialectTeaser('Model'), () => {
......@@ -125,7 +126,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
{aNumber: 10},
{aNumber: 12}
]).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.updatedAt).format('YYYY-MM-DD')).to.equal('2012-01-02');
users.forEach(u => {
......@@ -1884,7 +1885,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const self = this;
return this.User.create({username: 'user1'}).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);
});
});
......@@ -2693,7 +2694,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.sequelize.or({ username: 'leia' }, { username: 'luke' }),
this.sequelize.and(
{ 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 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise,
expect = chai.expect,
Support = require(__dirname + '/../../support'),
......@@ -57,7 +58,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({
where: {
name: {
$regexp: '^Foo'
[Op.regexp]: '^Foo'
}
}
});
......@@ -75,7 +76,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({
where: {
name: {
$notRegexp: '^Foo'
[Op.notRegexp]: '^Foo'
}
}
});
......@@ -94,7 +95,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({
where: {
name: {
$iRegexp: '^foo'
[Op.iRegexp]: '^foo'
}
}
});
......@@ -112,7 +113,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return self.User.find({
where: {
name: {
$notIRegexp: '^foo'
[Op.notIRegexp]: '^foo'
}
}
});
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise,
expect = chai.expect,
Support = require(__dirname + '/../support'),
......@@ -88,7 +89,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return User.findAll({
where: {
updatedAt: {
ne: null
[Op.ne]: null
}
}
}).then(users => {
......
......@@ -8,6 +8,7 @@ const chai = require('chai'),
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
dialect = Support.getTestDialect(),
Op = Sequelize.Op,
_ = require('lodash'),
assert = require('assert'),
current = Support.sequelize;
......@@ -150,7 +151,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
.then(() => User.create({ username: 'gottlieb' }))
.then(() => User.findOrCreate({
where: {
$or: [{
[Op.or]: [{
objectId: 'asdasdasd1'
}, {
objectId: 'asdasdasd2'
......@@ -686,7 +687,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return User.findOne({
where: {
updatedAt: {
ne: null
[Op.ne]: null
}
}
}).then(user => {
......
......@@ -5,6 +5,7 @@ const chai = require('chai'),
Sequelize = require('../../../index'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
Op = Sequelize.Op,
DataTypes = require(__dirname + '/../../../lib/data-types'),
dialect = Support.getTestDialect(),
config = require(__dirname + '/../../config/config'),
......@@ -103,7 +104,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
username: {
like: '%2'
[Op.like]: '%2'
}
}
}).then(users => {
......@@ -118,7 +119,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
username: {
nlike: '%2'
[Op.notLike]: '%2'
}
}
}).then(users => {
......@@ -134,7 +135,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
username: {
ilike: '%2'
[Op.iLike]: '%2'
}
}
}).then(users => {
......@@ -149,7 +150,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
username: {
notilike: '%2'
[Op.notILike]: '%2'
}
}
}).then(users => {
......@@ -165,7 +166,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
'..': ['2013-01-02', '2013-01-11']
[Op.between]: ['2013-01-02', '2013-01-11']
}
}
}).then(users => {
......@@ -178,7 +179,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
intVal: {
'!..': [8, 10]
[Op.notBetween]: [8, 10]
}
}
}).then(users => {
......@@ -303,7 +304,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
between: ['2013-01-02', '2013-01-11']
[Op.between]: ['2013-01-02', '2013-01-11']
}
}
}).then(users => {
......@@ -316,7 +317,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
between: ['2013-01-02', '2013-01-11']
[Op.between]: ['2013-01-02', '2013-01-11']
},
intVal: 10
}
......@@ -330,7 +331,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
intVal: {
nbetween: [8, 10]
[Op.notBetween]: [8, 10]
}
}
}).then(users => {
......@@ -343,8 +344,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
between: ['2012-12-10', '2013-01-02'],
nbetween: ['2013-01-04', '2013-01-20']
[Op.between]: ['2012-12-10', '2013-01-02'],
[Op.notBetween]: ['2013-01-04', '2013-01-20']
}
}
}).then(users => {
......@@ -357,8 +358,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
between: [new Date('2012-12-10'), new Date('2013-01-02')],
nbetween: [new Date('2013-01-04'), new Date('2013-01-20')]
[Op.between]: [new Date('2012-12-10'), new Date('2013-01-02')],
[Op.notBetween]: [new Date('2013-01-04'), new Date('2013-01-20')]
}
}
}).then(users => {
......@@ -371,7 +372,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
theDate: {
gte: new Date('2013-01-09')
[Op.gte]: new Date('2013-01-09')
}
}
}).then(users => {
......@@ -384,7 +385,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({
where: {
intVal: {
gte: 6
[Op.gte]: 6
}
}
}).then(user => {
......@@ -397,7 +398,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({
where: {
intVal: {
gt: 5
[Op.gt]: 5
}
}
}).then(user => {
......@@ -410,7 +411,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({
where: {
intVal: {
lte: 5
[Op.lte]: 5
}
}
}).then(user => {
......@@ -423,7 +424,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({
where: {
intVal: {
lt: 6
[Op.lt]: 6
}
}
}).then(user => {
......@@ -436,8 +437,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
intVal: {
lt: 6,
gt: 4
[Op.lt]: 6,
[Op.gt]: 4
}
}
}).then(users => {
......@@ -450,7 +451,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.find({
where: {
intVal: {
ne: 10
[Op.ne]: 10
}
}
}).then(user => {
......@@ -463,7 +464,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.User.findAll({
where: {
intVal: {
lte: 10
[Op.lte]: 10
}
}
}).then(users => {
......@@ -1033,7 +1034,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({
include: [{
model: this.Animal,
where: { age: { $gte: 29 } },
where: { age: { [Op.gte]: 29 } },
attributes: []
}]
}).then(kingdoms => {
......@@ -1049,7 +1050,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({
include: [{
model: this.Animal,
where: { age: { $gte: 29 } },
where: { age: { [Op.gte]: 29 } },
through: {
attributes: []
}
......@@ -1067,7 +1068,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Kingdom.findAll({
include: [{
model: this.Animal,
where: { age: { $gte: 29 } },
where: { age: { [Op.gte]: 29 } },
attributes: [],
through: {
attributes: ['mutation']
......@@ -1494,7 +1495,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
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(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2);
......@@ -1502,7 +1503,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2);
......@@ -1580,7 +1581,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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(Array.isArray(info.rows)).to.be.ok;
expect(info.rows.length).to.equal(2);
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise,
moment = require('moment'),
expect = chai.expect,
......@@ -281,7 +282,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Event.findAll({
where: {
json: {
lastLogin: {$between: [before, after]}
lastLogin: {[Op.between]: [before, after]}
}
}
}).then(events => {
......@@ -324,7 +325,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.Event.findAll({
where: {
json: {
active: {$in: [true, false]}
active: {[Op.in]: [true, false]}
}
}
}).then(events => {
......@@ -364,7 +365,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
where: {
data: {
age: {
$gt: 38
[Op.gt]: 38
}
}
}
......@@ -515,7 +516,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
last: 'Simpson'
},
employment: {
$ne: 'None'
[Op.ne]: 'None'
}
}
},
......
......@@ -5,7 +5,9 @@ const chai = require('chai'),
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
current = Support.sequelize,
Op = current.Op,
Promise = current.Promise;
const SCHEMA_ONE = 'schema_one';
const SCHEMA_TWO = 'schema_two';
......@@ -101,7 +103,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
describe('Get associated data in public schema via include', () => {
beforeEach(function() {
return Promise.all([
......@@ -290,7 +292,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(restaurant.bar).to.contain('one');
});
return self.RestaurantOne.findAll({
where: {bar: {$like: '%.1'}}
where: {bar: {[Op.like]: '%.1'}}
});
}).then(restaurantsOne => {
expect(restaurantsOne).to.not.be.null;
......@@ -318,7 +320,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(restaurant.bar).to.contain('two');
});
return self.RestaurantTwo.findAll({
where: {bar: {$like: '%.3'}}
where: {bar: {[Op.like]: '%.3'}}
});
}).then(restaurantsTwo => {
expect(restaurantsTwo).to.not.be.null;
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../support');
......@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
attributes: ['other_value', 'access_level'],
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
},
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../../support'),
Promise = require(__dirname + '/../../../../lib/promise');
......@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
}
},
......@@ -30,7 +31,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: {
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
},
......@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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() {
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Promise = Sequelize.Promise,
Support = require(__dirname + '/../../support');
......@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
}
},
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Promise = require(__dirname + '/../../../../lib/promise'),
Support = require(__dirname + '/../../support');
......@@ -22,7 +23,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
},
attributes: ['id', 'username', 'email', 'access_level']
......@@ -31,7 +32,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: {
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
},
......@@ -98,7 +99,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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() {
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../../support');
......@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
}
},
......@@ -26,7 +27,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: {
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
}
......@@ -55,7 +56,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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();
}).then(users => {
expect(users).to.have.length(2);
......
......@@ -3,6 +3,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
expect = chai.expect,
Op = Sequelize.Op,
Support = require(__dirname + '/../../support');
describe(Support.getTestDialectTeaser('Model'), () => {
......@@ -18,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
}
},
......@@ -26,16 +27,16 @@ describe(Support.getTestDialectTeaser('Model'), () => {
highValue: {
where: {
other_value: {
gte: 10
[Op.gte]: 10
}
}
},
andScope: {
where: {
$and: [
[Op.and]: [
{
email: {
like: '%@sequelizejs.com'
[Op.like]: '%@sequelizejs.com'
}
},
{ access_level: 3 }
......
......@@ -2,6 +2,7 @@
const chai = require('chai'),
Sequelize = require('../../../../index'),
Op = Sequelize.Op,
expect = chai.expect,
Support = require(__dirname + '/../../support');
......@@ -20,7 +21,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
},
attributes: ['username', 'email', 'access_level']
......@@ -29,7 +30,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: {
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
},
......@@ -58,7 +59,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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 => {
expect(result.count).to.equal(1);
expect(result.rows.length).to.equal(1);
......
......@@ -4,6 +4,7 @@ const chai = require('chai'),
_ = require('lodash'),
Sequelize = require('../../../../index'),
expect = chai.expect,
Op = Sequelize.Op,
Support = require(__dirname + '/../../support');
describe(Support.getTestDialectTeaser('Model'), () => {
......@@ -19,7 +20,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
defaultScope: {
where: {
access_level: {
gte: 5
[Op.gte]: 5
}
}
},
......@@ -27,7 +28,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
lowAccess: {
where: {
access_level: {
lte: 5
[Op.lte]: 5
}
}
}
......@@ -56,7 +57,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
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' }});
}).then(users => {
expect(users).to.have.length(2);
......@@ -77,7 +78,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
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.unscoped().findAll({ where: { username: { $ne: 'ruben' }}});
return this.ScopeMe.unscoped().findAll({ where: { username: { [Op.ne]: 'ruben' }}});
}).then(users => {
expect(users).to.have.length(1);
expect(users[0].get('email')).to.equal('tobi@fakeemail.com');
......
......@@ -4,6 +4,7 @@ const chai = require('chai');
const expect = chai.expect;
const Support = require(__dirname + '/../support');
const DataTypes = require(__dirname + '/../../../lib/data-types');
const Op = Support.Sequelize.Op;
const SEARCH_PATH_ONE = 'schema_one,public';
const SEARCH_PATH_TWO = 'schema_two,public';
......@@ -225,7 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return restaurauntModel.save({searchPath: SEARCH_PATH_TWO});
}).then(() => {
return Restaurant.findAll({
where: {bar: {$like: 'one%'}},
where: {bar: {[Op.like]: 'one%'}},
searchPath: SEARCH_PATH_ONE
});
}).then(restaurantsOne => {
......@@ -239,7 +240,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(count).to.not.be.null;
expect(count).to.equal(2);
return Restaurant.findAll({
where: {bar: {$like: 'two%'}},
where: {bar: {[Op.like]: 'two%'}},
searchPath: SEARCH_PATH_TWO
});
}).then(restaurantsTwo => {
......
......@@ -60,17 +60,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
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', () => {
const operatorsAliases = { fake: true };
const sequelize = Support.createSequelizeInstance({ operatorsAliases });
......
......@@ -5,7 +5,8 @@ const chai = require('chai'),
Utils = require(__dirname + '/../../lib/utils'),
Support = require(__dirname + '/support'),
DataTypes = require(__dirname + '/../../lib/data-types'),
Sequelize = require('../../index');
Sequelize = require('../../index'),
Op = Sequelize.Op;
describe(Support.getTestDialectTeaser('Utils'), () => {
describe('removeCommentsFromFunctionString', () => {
......@@ -265,9 +266,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => {
engines: 1
}, type)), 'count-engines'],
[Sequelize.fn('SUM', Sequelize.cast({
$or: {
[Op.or]: {
engines: {
$gt: 1
[Op.gt]: 1
},
wings: 4
}
......@@ -290,9 +291,9 @@ describe(Support.getTestDialectTeaser('Utils'), () => {
engines: 1
}), 'count-engines'],
[Sequelize.fn('SUM', {
$or: {
[Op.or]: {
engines: {
$gt: 1
[Op.gt]: 1
},
wings: 4
}
......
......@@ -19,7 +19,7 @@ describe('QueryGenerator', () => {
.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);
expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}]))
.to.throw('Invalid value { test: 5 }');
......@@ -86,7 +86,6 @@ describe('QueryGenerator', () => {
expect(() => QG.whereItemQuery('test', {$in: [4]}))
.to.throw('Invalid value { \'$in\': [ 4 ] }');
});
});
});
......@@ -5,7 +5,7 @@ const chai = require('chai'),
Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(),
_ = require('lodash'),
Operators = require('../../../../lib/operators'),
Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/mysql/query-generator');
if (dialect === 'mysql') {
......@@ -320,7 +320,7 @@ if (dialect === 'mysql') {
return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
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;',
......@@ -332,7 +332,7 @@ if (dialect === 'mysql') {
return {
where: sequelize.and(
{ 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') {
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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]';",
context: QueryGenerator
}, {
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]';",
context: QueryGenerator
}, {
......@@ -433,7 +433,7 @@ if (dialect === 'mysql') {
return {
subQuery: true,
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`;',
......@@ -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
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);
expect(conditions).to.deep.equal(test.expectation);
......
......@@ -2,7 +2,7 @@
const chai = require('chai'),
expect = chai.expect,
Operators = require('../../../../lib/operators'),
Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/postgres/query-generator'),
Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(),
......@@ -356,12 +356,12 @@ if (dialect.match(/^postgres/)) {
context: QueryGenerator,
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) {
return {
where: sequelize.and(
{ 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/)) {
return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
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;',
......@@ -432,7 +432,7 @@ if (dialect.match(/^postgres/)) {
context: QueryGenerator
}, {
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'];"
},
......@@ -503,43 +503,43 @@ if (dialect.match(/^postgres/)) {
expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name = 'foo'';DROP TABLE mySchema.myTable;';",
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use != if ne !== null',
arguments: ['myTable', {where: {field: {ne: 0}}}],
title: 'use != if Op.ne !== null',
arguments: ['myTable', {where: {field: {[Op.ne]: 0}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 0;',
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use IS NOT if ne === null',
arguments: ['myTable', {where: {field: {ne: null}}}],
title: 'use IS NOT if Op.ne === null',
arguments: ['myTable', {where: {field: {[Op.ne]: null}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;',
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', {where: {field: {not: true}}}],
title: 'use IS NOT if Op.not === BOOLEAN',
arguments: ['myTable', {where: {field: {[Op.not]: true}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;',
context: {options: {quoteIdentifiers: false}}
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', {where: {field: {not: 3}}}],
title: 'use != if Op.not !== BOOLEAN',
arguments: ['myTable', {where: {field: {[Op.not]: 3}}}],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;',
context: {options: {quoteIdentifiers: false}}
}, {
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]';",
context: QueryGenerator
}, {
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]';",
context: QueryGenerator
}, {
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]';",
context: QueryGenerator
}, {
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]';",
context: QueryGenerator
}
......@@ -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
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);
expect(conditions).to.deep.equal(test.expectation);
......
......@@ -7,7 +7,7 @@ const chai = require('chai'),
dialect = Support.getTestDialect(),
_ = require('lodash'),
moment = require('moment'),
Operators = require('../../../../lib/operators'),
Op = require('../../../../lib/operators'),
QueryGenerator = require('../../../../lib/dialects/sqlite/query-generator');
if (dialect === 'sqlite') {
......@@ -294,7 +294,7 @@ if (dialect === 'sqlite') {
return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
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;',
......@@ -340,22 +340,22 @@ if (dialect === 'sqlite') {
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}, {
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;',
context: QueryGenerator
}
......@@ -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
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);
expect(conditions).to.deep.equal(test.expectation);
......
......@@ -4,6 +4,7 @@ const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
current = Support.sequelize,
Op = current.Op,
sinon = require('sinon'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
Promise = require('bluebird');
......@@ -62,7 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should add limit when using { $ gt on the primary key', function() {
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');
});
});
......
......@@ -6,6 +6,7 @@ const chai = require('chai'),
Sequelize = require(__dirname + '/../../../index'),
Support = require(__dirname + '/../support'),
current = Support.sequelize,
Op = current.Op,
Promise = current.Promise,
config = require(__dirname + '/../../config/config');
......@@ -355,8 +356,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return expect(User.all({
where: {
name: {
$like: {
$any: ['foo%', 'bar%']
[Op.like]: {
[Op.any]: ['foo%', 'bar%']
}
}
}
......@@ -367,7 +368,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return expect(User.all({
where: {
uid: {
$like: '12345678%'
[Op.like]: '12345678%'
}
}
})).not.to.be.rejected;
......
......@@ -4,6 +4,7 @@ const Support = require(__dirname + '/../support');
const current = Support.sequelize;
const expectsql = Support.expectsql;
const sql = current.dialect.QueryGenerator;
const Op = current.Op;
const expect = require('chai').expect;
const sinon = require('sinon');
......@@ -61,9 +62,9 @@ if (current.dialect.supports.constraints.addConstraint) {
name: 'check_mycolumn_where',
where: {
myColumn: {
$and: {
$gt: 50,
$lt: 100
[Op.and]: {
[Op.gt]: 50,
[Op.lt]: 100
}
}
}
......
'use strict';
const Support = require(__dirname + '/../support'),
const Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
Sequelize = require(__dirname + '/../../../lib/sequelize'),
util = require('util'),
_ = require('lodash'),
expectsql = Support.expectsql,
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
......@@ -279,8 +280,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
include: [
{
association: User.Tasks, on: {
$or: [
{ '$User.id_user$': { $col: 'Tasks.user_id' } },
[Op.or]: [
{ '$User.id_user$': { [Op.col]: 'Tasks.user_id' } },
{ '$Tasks.user_id$': 2 }
]
}
......@@ -296,7 +297,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
include: [
{
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]' }
......@@ -314,8 +315,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
{
association: Company.Owner,
on: {
$or: [
{ '$Company.owner_id$': { $col: 'Company.Owner.id_user'} },
[Op.or]: [
{ '$Company.owner_id$': { [Op.col]: 'Company.Owner.id_user'} },
{ '$Company.Owner.id_user$': 2 }
]
}
......
......@@ -5,6 +5,7 @@ const current = Support.sequelize;
const expectsql = Support.expectsql;
const sql = current.dialect.QueryGenerator;
const expect = require('chai').expect;
const Op = current.Op;
describe(Support.getTestDialectTeaser('SQL'), () => {
describe('getConstraintSnippet', () => {
......@@ -61,9 +62,9 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
name: 'check_mycolumn_where',
where: {
myColumn: {
$and: {
$gt: 50,
$lt: 100
[Op.and]: {
[Op.gt]: 50,
[Op.lt]: 100
}
}
}
......
......@@ -3,7 +3,8 @@
const Support = require(__dirname + '/../support'),
expectsql = Support.expectsql,
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
......@@ -103,7 +104,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
fields: ['type'],
where: {
type: {
$or: [
[Op.or]: [
'group',
'private'
]
......@@ -119,7 +120,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
fields: ['type'],
where: {
type: {
$ne: null
[Op.ne]: null
}
}
}), {
......
......@@ -8,7 +8,8 @@ const Support = require(__dirname + '/../support'),
expect = chai.expect,
expectsql = Support.expectsql,
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
......@@ -170,7 +171,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
],
where: {
age: {
$gte: 21
[Op.gte]: 21
}
},
groupedLimit: {
......
......@@ -5,7 +5,8 @@ const Support = require(__dirname + '/../support'),
util = require('util'),
expectsql = Support.expectsql,
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
......@@ -45,21 +46,21 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql({
name: 'a project',
$or: [
[Op.or]: [
{ id: [1, 2, 3] },
{ id: { $gt: 10 } }
{ id: { [Op.gt]: 10 } }
]
}, {
default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)",
mssql: "WHERE [name] = N'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
default: "WHERE ([id] IN (1, 2, 3) OR [id] > 10) AND [name] = 'a project'",
mssql: "WHERE ([id] IN (1, 2, 3) OR [id] > 10) AND [name] = N'a project'"
});
testsql({
name: 'a project',
id: {
$or: [
[Op.or]: [
[1, 2, 3],
{ $gt: 10 }
{ [Op.gt]: 10 }
]
}
}, {
......@@ -83,7 +84,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
options = undefined;
}
test(key+': '+util.inspect(value, {depth: 10})+(options && ', '+util.inspect(options) || ''), () => {
test(String(key)+': '+util.inspect(value, {depth: 10})+(options && ', '+util.inspect(options) || ''), () => {
return expectsql(sql.whereItemQuery(key, value, options), expectation);
});
};
......@@ -100,25 +101,25 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$in', () => {
testsql('equipment', {
$in: [1, 3]
[Op.in]: [1, 3]
}, {
default: '[equipment] IN (1, 3)'
});
testsql('equipment', {
$in: []
[Op.in]: []
}, {
default: '[equipment] IN (NULL)'
});
testsql('muscles', {
in: [2, 4]
[Op.in]: [2, 4]
}, {
default: '[muscles] IN (2, 4)'
});
testsql('equipment', {
$in: current.literal(
[Op.in]: current.literal(
'(select order_id from product_orders where product_id = 3)'
)
}, {
......@@ -137,7 +138,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$not', () => {
testsql('deleted', {
$not: true
[Op.not]: true
}, {
default: '[deleted] IS NOT true',
mssql: '[deleted] IS NOT 1',
......@@ -145,13 +146,13 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('deleted', {
$not: null
[Op.not]: null
}, {
default: '[deleted] IS NOT NULL'
});
testsql('muscles', {
$not: 3
[Op.not]: 3
}, {
default: '[muscles] != 3'
});
......@@ -159,19 +160,19 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notIn', () => {
testsql('equipment', {
$notIn: []
[Op.notIn]: []
}, {
default: ''
});
testsql('equipment', {
$notIn: [4, 19]
[Op.notIn]: [4, 19]
}, {
default: '[equipment] NOT IN (4, 19)'
});
testsql('equipment', {
$notIn: current.literal(
[Op.notIn]: current.literal(
'(select order_id from product_orders where product_id = 3)'
)
}, {
......@@ -181,7 +182,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$ne', () => {
testsql('email', {
$ne: 'jack.bauer@gmail.com'
[Op.ne]: 'jack.bauer@gmail.com'
}, {
default: "[email] != 'jack.bauer@gmail.com'",
mssql: "[email] != N'jack.bauer@gmail.com'"
......@@ -191,22 +192,22 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$and/$or/$not', () => {
suite('$or', () => {
testsql('email', {
$or: ['maker@mhansen.io', 'janzeh@gmail.com']
[Op.or]: ['maker@mhansen.io', 'janzeh@gmail.com']
}, {
default: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')',
mssql: '([email] = N\'maker@mhansen.io\' OR [email] = N\'janzeh@gmail.com\')'
});
testsql('rank', {
$or: {
$lt: 100,
$eq: null
[Op.or]: {
[Op.lt]: 100,
[Op.eq]: null
}
}, {
default: '([rank] < 100 OR [rank] IS NULL)'
});
testsql('$or', [
testsql(Op.or, [
{email: 'maker@mhansen.io'},
{email: 'janzeh@gmail.com'}
], {
......@@ -214,7 +215,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
mssql: '([email] = N\'maker@mhansen.io\' OR [email] = N\'janzeh@gmail.com\')'
});
testsql('$or', {
testsql(Op.or, {
email: 'maker@mhansen.io',
name: 'Mick Hansen'
}, {
......@@ -222,16 +223,16 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
mssql: '([email] = N\'maker@mhansen.io\' OR [name] = N\'Mick Hansen\')'
});
testsql('$or', {
testsql(Op.or, {
equipment: [1, 3],
muscles: {
$in: [2, 4]
[Op.in]: [2, 4]
}
}, {
default: '([equipment] IN (1, 3) OR [muscles] IN (2, 4))'
});
testsql('$or', [
testsql(Op.or, [
{
roleName: 'NEW'
}, {
......@@ -256,11 +257,11 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
});
testsql('$or', [], {
testsql(Op.or, [], {
default: '0 = 1'
});
testsql('$or', {}, {
testsql(Op.or, {}, {
default: '0 = 1'
});
......@@ -272,8 +273,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
suite('$and', () => {
testsql('$and', {
$or: {
testsql(Op.and, {
[Op.or]: {
group_id: 1,
user_id: 2
},
......@@ -282,15 +283,15 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
default: '(([group_id] = 1 OR [user_id] = 2) AND [shared] = 1)'
});
testsql('$and', [
testsql(Op.and, [
{
name: {
$like: '%hello'
[Op.like]: '%hello'
}
},
{
name: {
$like: 'hello%'
[Op.like]: 'hello%'
}
}
], {
......@@ -299,18 +300,18 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('rank', {
$and: {
$ne: 15,
$between: [10, 20]
[Op.and]: {
[Op.ne]: 15,
[Op.between]: [10, 20]
}
}, {
default: '([rank] != 15 AND [rank] BETWEEN 10 AND 20)'
});
testsql('name', {
$and: [
{like: '%someValue1%'},
{like: '%someValue2%'}
[Op.and]: [
{[Op.like]: '%someValue1%'},
{[Op.like]: '%someValue2%'}
]
}, {
default: "([name] LIKE '%someValue1%' AND [name] LIKE '%someValue2%')",
......@@ -325,8 +326,8 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
suite('$not', () => {
testsql('$not', {
$or: {
testsql(Op.not, {
[Op.or]: {
group_id: 1,
user_id: 2
},
......@@ -335,11 +336,11 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
default: 'NOT (([group_id] = 1 OR [user_id] = 2) AND [shared] = 1)'
});
testsql('$not', [], {
testsql(Op.not, [], {
default: '0 = 1'
});
testsql('$not', {}, {
testsql(Op.not, {}, {
default: '0 = 1'
});
});
......@@ -347,42 +348,42 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$col', () => {
testsql('userId', {
$col: 'user.id'
[Op.col]: 'user.id'
}, {
default: '[userId] = [user].[id]'
});
testsql('userId', {
$eq: {
$col: 'user.id'
[Op.eq]: {
[Op.col]: 'user.id'
}
}, {
default: '[userId] = [user].[id]'
});
testsql('userId', {
$gt: {
$col: 'user.id'
[Op.gt]: {
[Op.col]: 'user.id'
}
}, {
default: '[userId] > [user].[id]'
});
testsql('$or', [
{'ownerId': {$col: 'user.id'}},
{'ownerId': {$col: 'organization.id'}}
testsql(Op.or, [
{'ownerId': {[Op.col]: 'user.id'}},
{'ownerId': {[Op.col]: 'organization.id'}}
], {
default: '([ownerId] = [user].[id] OR [ownerId] = [organization].[id])'
});
testsql('$organization.id$', {
$col: 'user.organizationId'
[Op.col]: 'user.organizationId'
}, {
default: '[organization].[id] = [user].[organizationId]'
});
testsql('$offer.organization.id$', {
$col: 'offer.user.organizationId'
[Op.col]: 'offer.user.organizationId'
}, {
default: '[offer->organization].[id] = [offer->user].[organizationId]'
});
......@@ -390,14 +391,14 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$gt', () => {
testsql('rank', {
$gt: 2
[Op.gt]: 2
}, {
default: '[rank] > 2'
});
testsql('created_at', {
$lt: {
$col: 'updated_at'
[Op.lt]: {
[Op.col]: 'updated_at'
}
}, {
default: '[created_at] < [updated_at]'
......@@ -406,7 +407,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$like', () => {
testsql('username', {
$like: '%swagger'
[Op.like]: '%swagger'
}, {
default: "[username] LIKE '%swagger'",
mssql: "[username] LIKE N'%swagger'"
......@@ -415,15 +416,15 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$between', () => {
testsql('date', {
$between: ['2013-01-01', '2013-01-11']
[Op.between]: ['2013-01-01', '2013-01-11']
}, {
default: "[date] BETWEEN '2013-01-01' AND '2013-01-11'",
mssql: "[date] BETWEEN N'2013-01-01' AND N'2013-01-11'"
});
testsql('date', {
between: ['2012-12-10', '2013-01-02'],
nbetween: ['2013-01-04', '2013-01-20']
[Op.between]: ['2012-12-10', '2013-01-02'],
[Op.notBetween]: ['2013-01-04', '2013-01-20']
}, {
default: "([date] BETWEEN '2012-12-10' AND '2013-01-02' AND [date] NOT BETWEEN '2013-01-04' AND '2013-01-20')",
mssql: "([date] BETWEEN N'2012-12-10' AND N'2013-01-02' AND [date] NOT BETWEEN N'2013-01-04' AND N'2013-01-20')"
......@@ -432,7 +433,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notBetween', () => {
testsql('date', {
$notBetween: ['2013-01-01', '2013-01-11']
[Op.notBetween]: ['2013-01-01', '2013-01-11']
}, {
default: "[date] NOT BETWEEN '2013-01-01' AND '2013-01-11'",
mssql: "[date] NOT BETWEEN N'2013-01-01' AND N'2013-01-11'"
......@@ -443,19 +444,19 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('ARRAY', () => {
suite('$contains', () => {
testsql('muscles', {
$contains: [2, 3]
[Op.contains]: [2, 3]
}, {
postgres: '"muscles" @> ARRAY[2,3]'
});
testsql('muscles', {
$contained: [6, 8]
[Op.contained]: [6, 8]
}, {
postgres: '"muscles" <@ ARRAY[6,8]'
});
testsql('muscles', {
$contains: [2, 5]
[Op.contains]: [2, 5]
}, {
field: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
......@@ -467,33 +468,21 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$overlap', () => {
testsql('muscles', {
$overlap: [3, 11]
[Op.overlap]: [3, 11]
}, {
postgres: '"muscles" && ARRAY[3,11]'
});
testsql('muscles', {
$overlap: [3, 1]
}, {
postgres: '"muscles" && ARRAY[3,1]'
});
testsql('muscles', {
'&&': [9, 182]
}, {
postgres: '"muscles" && ARRAY[9,182]'
});
});
suite('$any', () => {
testsql('userId', {
$any: [4, 5, 6]
[Op.any]: [4, 5, 6]
}, {
postgres: '"userId" = ANY (ARRAY[4,5,6])'
});
testsql('userId', {
$any: [2, 5]
[Op.any]: [2, 5]
}, {
field: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
......@@ -504,16 +493,16 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$values', () => {
testsql('userId', {
$any: {
$values: [4, 5, 6]
[Op.any]: {
[Op.values]: [4, 5, 6]
}
}, {
postgres: '"userId" = ANY (VALUES (4), (5), (6))'
});
testsql('userId', {
$any: {
$values: [2, 5]
[Op.any]: {
[Op.values]: [2, 5]
}
}, {
field: {
......@@ -527,13 +516,13 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$all', () => {
testsql('userId', {
$all: [4, 5, 6]
[Op.all]: [4, 5, 6]
}, {
postgres: '"userId" = ALL (ARRAY[4,5,6])'
});
testsql('userId', {
$all: [2, 5]
[Op.all]: [2, 5]
}, {
field: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
......@@ -544,16 +533,16 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$values', () => {
testsql('userId', {
$all: {
$values: [4, 5, 6]
[Op.all]: {
[Op.values]: [4, 5, 6]
}
}, {
postgres: '"userId" = ALL (VALUES (4), (5), (6))'
});
testsql('userId', {
$all: {
$values: [2, 5]
[Op.all]: {
[Op.values]: [2, 5]
}
}, {
field: {
......@@ -567,64 +556,64 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$like', () => {
testsql('userId', {
$like: {
$any: ['foo', 'bar', 'baz']
[Op.like]: {
[Op.any]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" LIKE ANY (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$iLike: {
$any: ['foo', 'bar', 'baz']
[Op.iLike]: {
[Op.any]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" ILIKE ANY (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$notLike: {
$any: ['foo', 'bar', 'baz']
[Op.notLike]: {
[Op.any]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" NOT LIKE ANY (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$notILike: {
$any: ['foo', 'bar', 'baz']
[Op.notILike]: {
[Op.any]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" NOT ILIKE ANY (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$like: {
$all: ['foo', 'bar', 'baz']
[Op.like]: {
[Op.all]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" LIKE ALL (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$iLike: {
$all: ['foo', 'bar', 'baz']
[Op.iLike]: {
[Op.all]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" ILIKE ALL (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$notLike: {
$all: ['foo', 'bar', 'baz']
[Op.notLike]: {
[Op.all]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" NOT LIKE ALL (ARRAY['foo','bar','baz'])"
});
testsql('userId', {
$notILike: {
$all: ['foo', 'bar', 'baz']
[Op.notILike]: {
[Op.all]: ['foo', 'bar', 'baz']
}
}, {
postgres: "\"userId\" NOT ILIKE ALL (ARRAY['foo','bar','baz'])"
......@@ -637,7 +626,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('RANGE', () => {
testsql('range', {
$contains: new Date(Date.UTC(2000, 1, 1))
[Op.contains]: new Date(Date.UTC(2000, 1, 1))
}, {
field: {
type: new DataTypes.postgres.RANGE(DataTypes.DATE)
......@@ -648,7 +637,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('range', {
$contains: [new Date(Date.UTC(2000, 1, 1)), new Date(Date.UTC(2000, 2, 1))]
[Op.contains]: [new Date(Date.UTC(2000, 1, 1)), new Date(Date.UTC(2000, 2, 1))]
}, {
field: {
type: new DataTypes.postgres.RANGE(DataTypes.DATE)
......@@ -659,7 +648,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('range', {
$contained: [new Date(Date.UTC(2000, 1, 1)), new Date(Date.UTC(2000, 2, 1))]
[Op.contained]: [new Date(Date.UTC(2000, 1, 1)), new Date(Date.UTC(2000, 2, 1))]
}, {
field: {
type: new DataTypes.postgres.RANGE(DataTypes.DATE)
......@@ -670,7 +659,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('unboundedRange', {
$contains: [new Date(Date.UTC(2000, 1, 1)), null]
[Op.contains]: [new Date(Date.UTC(2000, 1, 1)), null]
}, {
field: {
type: new DataTypes.postgres.RANGE(DataTypes.DATE)
......@@ -681,7 +670,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('unboundedRange', {
$contains: [-Infinity, Infinity]
[Op.contains]: [-Infinity, Infinity]
}, {
field: {
type: new DataTypes.postgres.RANGE(DataTypes.DATE)
......@@ -692,7 +681,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$overlap: [1, 4]
[Op.overlap]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -703,7 +692,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$adjacent: [1, 4]
[Op.adjacent]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -714,7 +703,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$strictLeft: [1, 4]
[Op.strictLeft]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -725,7 +714,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$strictRight: [1, 4]
[Op.strictRight]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -736,7 +725,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$noExtendRight: [1, 4]
[Op.noExtendRight]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -747,7 +736,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('reservedSeats', {
$noExtendLeft: [1, 4]
[Op.noExtendLeft]: [1, 4]
}, {
field: {
type: new DataTypes.postgres.RANGE()
......@@ -795,7 +784,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql('data', {
nested: {
$in: [1, 2]
[Op.in]: [1, 2]
}
}, {
field: {
......@@ -809,7 +798,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql('data', {
nested: {
$between: [1, 2]
[Op.between]: [1, 2]
}
}, {
field: {
......@@ -825,7 +814,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
nested: {
attribute: 'value',
prop: {
$ne: 'None'
[Op.ne]: 'None'
}
}
}, {
......@@ -844,7 +833,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
last: 'Simpson'
},
employment: {
$ne: 'None'
[Op.ne]: 'None'
}
}, {
field: {
......@@ -899,7 +888,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
});
testsql('data.nested.attribute', {
$in: [3, 7]
[Op.in]: [3, 7]
}, {
model: {
rawAttributes: {
......@@ -917,7 +906,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql('data', {
nested: {
attribute: {
$gt: 2
[Op.gt]: 2
}
}
}, {
......@@ -933,7 +922,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql('data', {
nested: {
'attribute::integer': {
$gt: 2
[Op.gt]: 2
}
}
}, {
......@@ -950,7 +939,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
testsql('data', {
nested: {
attribute: {
$gt: dt
[Op.gt]: dt
}
}
}, {
......@@ -998,7 +987,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
if (current.dialect.supports.JSONB) {
suite('JSONB', () => {
testsql('data', {
$contains: {
[Op.contains]: {
company: 'Magnafone'
}
}, {
......@@ -1014,7 +1003,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
if (current.dialect.supports.REGEXP) {
suite('$regexp', () => {
testsql('username', {
$regexp: '^sw.*r$'
[Op.regexp]: '^sw.*r$'
}, {
mysql: "`username` REGEXP '^sw.*r$'",
postgres: '"username" ~ \'^sw.*r$\''
......@@ -1023,7 +1012,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$regexp', () => {
testsql('newline', {
$regexp: '^new\nline$'
[Op.regexp]: '^new\nline$'
}, {
mysql: "`newline` REGEXP '^new\nline$'",
postgres: '"newline" ~ \'^new\nline$\''
......@@ -1032,7 +1021,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notRegexp', () => {
testsql('username', {
$notRegexp: '^sw.*r$'
[Op.notRegexp]: '^sw.*r$'
}, {
mysql: "`username` NOT REGEXP '^sw.*r$'",
postgres: '"username" !~ \'^sw.*r$\''
......@@ -1041,7 +1030,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notRegexp', () => {
testsql('newline', {
$notRegexp: '^new\nline$'
[Op.notRegexp]: '^new\nline$'
}, {
mysql: "`newline` NOT REGEXP '^new\nline$'",
postgres: '"newline" !~ \'^new\nline$\''
......@@ -1051,7 +1040,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
if (current.dialect.name === 'postgres') {
suite('$iRegexp', () => {
testsql('username', {
$iRegexp: '^sw.*r$'
[Op.iRegexp]: '^sw.*r$'
}, {
postgres: '"username" ~* \'^sw.*r$\''
});
......@@ -1059,7 +1048,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$iRegexp', () => {
testsql('newline', {
$iRegexp: '^new\nline$'
[Op.iRegexp]: '^new\nline$'
}, {
postgres: '"newline" ~* \'^new\nline$\''
});
......@@ -1067,7 +1056,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notIRegexp', () => {
testsql('username', {
$notIRegexp: '^sw.*r$'
[Op.notIRegexp]: '^sw.*r$'
}, {
postgres: '"username" !~* \'^sw.*r$\''
});
......@@ -1075,7 +1064,7 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
suite('$notIRegexp', () => {
testsql('newline', {
$notIRegexp: '^new\nline$'
[Op.notIRegexp]: '^new\nline$'
}, {
postgres: '"newline" !~* \'^new\nline$\''
});
......
......@@ -7,6 +7,7 @@ const DataTypes = require(__dirname + '/../../lib/data-types');
const Utils = require(__dirname + '/../../lib/utils');
const tedious = require('tedious');
const tediousIsolationLevel = tedious.ISOLATION_LEVEL;
const Op = Support.sequelize.Op;
suite(Support.getTestDialectTeaser('Utils'), () => {
suite('merge', () => {
......@@ -147,7 +148,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$or where', () => {
expect(Utils.mapOptionFieldNames({
where: {
$or: {
[Op.or]: {
firstName: 'Paul',
lastName: 'Atreides'
}
......@@ -163,7 +164,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
}
}))).to.eql({
where: {
$or: {
[Op.or]: {
first_name: 'Paul',
last_name: 'Atreides'
}
......@@ -174,7 +175,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$or[] where', () => {
expect(Utils.mapOptionFieldNames({
where: {
$or: [
[Op.or]: [
{firstName: 'Paul'},
{lastName: 'Atreides'}
]
......@@ -190,7 +191,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
}
}))).to.eql({
where: {
$or: [
[Op.or]: [
{first_name: 'Paul'},
{last_name: 'Atreides'}
]
......@@ -201,7 +202,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('$and where', () => {
expect(Utils.mapOptionFieldNames({
where: {
$and: {
[Op.and]: {
firstName: 'Paul',
lastName: 'Atreides'
}
......@@ -217,7 +218,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
}
}))).to.eql({
where: {
$and: {
[Op.and]: {
first_name: 'Paul',
last_name: 'Atreides'
}
......@@ -258,7 +259,7 @@ suite(Support.getTestDialectTeaser('Utils'), () => {
test('accepts condition object (auto casting)', () => {
expectsql(run(sql.fn('SUM', sql.cast({
$or: {
[Op.or]: {
foo: 'foo',
bar: 'bar'
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!