Skip to content

Commit

Permalink
fix(types): add Col to where Ops (sequelize#13717)
Browse files Browse the repository at this point in the history
* fix(types): add Col to where Ops

* fix(types): tests
  • Loading branch information
madguy02 authored and aliatsis committed Jun 2, 2022
1 parent fafa228 commit 5a210ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions types/lib/model.d.ts
Expand Up @@ -146,18 +146,18 @@ export interface WhereOperators {
*/

/** Example: `[Op.eq]: 6,` becomes `= 6` */
[Op.eq]?: null | boolean | string | number | Literal | WhereOperators;
[Op.eq]?: null | boolean | string | number | Literal | WhereOperators | Col;

[Op.any]?: readonly (string | number | Literal)[] | Literal;

/** Example: `[Op.gte]: 6,` becomes `>= 6` */
[Op.gte]?: number | string | Date | Literal;
[Op.gte]?: number | string | Date | Literal | Col;

/** Example: `[Op.lt]: 10,` becomes `< 10` */
[Op.lt]?: number | string | Date | Literal;
[Op.lt]?: number | string | Date | Literal | Col;

/** Example: `[Op.lte]: 10,` becomes `<= 10` */
[Op.lte]?: number | string | Date | Literal;
[Op.lte]?: number | string | Date | Literal | Col;

/** Example: `[Op.match]: Sequelize.fn('to_tsquery', 'fat & rat')` becomes `@@ to_tsquery('fat & rat')` */
[Op.match]?: Fn;
Expand Down Expand Up @@ -225,7 +225,7 @@ export interface WhereOperators {
[Op.contained]?: readonly (string | number)[] | Rangable;

/** Example: `[Op.gt]: 6,` becomes `> 6` */
[Op.gt]?: number | string | Date | Literal;
[Op.gt]?: number | string | Date | Literal | Col;

/**
* PG only
Expand Down
11 changes: 11 additions & 0 deletions types/test/where.ts
Expand Up @@ -45,10 +45,15 @@ expectTypeOf({

expectTypeOf({
[Op.eq]: 6, // = 6
[Op.eq]: Sequelize.col('SOME_COL'), // = <column>
[Op.gt]: 6, // > 6
[Op.gt]: Sequelize.col('SOME_COL'), // > <column>
[Op.gte]: 6, // >= 6
[Op.gte]: Sequelize.col('SOME_COL'), // >= <column>
[Op.lt]: 10, // < 10
[Op.lt]: Sequelize.col('SOME_COL'), // < <column>
[Op.lte]: 10, // <= 10
[Op.lte]: Sequelize.col('SOME_COL'), // <= <column>
[Op.ne]: 20, // != 20
[Op.not]: true, // IS NOT TRUE
[Op.is]: null, // IS NULL
Expand Down Expand Up @@ -222,12 +227,18 @@ MyModel.findAll({
where: {
id: {
// casting here to check a missing operator is not accepted as field name
[Op.eq]: 6, // id = 6
[Op.eq]: Sequelize.col('SOME_COL'), // id = <column>
[Op.and]: { a: 5 }, // AND (a = 5)
[Op.or]: [{ a: 5 }, { a: 6 }], // (a = 5 OR a = 6)
[Op.gt]: 6, // id > 6
[Op.gt]: Sequelize.col('SOME_COL'), // id > <column>
[Op.gte]: 6, // id >= 6
[Op.gte]: Sequelize.col('SOME_COL'), // id >= <column>
[Op.lt]: 10, // id < 10
[Op.lt]: Sequelize.col('SOME_COL'), // id < <column>
[Op.lte]: 10, // id <= 10
[Op.lte]: Sequelize.col('SOME_COL'), // id <= <column>
[Op.ne]: 20, // id != 20
[Op.between]: [6, 10] || [new Date(), new Date()] || ["2020-01-01", "2020-12-31"], // BETWEEN 6 AND 10
[Op.notBetween]: [11, 15], // NOT BETWEEN 11 AND 15
Expand Down

0 comments on commit 5a210ab

Please sign in to comment.