forked from sequelize/sequelize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(operators): Add $regexp operator (sequelize#7855)
Adds $regexp operator for MySQL and Postgres and its negated and case-insensitive versions.
- Loading branch information
1 parent
0528f39
commit 18e04a2
Showing
9 changed files
with
257 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'), | ||
Sequelize = require('../../../../index'), | ||
Promise = Sequelize.Promise, | ||
expect = chai.expect, | ||
Support = require(__dirname + '/../../support'), | ||
DataTypes = require(__dirname + '/../../../../lib/data-types'), | ||
dialect = Support.getTestDialect(); | ||
|
||
describe(Support.getTestDialectTeaser('Model'), () => { | ||
describe('attributes', () => { | ||
describe('operators', () => { | ||
describe('REGEXP', () => { | ||
beforeEach(function() { | ||
const queryInterface = this.sequelize.getQueryInterface(); | ||
|
||
this.User = this.sequelize.define('user', { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
field: 'userId' | ||
}, | ||
name: { | ||
type: DataTypes.STRING, | ||
field: 'full_name' | ||
} | ||
}, { | ||
tableName: 'users', | ||
timestamps: false | ||
}); | ||
|
||
return Promise.all([ | ||
queryInterface.createTable('users', { | ||
userId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
autoIncrement: true | ||
}, | ||
full_name: { | ||
type: DataTypes.STRING | ||
} | ||
}) | ||
]); | ||
}); | ||
|
||
if (dialect === 'mysql' || dialect === 'postgres') { | ||
it('should work with a regexp where', function() { | ||
const self = this; | ||
|
||
return this.User.create({ | ||
name: 'Foobar' | ||
}).then(() => { | ||
return self.User.find({ | ||
where: { | ||
name: { | ||
$regexp: '^Foo' | ||
} | ||
} | ||
}); | ||
}).then(user => { | ||
expect(user).to.be.ok; | ||
}); | ||
}); | ||
|
||
it('should work with a not regexp where', function() { | ||
const self = this; | ||
|
||
return this.User.create({ | ||
name: 'Foobar' | ||
}).then(() => { | ||
return self.User.find({ | ||
where: { | ||
name: { | ||
$notRegexp: '^Foo' | ||
} | ||
} | ||
}); | ||
}).then(user => { | ||
expect(user).to.not.be.ok; | ||
}); | ||
}); | ||
|
||
if (dialect === 'postgres') { | ||
it('should work with a case-insensitive regexp where', function() { | ||
const self = this; | ||
|
||
return this.User.create({ | ||
name: 'Foobar' | ||
}).then(() => { | ||
return self.User.find({ | ||
where: { | ||
name: { | ||
$iRegexp: '^foo' | ||
} | ||
} | ||
}); | ||
}).then(user => { | ||
expect(user).to.be.ok; | ||
}); | ||
}); | ||
|
||
it('should work with a case-insensitive not regexp where', function() { | ||
const self = this; | ||
|
||
return this.User.create({ | ||
name: 'Foobar' | ||
}).then(() => { | ||
return self.User.find({ | ||
where: { | ||
name: { | ||
$notIRegexp: '^foo' | ||
} | ||
} | ||
}); | ||
}).then(user => { | ||
expect(user).to.not.be.ok; | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters