在不使用Typescript修饰符@UpdateDateColumn
的情况下,在TypeORM中添加updatedDate
列,可以通过以下步骤实现:
updatedDate
的属性,用于存储更新日期。该属性需要使用@Column
修饰符来指定数据库中的列属性。import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class YourEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
createdDate: Date;
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
updatedDate: Date;
}
在上述代码中,@Column
修饰符用于定义数据库表中的列属性。type
属性指定了列的数据类型为timestamp
,default
属性指定了默认值为当前时间戳。onUpdate
属性指定了在更新实体时自动更新为当前时间戳。
updatedDate
列。当更新实体时,该列的值会自动更新为当前时间戳。这是一种在TypeORM中添加updatedDate
列的方法,它可以在不使用Typescript修饰符@UpdateDateColumn
的情况下实现。请注意,这只是一种实现方式,具体的实现方法可能因项目需求和配置而有所不同。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云