@ifjkt/typeorm-revisions
v1.0.3
Published
Revisions History for [TypeORM](https://typeorm.io) Entities
Downloads
349
Maintainers
Readme
@ifjkt/typeorm-revisions
Description
Provides a Revision History Subscriber for TypeORM Entities
Tested: MySQL 8, MariaDB and Postgres
Installation
$ npm i --save typeorm @ifjkt/typeorm-revisions
Quick Start
1. Create your own Entity
@Entity()
class MyModel extends BaseEntity {
@PrimaryGeneratedColumn()
public id!: number;
@Column()
public name!: string;
@Column()
public email!: string;
}
2. Create an Entity for your Audit table
@Entity()
class MyModelHistory extends MyModel implements HistoryEntityInterface {
@Column({
name: 'record_id',
type: 'int',
})
recordId: number;
@Column({
name: 'revision_timestamp',
})
revisionTime: Date;
@Column({
name: 'revision_type',
})
revisionType: RevisionActionType;
}
3. Annotate your Audit table with the @AuditTable decorator and specify your audit fields
@Entity()
@AuditTable({
recordIdProperty: 'recordId',
revisionTypeProperty: 'revisionType',
revisionTimestampProperty: 'revisionTime',
})
class MyModelHistory extends MyModel implements HistoryEntityInterface {
@Column({
name: 'record_id',
type: 'int',
})
recordId: number;
@Column({
name: 'revision_timestamp',
})
revisionTime: Date;
@Column({
name: 'revision_type',
})
revisionType: RevisionActionType;
}
4. Create an Entity Subscriber for your entity to process Audit events
@EventSubscriber()
class MyModelHistorySubscriber extends HistorySubscriber<MyModel, MyModelHistory> {
public entity = MyModel;
public historyEntity = MyModelHistory;
}
License
Forked from https://github.com/ephillipe/typeorm-revisions