Seed your Nest with TypeORM application decoratively
Seed your Nest + TypeORM application database using decorators. Add the module to your application for automatic seeding on startup or use the standalone version if being more hands-on is your thing.
To learn about seeding with TypeORM, check out @airhead/typeorm-seeder.
This tool is in early stages and in active development, breaking changes may occur between minor versions.
npm install @airhead/nest-typeorm-seeder
Coming soon! In the meantime, submit an issue.
Import TypeOrmSeederModule
alongside TypeOrmModule
and provide the seeders.
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeOrmSeederModule } from '@airhead/nest-typeorm-seeder';
@Module({
imports: [
TypeOrmModule.forRoot({ ... }),
TypeOrmSeederModule.forRoot({
seeders: [UserSeeder, PostSeeder, CategorySeeder],
}),
],
})
export class AppModule {
}
Handy to manually trigger seeding. Use TypeOrmSeeder
instead of TypeOrmSeederModule
. Import TypeOrmModule
just
like in your normal Nest application and provide the seeders.
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeOrmSeeder } from '@airhead/nest-typeorm-seeder';
TypeOrmSeeder.run({
imports: [TypeOrmModule.forRoot({ ... })],
seeders: [UserSeeder, PostSeeder, CategorySeeder],
});