MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / getDatabases

Function getDatabases

src/lib/connectors/postgres/index.ts:76–93  ·  view source on GitHub ↗
(connection: Connection)

Source from the content-addressed store, hash-verified

74};
75
76const getDatabases = async (connection: Connection): Promise<string[]> => {
77 const client = await newPostgresClient(connection);
78 if (connection.database) {
79 await client.end();
80 return [connection.database];
81 }
82
83 const { rows } = await client.query(`SELECT datname FROM pg_database;`);
84 await client.end();
85 const databaseList = [];
86 for (const row of rows) {
87 if (row["datname"]) {
88 databaseList.push(row["datname"]);
89 }
90 }
91 await client.end();
92 return databaseList;
93};
94
95const getTableSchema = async (connection: Connection, databaseName: string): Promise<Schema[]> => {
96 connection.database = databaseName;

Callers 1

newConnectorFunction · 0.70

Calls 1

newPostgresClientFunction · 0.85

Tested by

no test coverage detected