import * as knex from 'knex' ; import { AuthDatabaseMigrationRunner } from '../database-migrations/AuthDatabaseMigrationRunner' ; import { AuthDbConfig } from '../interfaces/AuthDbConfig' ; export class AuthDatabaseFacade { private authDb : knex ; private authDbConfig : AuthDbConfig ; public constructor ( authDbConfig ) { this . authDbConfig = authDbConfig ; this . authDb = knex ( { client : 'mysql' , connection : { host : this . authDbConfig . host , port : this . authDbConfig . port , database : this . authDbConfig . databaseName , user : this . authDbConfig . user , password : this . authDbConfig . password , charset : 'utf8mb4' , } , pool : { min : 0 , max : this . authDbConfig . connectionLimit } , } ) ; } public getDb ( ) { return this . authDb ; } public checkAuthDatabaseTables ( ) { return new Promise < void > ( async ( resolve , reject ) : Promise < void > => { try { const migrationRunner = new AuthDatabaseMigrationRunner ( this . authDb ) ; await migrationRunner . run ( ) ; resolve ( ) ; } catch ( error ) { reject ( error ) ; } } ) ; } public async closeAuthDatabase ( ) { await this . authDb . destroy ( ) ; } }