我想自动填充created_at和updated_at列。
import {BaseEntity, CreateDateColumn, PrimaryGeneratedColumn, UpdateDateColumn} from "typeorm"
import {Moment} from "moment"
import {momentTransformer} from "../helpers/transformers"
export default abstract class Model extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@CreateDateColumn({type: "timestamp", transformer: momentTransformer})
created_at: Moment
@UpdateDateColumn({type: "timestamp", transformer: momentTransformer})
updated_at: Moment
}
如何在不更改数据库架构的情况下设置用于sql查询的默认值(当前时间)。我我希望代码设置值而不是数据库。上面的代码将导致以下查询:
INSERT INTO `someTable`(`id`, `created_at`, `updated_at`) VALUES (DEFAULT, DEFAULT, DEFAULT)