KnexModule.forRootAsync({
useFactory: () => ({
config: {
client: 'sqlite3',
useNullAsDefault: true,
connection: ':memory:',
},
}),
}),
import { Module, OnModuleInit } from '@nestjs/common';
import { KnexModule } from '@nestjsplus/knex';
import { MigrationConfig } from '@nestjsplus/knex/dist/interfaces/migration-config.interface';
import * as path from 'path';
@Module({
imports: [
KnexModule.forRootAsync({
useFactory: (): MigrationConfig => ({
config: {
client: 'sqlite3',
useNullAsDefault: true,
connection: ':memory:',
},
migrations: {
directory: path.resolve(__dirname, 'migrations'),
},
}),
}),
],
})
export class DatabaseModule implements OnModuleInit {
constructor(private readonly knexService: KnexService) {}
async onModuleInit() {
await this.knexService.client.migrate.latest();
}
}