UNPKG

create-chuntianxiaozhu

Version:

春天小猪模板工具

33 lines (26 loc) 579 B
import { BeforeInsert, BeforeUpdate, Column, PrimaryGeneratedColumn, } from 'typeorm'; export class BaseEntity<T> { @PrimaryGeneratedColumn() id: number; @Column({ name: 'create_date', type: 'bigint' }) createDate: number; @Column({ name: 'update_date', type: 'bigint' }) updateDate: number; @BeforeInsert() beforeInsert() { this.createDate = Date.now(); this.updateDate = Date.now(); } @BeforeUpdate() beforeUpdate() { this.updateDate = Date.now(); } constructor(partial: Partial<T>) { Object.assign(this, partial); } }