// tslint:disable: variable-name import { Injectable, Inject, Logger } from '@nestjs/common'; import { NEST_KNEX_OPTIONS } from './constants'; import { NestKnexOptions } from './interfaces'; import { Knex } from 'knex'; import knex from 'knex' /** * Sample interface for NestMysql2Service * * Customize this as needed to describe the NestMysql2Service * */ interface INestKnexService { getKnex(): Knex; } @Injectable() /** * You can remove the dependencies on the Logger if you don't need it. You can also * remove the `async test()` method. * * The only thing you need to leave intact is the `@Inject(NEST_MYSQL2_OPTIONS) private _nest-mysql2Options`. * * That injected dependency gives you access to the options passed in to * NestMysql2Service. * */ export class NestKnexService implements INestKnexService { private readonly logger: Logger; private _knexConnection: any; constructor( @Inject(NEST_KNEX_OPTIONS) private _NestKnexOptions: NestKnexOptions, ) { this.logger = new Logger('NestKnexService'); this.logger.log(`Options: ${JSON.stringify(this._NestKnexOptions)}`); } getKnex(): Knex { if (!this._knexConnection) { this._knexConnection = knex(this._NestKnexOptions); } return this._knexConnection; } }