Skip to main content

Function: BeforeInsert()

BeforeInsert(): MethodDecorator

Defined in: src/decorators/LifecycleHooks.ts:37

Method decorator marking a method to run immediately before this entity is inserted into the database.

Can be synchronous or asynchronous. Any uncaught error aborts the insert operation.

Returns​

MethodDecorator

Usecase​

Input normalization, password hashing, pre-insert calculations, or domain validation.

Example​

@BeforeInsert()
normalizeData() {
this.email = this.email.trim().toLowerCase();
}