From 01a5cf582052efa91da59754f395fa57d98bd5f4 Mon Sep 17 00:00:00 2001 From: Konstantin Vasilev Date: Thu, 5 Oct 2017 16:38:41 +0300 Subject: [PATCH] [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 --- types/sequelize/index.d.ts | 90 ++++++++++++++++++++++++++++++ types/sequelize/sequelize-tests.ts | 18 ++++++ 2 files changed, 108 insertions(+) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 5d65397bf7..f1dc66fce5 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -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; + 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 diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index 77daabefc9..a04140e508 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -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 }>({