Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add Sequelize operator aliases (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jan 26, 2018
1 parent df312b0 commit 2520532
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions generators/connection/templates/sequelize-mssql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
const url = require('url');
const Sequelize = require('sequelize');
const { Op } = Sequelize;
const operatorsAliases = {
$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
};

module.exports = function (app) {
const connectionString = app.get('mssql');
Expand All @@ -11,6 +48,7 @@ module.exports = function (app) {
dialect: 'mssql',
host: hostname,
logging: false,
operatorsAliases,
define: {
freezeTableName: true
},
Expand Down
38 changes: 38 additions & 0 deletions generators/connection/templates/sequelize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
const Sequelize = require('sequelize');
const { Op } = Sequelize;
const operatorsAliases = {
$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
};

module.exports = function (app) {
const connectionString = app.get('<%= database %>');
const sequelize = new Sequelize(connectionString, {
dialect: '<%= database %>',
logging: false,
operatorsAliases,
define: {
freezeTableName: true
}
Expand Down

0 comments on commit 2520532

Please sign in to comment.