@joakimbugge/typeorm-seeder / SeedFactory
Type Alias: SeedFactory<T, TEntity>
ts
type SeedFactory<T, TEntity> = (context, self, index) => T | Promise<T>;Defined in: seed/registry.ts:52
Factory callback passed to @Seed. Receives the seed context, the partially built entity, and a zero-based index that counts up across a createMany/saveMany batch.
Properties are seeded sequentially in declaration order, so any property declared above the current one is already set on self and can be read to derive the current value.
Annotate self with the entity class to get full type inference — TypeScript infers TEntity from the annotation, so no cast is needed:
Type Parameters
T
T = unknown
TEntity
TEntity = any
Parameters
context
self
TEntity
index
number
Returns
T | Promise<T>
Example
ts
@Seed((_, __, i) => `user-${i}@example.com`)
email!: string
@Seed(() => faker.date.past())
beginDate!: Date
@Seed((_, self: MyEntity) => faker.date.future({ refDate: self.beginDate }))
endDate!: Date