初始版本,目前线上可用
This commit is contained in:
34
backEnd/src/abstrClass/BaseEntity.ts
Normal file
34
backEnd/src/abstrClass/BaseEntity.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import dayjs from "dayjs";
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryGeneratedColumn({ type: "int", name: "id" })
|
||||
id: number;
|
||||
@Column({
|
||||
type: "datetime",
|
||||
comment: "创建时间",
|
||||
default: () => "CURRENT_TIMESTAMP",
|
||||
transformer: {
|
||||
to(value: Date) {
|
||||
return value;
|
||||
},
|
||||
from(value) {
|
||||
return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
|
||||
},
|
||||
},
|
||||
})
|
||||
createDate: Date;
|
||||
@Column({
|
||||
type: "datetime",
|
||||
comment: "更新时间",
|
||||
default: () => "CURRENT_TIMESTAMP",
|
||||
transformer: {
|
||||
to(value: Date) {
|
||||
return value;
|
||||
},
|
||||
from(value) {
|
||||
return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
|
||||
},
|
||||
},
|
||||
})
|
||||
updateDate: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user