[sequelize] add operatorsAliases option (#20284)

* [sequelize] add operatorsAliases option

* fix. right symbols usage

* add arbitrary key for aliases options

* fix arbitrary key for strict usage
This commit is contained in:
Konstantin Vasilev
2017-10-05 16:38:41 +03:00
committed by Masahiro Wakame
parent b951e88ed5
commit 01a5cf5820
2 changed files with 108 additions and 0 deletions

View File

@@ -5272,6 +5272,88 @@ declare namespace sequelize {
}
/**
* Operator symbols to be used when querying data
*/
interface Operators {
eq: symbol;
ne: symbol;
gte: symbol;
gt: symbol;
lte: symbol;
lt: symbol;
not: symbol;
is: symbol;
in: symbol;
notIn: symbol;
like: symbol;
notLike: symbol;
iLike: symbol;
notILike: symbol;
regexp: symbol;
notRegexp: symbol;
iRegexp: symbol;
notIRegexp: symbol;
between: symbol;
notBetween: symbol;
overlap: symbol;
contains: symbol;
contained: symbol;
adjacent: symbol;
strictLeft: symbol;
strictRight: symbol;
noExtendRight: symbol;
noExtendLeft: symbol;
and: symbol;
or: symbol;
any: symbol;
all: symbol;
values: symbol;
col: symbol;
placeholder: symbol;
join: symbol;
raw: symbol; //deprecated remove by v5.0
}
type OperatorsAliases = Partial<{
[key: string]: symbol;
$eq: symbol;
$ne: symbol;
$gte: symbol;
$gt: symbol;
$lte: symbol;
$lt: symbol;
$not: symbol;
$in: symbol;
$notIn: symbol;
$is: symbol;
$like: symbol;
$notLike: symbol;
$iLike: symbol;
$notILike: symbol;
$regexp: symbol;
$notRegexp: symbol;
$iRegexp: symbol;
$notIRegexp: symbol;
$between: symbol;
$notBetween: symbol;
$overlap: symbol;
$contains: symbol;
$contained: symbol;
$adjacent: symbol;
$strictLeft: symbol;
$strictRight: symbol;
$noExtendRight: symbol;
$noExtendLeft: symbol;
$and: symbol;
$or: symbol;
$any: symbol;
$all: symbol;
$values: symbol;
$col: symbol;
$raw: symbol; //deprecated remove by v5.0
}>
/**
* Options for the constructor of Sequelize main class
*/
@@ -5447,6 +5529,12 @@ declare namespace sequelize {
* Defaults to false
*/
benchmark?: boolean;
/**
* String based operator alias, default value is true which will enable all operators alias.
* Pass object to limit set of aliased operators or false to disable completely.
*/
operatorsAliases?: boolean | OperatorsAliases;
}
/**
@@ -5500,6 +5588,8 @@ declare namespace sequelize {
*/
Instance: Instance<any>;
Op: Operators;
/**
* Creates a object representing a database function. This can be used in search queries, both in where and
* order parts, and as default values in column definitions. If you want to refer to columns in your

View File

@@ -1207,6 +1207,17 @@ new Sequelize( {
typeValidation: true
} );
new Sequelize({
operatorsAliases: false,
});
new Sequelize({
operatorsAliases: {
$and: Sequelize.Op.and,
customAlias: Sequelize.Op.or,
},
});
s.model( 'Project' );
s.models['Project'];
s.define( 'Project', {
@@ -1469,6 +1480,13 @@ Chair.findAll({
},
});
Chair.findAll({
where: {
color: 'blue',
legs: { [Sequelize.Op.in]: [3, 4] },
},
});
// If you want to use a property that isn't explicitly on the model's Attributes
// use the find-function's generic type parameter.
Chair.findAll<{ customProperty: number }>({