Commit 7b5f7c19 authored by Abdul R. Wahid's avatar Abdul R. Wahid
Browse files

Knex Module Restructure

parent 16e6481a
......@@ -3,7 +3,7 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppGateway } from './app.gateway';
import { KnexMysqlModule } from '@database/knex/knex.module';
import { KnexModule } from '@database/knex/knex.module';
import { MongooseLoaderModule } from '@database/mongoose/mongoose.module';
import { AdminModule } from '@module/admin/admin.module';
import { AuthModule } from '@module/auth/auth.module';
......@@ -17,7 +17,7 @@ import { MailjetModule } from '@utils/mailer/mailjet/mailjet.module';
import { SocketModule } from '@utils/socket/socket.module';
import { FcmModule } from '@utils/fcm/fcm.module';
let BaseModules = [KnexMysqlModule, AdminModule, AuthModule, CloudinaryModule, MJMLModule, MailjetModule, SocketModule, FcmModule]
let BaseModules = [KnexModule, AdminModule, AuthModule, CloudinaryModule, MJMLModule, MailjetModule, SocketModule, FcmModule]
if (config.get('db_mongo.active')) {
BaseModules.push(MongooseLoaderModule)
......
export interface KnexServiceInterface {
initKnex()
getKnex()
}
import { Global, Module } from '@nestjs/common'
import { connectionFactory } from './knex.providers'
import { KnexMysqlService } from './knex.service'
import { mysqlConnectionFactory } from './knex.mysql.providers'
import { KnexMysqlService } from './knex.mysql.service'
@Global()
@Module({
providers: [KnexMysqlService, connectionFactory],
exports: [KnexMysqlService, connectionFactory],
providers: [KnexMysqlService, mysqlConnectionFactory],
exports: [KnexMysqlService, mysqlConnectionFactory],
})
export class KnexMysqlModule {}
export class KnexModule {}
import { KNEX_MYSQL } from '@common/constant'
import { KnexMysqlService } from './knex.service'
import { KnexMysqlService } from './knex.mysql.service'
export const connectionFactory = {
export const mysqlConnectionFactory = {
provide: KNEX_MYSQL,
useFactory: async knexMysqlService => {
return knexMysqlService.initKnex()
......
import { Injectable, Logger } from '@nestjs/common'
import * as knex from 'knex'
import { KnexServiceInterface } from './interface/knex.service.interface'
import config from '@config/config.loader'
interface KnexServiceInterface {
getKnex()
}
@Injectable()
export class KnexMysqlService implements KnexServiceInterface {
private readonly logger: Logger
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment