feat(utils,types): DML Index can generate where SQL from a query builder (#7849)

what:

- introduces a simple query builder
- uses the query builder to tranform an object in where to SQL when applying indexes

```
Examples:
  { where: { column: null } } -> column IS NULL
  { where: { column: { $ne: null } } } -> column IS NOT NULL
  { where: { boolean_column: true } } -> boolean_column IS TRUE
  { where: { column: "value", another_column: { $ne: 30 } } } -> column = "value" AND another_column != 30
```

```
const user = model
  .define("user", {
    email: model.text(),
    account: model.text(),
    organization: model.text(),
  })
  .indexes([
    {
      on: ["organization", "account"],
      where: { email: { $ne: null } },
    },
    {
      name: "IDX-email-account-special",
      on: ["organization", "account"],
      where: {
        email: { $ne: null },
        account: null,
      },
    },
```

RESOLVES CORE-2392
This commit is contained in:
Riqwan Thamir
2024-06-27 10:24:34 +00:00
committed by GitHub
parent b1df20b0dc
commit 3f16b011fa
8 changed files with 215 additions and 45 deletions
+10 -9
View File
@@ -2,6 +2,7 @@ export * from "./alter-columns-helper"
export * from "./array-difference"
export * from "./array-intersection"
export * from "./build-query"
export * from "./build-regexp-if-valid"
export * from "./camel-to-snake-case"
export * from "./container"
export * from "./convert-item-response-to-update-request"
@@ -11,29 +12,36 @@ export * from "./deduplicate"
export * from "./deep-copy"
export * from "./deep-equal-obj"
export * from "./deep-flat-map"
export * from "./define-config"
export * from "./errors"
export * from "./file-system"
export * from "./generate-entity-id"
export * from "./generate-linkable-keys-map"
export * from "./get-caller-file-path"
export * from "./get-config-file"
export * from "./get-duplicates"
export * from "./get-iso-string-from-date"
export * from "./get-selects-and-relations-from-object-array"
export * from "./get-set-difference"
export * from "./graceful-shutdown-server"
export * from "./group-by"
export * from "./handle-postgres-database-error"
export * from "./is-big-number"
export * from "./is-boolean"
export * from "./is-date"
export * from "./is-defined"
export * from "./is-email"
export * from "./is-object"
export * from "./is-present"
export * from "./is-string"
export * from "./load-env"
export * from "./lower-case-first"
export * from "./map-object-to"
export * from "./medusa-container"
export * from "./object-from-string-path"
export * from "./object-to-string-path"
export * from "./optional-numeric-serializer"
export * from "./parse-cors-origins"
export * from "./partition-array"
export * from "./pick-deep"
export * from "./pick-value-from-object"
@@ -51,18 +59,11 @@ export * from "./simple-hash"
export * from "./string-to-select-relation-object"
export * from "./stringify-circular"
export * from "./to-camel-case"
export * from "./to-handle"
export * from "./to-kebab-case"
export * from "./to-pascal-case"
export * from "./transaction"
export * from "./trim-zeros"
export * from "./upper-case-first"
export * from "./wrap-handler"
export * from "./to-handle"
export * from "./validate-handle"
export * from "./parse-cors-origins"
export * from "./build-regexp-if-valid"
export * from "./load-env"
export * from "./define-config"
export * from "./file-system"
export * from "./graceful-shutdown-server"
export * from "./get-caller-file-path"
export * from "./wrap-handler"
@@ -0,0 +1,3 @@
export function isBoolean(val: any): val is boolean {
return val != null && typeof val === "boolean"
}