Files
medusa-store/packages/medusa/src/utils/db-aware-column.ts
2023-05-17 12:13:36 +02:00

27 lines
708 B
TypeScript

import { Column, ColumnOptions, ColumnType } from "typeorm"
export function resolveDbType(pgSqlType: ColumnType): ColumnType {
return pgSqlType
}
export function resolveDbGenerationStrategy(
pgSqlType: "increment" | "uuid" | "rowid"
): "increment" | "uuid" | "rowid" {
return pgSqlType
}
export function DbAwareColumn(columnOptions: ColumnOptions): PropertyDecorator {
const pre = columnOptions.type
if (columnOptions.type) {
columnOptions.type = resolveDbType(columnOptions.type)
}
if (pre === "jsonb" && pre !== columnOptions.type) {
if ("default" in columnOptions) {
columnOptions.default = JSON.stringify(columnOptions.default)
}
}
return Column(columnOptions)
}