@joakimbugge/nest-typeorm-seeder
@joakimbugge/nest-typeorm-seeder / SeederModule
Class: SeederModule
Defined in: nest-typeorm-seeder/src/SeederModule.ts:146
Seeder module. Import at the application root to activate seeding.
When imported as a bare class (SeederModule) all configuration uses defaults — no root seeders, runOnce enabled, DataSource auto-resolved from TypeOrmModule. Use forRoot when you need to customise any of those options.
Constructors
Constructor
new SeederModule(): SeederModule;Returns
SeederModule
Methods
forFeature()
static forFeature(seeders): DynamicModule;Defined in: nest-typeorm-seeder/src/SeederModule.ts:215
Registers seeders from a feature module into the global seeder list.
Use this to co-locate seeders with the feature module they belong to rather than listing everything in the root module. The seeders are merged with any declared in forRoot and run together on bootstrap.
Requires SeederModule or SeederModule.forRoot() to be imported somewhere in the application.
Parameters
seeders
(string | SeederCtor)[]
Returns
DynamicModule
Example
// In a feature module:
SeederModule.forFeature([PostSeeder])forRoot()
static forRoot(options?): DynamicModule;Defined in: nest-typeorm-seeder/src/SeederModule.ts:164
Configures SeederModule at the application root with explicit options.
Seeding runs on onApplicationBootstrap, which fires after TypeORM has fully initialized — including schema synchronization and migrations — so no additional waiting or ordering is needed.
Omit options (or omit both seeders and run) when all seeders are registered via forFeature().
Parameters
options?
SeederModuleOptions = {}
Returns
DynamicModule
Examples
SeederModule.forRoot({ seeders: [PostSeeder] })// Gate seeding on an env var
SeederModule.forRoot({ seeders: [PostSeeder], enabled: process.env.SEED === 'true' })forRootAsync()
static forRootAsync(options): DynamicModule;Defined in: nest-typeorm-seeder/src/SeederModule.ts:186
Async variant of forRoot. Use when options depend on injected providers.
Parameters
options
Returns
DynamicModule
Example
SeederModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
seeders: [PostSeeder],
enabled: config.get('SEED') === 'true',
}),
})