Thanks to visit codestin.com
Credit goes to github.com

Skip to content

null type is not allowed in where clauses but is correctly interpreted by Sequelize application codeΒ #18118

@jakeisnt

Description

@jakeisnt

Hi! πŸ‘‹ Thank you for supporting this package.

I've noticed a difference between how null and undefined values are treated in where clauses in Sequelize, but have noticed that null values are not supported in cases where it is necessary to generate Postgres code like IS NULL or IS NOT NULL in SELECT statements.

Sequelize application code properly supports null in these cases, but the typings do not. I'm currently use this patch locally and would love to contribute it upstream:

diff --git a/node_modules/sequelize/types/model.d.ts b/node_modules/sequelize/types/model.d.ts
index 7ab36db..ca99807 100644
--- a/node_modules/sequelize/types/model.d.ts
+++ b/node_modules/sequelize/types/model.d.ts
@@ -200,7 +200,7 @@ export type ColumnReference = Col | { [Op.col]: string };
  * Internal type - prone to changes. Do not export.
  * @private
  */
-type WhereSerializableValue = boolean | string | number | Buffer | Date;
+type WhereSerializableValue = boolean | string | number | Buffer | Date | null;
 
 /**
  * Internal type - prone to changes. Do not export.
@@ -598,8 +598,10 @@ export type WhereAttributeHash<TAttributes = any> = {
 
 /**
  * Types that can be compared to an attribute in a WHERE context.
+ * undefined is allowed so optional condition values omit the key at runtime.
  */
 export type WhereAttributeHashValue<AttributeType> =
+  | undefined
   | AllowNotOrAndRecursive<
     // if the right-hand side is an array, it will be equal to Op.in
     // otherwise it will be equal to Op.eq

Let me know if this can be contributed upstream!

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions