Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

joakimbugge/nest-typeorm-seeder

Repository files navigation




Seed your Nest with TypeORM application decoratively



Introduction

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.

Installation

npm install @airhead/nest-typeorm-seeder

Documentation

Coming soon! In the meantime, submit an issue.

Quick start

Module

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 {
}

Standalone

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],
});

Grow icons created by Freepik - Flaticon