27 lines
708 B
TypeScript
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)
|
|
}
|