(connection: IConnection, dbname?: string)
| 70 | } |
| 71 | |
| 72 | public static async createConnection(connection: IConnection, dbname?: string): Promise<PgClient> { |
| 73 | const connectionOptions: any = Object.assign({}, connection); |
| 74 | connectionOptions.database = dbname ? dbname : connection.database; |
| 75 | if (connectionOptions.certPath && fs.existsSync(connectionOptions.certPath)) { |
| 76 | connectionOptions.ssl = { |
| 77 | ca: fs.readFileSync(connectionOptions.certPath).toString(), |
| 78 | rejectUnauthorized: false, |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (connectionOptions.ssl === true) { |
| 83 | connectionOptions.ssl = {rejectUnauthorized: false}; |
| 84 | } |
| 85 | |
| 86 | let client = new PgClient(connectionOptions); |
| 87 | await client.connect(); |
| 88 | const versionRes = await client.query(`SELECT current_setting('server_version_num') as ver_num;`); |
| 89 | /* |
| 90 | return res.rows.map<ColumnNode>(column => { |
| 91 | return new ColumnNode(this.connection, this.table, column); |
| 92 | }); |
| 93 | */ |
| 94 | let versionNumber = parseInt(versionRes.rows[0].ver_num); |
| 95 | client.pg_version = versionNumber; |
| 96 | return client; |
| 97 | } |
| 98 | |
| 99 | private static getDurationText(milliseconds: number): string { |
| 100 | let sec = milliseconds / 1000.0; |
no outgoing calls
no test coverage detected