Skip to content

Commit

Permalink
chore: cleanup defineTable
Browse files Browse the repository at this point in the history
  • Loading branch information
subframe7536 committed Sep 30, 2024
1 parent bd21707 commit d3bc46c
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/schema/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,21 @@ export function defineTable<
const { columns, ...rest } = options
const { timeTrigger: { create, update } = {}, softDelete } = rest

const createOptions = { type: DataType.date, defaultTo: TGRC }
if (create === true) {
if (create) {
// #hack if `defaultTo === TGRC`, the column is updateAt
// @ts-expect-error assign
columns.createAt = createOptions
} else if (create) {
// #hack if `defaultTo === TGRC`, the column is updateAt
// @ts-expect-error assign
columns[create] = createOptions
columns[create === true ? 'createAt' : create] = { type: DataType.date, defaultTo: TGRC }
}
const updateOptions = { type: DataType.date, defaultTo: TGRU }
if (update === true) {
// #hack if `defaultTo === TGRU`, the column is updateAt
// @ts-expect-error assign
columns.updateAt = updateOptions
} else if (update) {

if (update) {
// #hack if `defaultTo === TGRU`, the column is updateAt
// @ts-expect-error assign
columns[update] = updateOptions
columns[update === true ? 'updateAt' : update] = { type: DataType.date, defaultTo: TGRU }
}
const softDeleteOptions = { type: DataType.int, defaultTo: 0 }
if (softDelete === true) {
// @ts-expect-error assign
columns.isDeleted = softDeleteOptions
} else if (softDelete) {

if (softDelete) {
// @ts-expect-error assign
columns[softDelete] = softDeleteOptions
columns[softDelete === true ? 'isDeleted' : softDelete] = { type: DataType.int, defaultTo: 0 }
}

return {
Expand Down

0 comments on commit d3bc46c

Please sign in to comment.