|
|
|
@ -2,11 +2,14 @@ import SqlClientFactory from '../../db/sql-client/lib/SqlClientFactory';
|
|
|
|
|
import { XKnex } from '../../db/sql-data-mapper'; |
|
|
|
|
import { NcConfig } from '../../../interface/config'; |
|
|
|
|
import fs from 'fs'; |
|
|
|
|
import { promisify } from 'util'; |
|
|
|
|
import { Knex } from 'knex'; |
|
|
|
|
|
|
|
|
|
import NcMetaIO from '../../meta/NcMetaIO'; |
|
|
|
|
import { defaultConnectionConfig } from '../NcConfigFactory'; |
|
|
|
|
|
|
|
|
|
const readFileAsync = promisify(fs.readFile); |
|
|
|
|
|
|
|
|
|
export default class NcConnectionMgr { |
|
|
|
|
private static connectionRefs: { |
|
|
|
|
[projectId: string]: { |
|
|
|
@ -43,7 +46,7 @@ export default class NcConnectionMgr {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static get({ |
|
|
|
|
public static async get({ |
|
|
|
|
dbAlias = 'db', |
|
|
|
|
env = '_noco', |
|
|
|
|
config, |
|
|
|
@ -53,7 +56,7 @@ export default class NcConnectionMgr {
|
|
|
|
|
env: string; |
|
|
|
|
config: NcConfig; |
|
|
|
|
projectId: string; |
|
|
|
|
}): XKnex { |
|
|
|
|
}): Promise<XKnex> { |
|
|
|
|
if (this.connectionRefs?.[projectId]?.[env]?.[dbAlias]) { |
|
|
|
|
return this.connectionRefs?.[projectId]?.[env]?.[dbAlias]; |
|
|
|
|
} |
|
|
|
@ -73,25 +76,25 @@ export default class NcConnectionMgr {
|
|
|
|
|
connectionConfig.connection.ssl.caFilePath && |
|
|
|
|
!connectionConfig.connection.ssl.ca |
|
|
|
|
) { |
|
|
|
|
connectionConfig.connection.ssl.ca = fs |
|
|
|
|
.readFileSync(connectionConfig.connection.ssl.caFilePath) |
|
|
|
|
.toString(); |
|
|
|
|
connectionConfig.connection.ssl.ca = await readFileAsync( |
|
|
|
|
connectionConfig.connection.ssl.caFilePath |
|
|
|
|
).toString(); |
|
|
|
|
} |
|
|
|
|
if ( |
|
|
|
|
connectionConfig.connection.ssl.keyFilePath && |
|
|
|
|
!connectionConfig.connection.ssl.key |
|
|
|
|
) { |
|
|
|
|
connectionConfig.connection.ssl.key = fs |
|
|
|
|
.readFileSync(connectionConfig.connection.ssl.keyFilePath) |
|
|
|
|
.toString(); |
|
|
|
|
connectionConfig.connection.ssl.key = await readFileAsync( |
|
|
|
|
connectionConfig.connection.ssl.keyFilePath |
|
|
|
|
).toString(); |
|
|
|
|
} |
|
|
|
|
if ( |
|
|
|
|
connectionConfig.connection.ssl.certFilePath && |
|
|
|
|
!connectionConfig.connection.ssl.cert |
|
|
|
|
) { |
|
|
|
|
connectionConfig.connection.ssl.cert = fs |
|
|
|
|
.readFileSync(connectionConfig.connection.ssl.certFilePath) |
|
|
|
|
.toString(); |
|
|
|
|
connectionConfig.connection.ssl.cert = await readFileAsync( |
|
|
|
|
connectionConfig.connection.ssl.certFilePath |
|
|
|
|
).toString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|