@knestjs/core
Version:
Knestjs search to be a Nestjs ORM in which you write the models once and only once. This is done creating migrations automatically from the models that you create.
24 lines (22 loc) • 818 B
text/typescript
import {Module, Global, DynamicModule} from '@nestjs/common'
import knexConstructor from 'knex'
import {KNEX_INSTANCE, KNEST_MIGRATIONS_CONFIG} from './constants'
import {MigrationsService} from './migrations/migrations.service'
import { KnestModuleConfig } from './types'
({
providers: [MigrationsService],
exports: [MigrationsService],
})
()
export class KnestModule {
static forRoot(config: KnestModuleConfig): DynamicModule{
return {
module: KnestModule,
providers: [
{provide: KNEX_INSTANCE, useValue: knexConstructor({...config.db, migrations: {directory: config.migrations.folder}})},
{provide: KNEST_MIGRATIONS_CONFIG, useValue: config.migrations},
],
exports: [KNEX_INSTANCE]
}
}
}