-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support EventSubscriberModel with provide (#1095)
- Loading branch information
1 parent
f6f4af9
commit 05431d2
Showing
4 changed files
with
133 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 54 additions & 53 deletions
107
packages/orm/test/fixtures/base-fn-multiple-db/src/event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
import { EventSubscriberModel } from '../../../../src'; | ||
import { EntitySubscriberInterface, InsertEvent, UpdateEvent, RemoveEvent } from 'typeorm'; | ||
import { Provide } from '@midwayjs/decorator'; | ||
|
||
|
||
@EventSubscriberModel() | ||
@Provide() | ||
@EventSubscriberModel({connectionName: 'test'}) | ||
export class EverythingSubscriber implements EntitySubscriberInterface { | ||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeInsert(event: InsertEvent<any>) { | ||
console.log(`BEFORE ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeUpdate(event: UpdateEvent<any>) { | ||
console.log(`BEFORE ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeRemove(event: RemoveEvent<any>) { | ||
console.log(`BEFORE ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterInsert(event: InsertEvent<any>) { | ||
console.log(`AFTER ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterUpdate(event: UpdateEvent<any>) { | ||
console.log(`AFTER ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterRemove(event: RemoveEvent<any>) { | ||
console.log(`AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity is loaded. | ||
*/ | ||
afterLoad(entity: any) { | ||
console.log(`AFTER ENTITY LOADED: `, entity); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeInsert(event: InsertEvent<any>) { | ||
console.log(`BEFORE ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeUpdate(event: UpdateEvent<any>) { | ||
console.log(`BEFORE ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeRemove(event: RemoveEvent<any>) { | ||
console.log(`BEFORE ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterInsert(event: InsertEvent<any>) { | ||
console.log(`AFTER ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterUpdate(event: UpdateEvent<any>) { | ||
console.log(`AFTER ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterRemove(event: RemoveEvent<any>) { | ||
console.log(`AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity is loaded. | ||
*/ | ||
afterLoad(entity: any) { | ||
console.log(`AFTER ENTITY LOADED: `, entity); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,58 @@ | ||
import { EventSubscriberModel } from '../../../../src'; | ||
import { EntitySubscriberInterface, InsertEvent, UpdateEvent, RemoveEvent } from 'typeorm'; | ||
import { Provide } from '@midwayjs/decorator'; | ||
|
||
@Provide() | ||
@EventSubscriberModel() | ||
export class EverythingSubscriber implements EntitySubscriberInterface { | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeInsert(event: InsertEvent<any>) { | ||
console.log(`BEFORE ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeUpdate(event: UpdateEvent<any>) { | ||
console.log(`BEFORE ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeRemove(event: RemoveEvent<any>) { | ||
console.log(`BEFORE ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterInsert(event: InsertEvent<any>) { | ||
console.log(`AFTER ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterUpdate(event: UpdateEvent<any>) { | ||
console.log(`AFTER ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterRemove(event: RemoveEvent<any>) { | ||
console.log(`AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity is loaded. | ||
*/ | ||
afterLoad(entity: any) { | ||
console.log(`AFTER ENTITY LOADED: `, entity); | ||
} | ||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeInsert(event: InsertEvent<any>) { | ||
console.log(`BEFORE ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeUpdate(event: UpdateEvent<any>) { | ||
console.log(`BEFORE ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called before entity insertion. | ||
*/ | ||
beforeRemove(event: RemoveEvent<any>) { | ||
console.log(`BEFORE ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterInsert(event: InsertEvent<any>) { | ||
console.log(`AFTER ENTITY INSERTED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterUpdate(event: UpdateEvent<any>) { | ||
console.log(`AFTER ENTITY UPDATED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity insertion. | ||
*/ | ||
afterRemove(event: RemoveEvent<any>) { | ||
console.log(`AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity); | ||
} | ||
|
||
/** | ||
* Called after entity is loaded. | ||
*/ | ||
afterLoad(entity: any) { | ||
console.log(`AFTER ENTITY LOADED: `, entity); | ||
} | ||
|
||
} |