Skip to main content

@AfterInsert

function AfterInsert(): PropertyDecorator;

A PropertyDecorator factory applied to a method — registers that method under the 'after-insert' bucket on the entity's EntityMetadata.eventListeners:

class Customer {
@Column()
declare givenName: string;

@AfterInsert()
logCreated(): void {
console.log(`Customer ${this.givenName} created`);
}
}

Throws You can define a Column for only string properties if applied to a symbol-keyed property, and Property must be a function if the decorated property isn't a function.

Not currently invoked automatically

As of this version of @sqb/connect, nothing in Repository or the create/update/delete command implementations reads eventListeners back or calls the registered functions — attaching @AfterInsert() to a method registers it as metadata only; it does not, by itself, make that method run after repo.create(...) inserts a row. See Lifecycle Hooks for the full explanation and workarounds.

See Lifecycle Hooks for the full guide and the sibling decorators: @BeforeInsert, @BeforeUpdate, @AfterUpdate, @BeforeDestroy, @AfterDestroy.