Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add Col to where Ops #13717

Merged
merged 2 commits into from Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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