MCPcopy Create free account
hub / github.com/Borvik/vscode-postgres / createConnection

Method createConnection

src/common/database.ts:72–97  ·  view source on GitHub ↗
(connection: IConnection, dbname?: string)

Source from the content-addressed store, hash-verified

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;

Callers 10

setDatabaseMethod · 0.80
runMethod · 0.80
runMethod · 0.80
getDefaultConnectionMethod · 0.80
runQueryMethod · 0.80
getChildrenMethod · 0.80
getChildrenMethod · 0.80
getChildrenMethod · 0.80
getChildrenMethod · 0.80
getChildrenMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected