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

feat: add an option to control the behavior of null in JSON attributes #16861

Merged
merged 4 commits into from Dec 12, 2023

Conversation

ephys
Copy link
Member

@ephys ephys commented Dec 11, 2023

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

Closes sequelize/website#578

This PR adds the ability to chose how the JavaScript null primitive is mapped in a JSON column, by configuring the new nullJsonStringification global option.

  • In json mode (default, v7 behavior): The value is stringified as a JSON value
  • In sql mode (v6 behavior): The value is stringified as the SQL NULL
  • In explicit mode: The value is rejected. The user must use SQL_NULL or JSON_NULL explicitly.

This only impacts the top level value of JSON columns, as that is the only place where an ambiguity is present.

The new SQL_NULL and JSON_NULL values can be used to compare against the attribute too, as an alternative to having to use Op.is and Op.eq explicitly.

@ephys ephys changed the title feat: add options controlling the behavior of null in JSON attributes feat: add option controlling the behavior of null in JSON attributes Dec 11, 2023
@ephys ephys changed the title feat: add option controlling the behavior of null in JSON attributes feat: add an option to control the behavior of null in JSON attributes Dec 11, 2023
WikiRik
WikiRik previously approved these changes Dec 11, 2023
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, assuming tests pass

packages/core/src/dialects/abstract/data-types.ts Outdated Show resolved Hide resolved
@ephys ephys added this pull request to the merge queue Dec 12, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 12, 2023
@ephys ephys added this pull request to the merge queue Dec 12, 2023
Merged via the queue into main with commit aff8f64 Dec 12, 2023
51 checks passed
@ephys ephys deleted the ephys/json-null-option branch December 12, 2023 09:41
papandreou added a commit to papandreou/sequelize that referenced this pull request Dec 19, 2023
v7.0.0-alpha.34

* tag 'v7.0.0-alpha.34': (94 commits)
  v7.0.0-alpha.34
  feat!: rename association classes to prevent conflicts with decorators (sequelize#16513)
  meta: add unit test for ARRAY(UUID) (sequelize#16841)
  fix: correct link to data types docs (sequelize#16674)
  feat: add support for `sql` tag & functions in `sequelize.query` (sequelize#16863)
  feat: add an option to control the behavior of `null` in JSON attributes (sequelize#16861)
  meta: update dependency nx to v17.2.1 (sequelize#16862)
  meta: update sequelize AUTHORS (sequelize#16856)
  meta: lock file maintenance (sequelize#16859)
  meta: update dependency typedoc-plugin-mdn-links to v3.1.7 (sequelize#16857)
  meta: update dependency markdownlint-cli to v0.38.0 (sequelize#16854)
  meta: update dependency nx to v17.2.0 (sequelize#16853)
  meta: update dependency ts-node to v10.9.2 (sequelize#16852)
  meta: update dependency @types/snowflake-sdk to v1.6.20 (sequelize#16850)
  meta: update dependency @types/snowflake-sdk to v1.6.19 (sequelize#16849)
  meta: update actions/stale action to v9 (sequelize#16847)
  meta: update dependency snowflake-sdk to v1.9.2 (sequelize#16846)
  meta: update dependency @types/node to v20.10.4 (sequelize#16845)
  meta: add tests to verify that showConstraints filters on schema (sequelize#16785)
  meta: update sequelize AUTHORS (sequelize#16781)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To document
2 participants