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

Function execute

src/lib/connectors/postgres/index.ts:59–74  ·  view source on GitHub ↗
(connection: Connection, databaseName: string, statement: string)

Source from the content-addressed store, hash-verified

57};
58
59const execute = async (connection: Connection, databaseName: string, statement: string): Promise<any> => {
60 connection.database = databaseName;
61 const client = await newPostgresClient(connection);
62 const { rows, rowCount } = await client.query(statement);
63 await client.end();
64
65 const executionResult: ExecutionResult = {
66 rawResult: rows,
67 affectedRows: rowCount,
68 };
69 // For those SELECT statement, we should set the affectedRows to undefined.
70 if (executionResult.rawResult.length === rowCount) {
71 executionResult.affectedRows = undefined;
72 }
73 return executionResult;
74};
75
76const getDatabases = async (connection: Connection): Promise<string[]> => {
77 const client = await newPostgresClient(connection);

Callers 1

newConnectorFunction · 0.70

Calls 1

newPostgresClientFunction · 0.85

Tested by

no test coverage detected