chore: export DML builders + fix default undefined values in SQL (#7776)
* chore: export dml builders through utils * chore: fix undefined sql error * chore: upgrade to ts 5 * chore: use isDefined
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
export * as DALUtils from "./dal"
|
||||
export * as DecoratorUtils from "./decorators"
|
||||
export * as DefaultsUtils from "./defaults"
|
||||
export * as DMLUtils from "./dml"
|
||||
export * as EventBusUtils from "./event-bus"
|
||||
export * as FeatureFlagUtils from "./feature-flags"
|
||||
export * as FulfillmentUtils from "./fulfillment"
|
||||
export * as InventoryUtils from "./inventory"
|
||||
export * as LinkUtils from "./link"
|
||||
export * as ModulesSdkUtils from "./modules-sdk"
|
||||
export * as OrchestrationUtils from "./orchestration"
|
||||
export * as OrderUtils from "./order"
|
||||
@@ -12,6 +16,3 @@ export * as PromotionUtils from "./promotion"
|
||||
export * as SearchUtils from "./search"
|
||||
export * as ShippingProfileUtils from "./shipping"
|
||||
export * as UserUtils from "./user"
|
||||
export * as InventoryUtils from "./inventory"
|
||||
export * as LinkUtils from "./link"
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
import {
|
||||
Enum,
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OneToMany,
|
||||
Property,
|
||||
OneToOne,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
Filter,
|
||||
PrimaryKey,
|
||||
BeforeCreate,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DmlEntity } from "../entity"
|
||||
import { DALUtils } from "../../bundles"
|
||||
import {
|
||||
pluralize,
|
||||
camelToSnakeCase,
|
||||
createPsqlIndexStatementHelper,
|
||||
toCamelCase,
|
||||
generateEntityId,
|
||||
isDefined,
|
||||
pluralize,
|
||||
toCamelCase,
|
||||
} from "../../common"
|
||||
import { upperCaseFirst } from "../../common/upper-case-first"
|
||||
import { DmlEntity } from "../entity"
|
||||
import { HasMany } from "../relations/has-many"
|
||||
import { HasOne } from "../relations/has-one"
|
||||
import { ManyToMany as DmlManyToMany } from "../relations/many-to-many"
|
||||
import type {
|
||||
Infer,
|
||||
PropertyType,
|
||||
EntityCascades,
|
||||
EntityConstructor,
|
||||
Infer,
|
||||
KnownDataTypes,
|
||||
PropertyMetadata,
|
||||
RelationshipType,
|
||||
EntityConstructor,
|
||||
PropertyType,
|
||||
RelationshipMetadata,
|
||||
RelationshipType,
|
||||
} from "../types"
|
||||
import { DALUtils } from "../../bundles"
|
||||
import { HasOne } from "../relations/has-one"
|
||||
import { HasMany } from "../relations/has-many"
|
||||
import { ManyToMany as DmlManyToMany } from "../relations/many-to-many"
|
||||
|
||||
/**
|
||||
* DML entity data types to PostgreSQL data types via
|
||||
@@ -169,7 +170,12 @@ export function createMikrORMEntity() {
|
||||
Enum({
|
||||
items: () => field.dataType.options!.choices,
|
||||
nullable: field.nullable,
|
||||
default: field.defaultValue,
|
||||
/**
|
||||
* MikroORM does not ignore undefined values for default when generating
|
||||
* the database schema SQL. Conditionally add it here to prevent undefined
|
||||
* from being set as default value in SQL.
|
||||
*/
|
||||
...(isDefined(field.defaultValue) && { default: field.defaultValue }),
|
||||
})(MikroORMEntity.prototype, field.fieldName)
|
||||
return
|
||||
}
|
||||
@@ -217,7 +223,12 @@ export function createMikrORMEntity() {
|
||||
columnType,
|
||||
type: propertyType,
|
||||
nullable: field.nullable,
|
||||
default: field.defaultValue,
|
||||
/**
|
||||
* MikroORM does not ignore undefined values for default when generating
|
||||
* the database schema SQL. Conditionally add it here to prevent undefined
|
||||
* from being set as default value in SQL.
|
||||
*/
|
||||
...(isDefined(field.defaultValue) && { default: field.defaultValue }),
|
||||
})(MikroORMEntity.prototype, field.fieldName)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./entity-builder"
|
||||
export * from "./helpers/create-mikro-orm-entity"
|
||||
@@ -1,15 +1,20 @@
|
||||
export * from "./api-key"
|
||||
export * from "./auth"
|
||||
export * from "./bundles"
|
||||
export * from "./common"
|
||||
export * from "./dal"
|
||||
export * from "./decorators"
|
||||
export * from "./defaults"
|
||||
export * from "./dml"
|
||||
export * from "./event-bus"
|
||||
export * from "./exceptions"
|
||||
export * from "./feature-flags"
|
||||
export * from "./file"
|
||||
export * from "./fulfillment"
|
||||
export * from "./inventory"
|
||||
export * from "./link"
|
||||
export * from "./modules-sdk"
|
||||
export * from "./notification"
|
||||
export * from "./orchestration"
|
||||
export * from "./order"
|
||||
export * from "./payment"
|
||||
@@ -21,9 +26,5 @@ export * from "./shipping"
|
||||
export * from "./totals"
|
||||
export * from "./totals/big-number"
|
||||
export * from "./user"
|
||||
export * from "./api-key"
|
||||
export * from "./link"
|
||||
export * from "./file"
|
||||
export * from "./notification"
|
||||
|
||||
export const MedusaModuleType = Symbol.for("MedusaModule")
|
||||
|
||||
Reference in New Issue
Block a user