MCPcopy Create free account
hub / github.com/firebase/firebase-tools / interactiveExecuteQuery

Function interactiveExecuteQuery

src/gcp/cloudsql/interactive.ts:27–53  ·  view source on GitHub ↗
(query: string, conn: pg.PoolClient)

Source from the content-addressed store, hash-verified

25
26// Pretty query execution display such as spinner and actual returned content for `SELECT` query.
27export async function interactiveExecuteQuery(query: string, conn: pg.PoolClient) {
28 const spinner = ora("Executing query...").start();
29 try {
30 const results = await conn.query(query);
31 spinner.succeed(clc.green("Query executed successfully"));
32
33 if (Array.isArray(results.rows) && results.rows.length > 0) {
34 const table: any[] = new Table({
35 head: Object.keys(results.rows[0]).map((key) => clc.cyan(key)),
36 style: { head: [], border: [] },
37 });
38
39 for (const row of results.rows) {
40 table.push(Object.values(row) as any);
41 }
42
43 logger.info(table.toString());
44 } else {
45 // If nothing is returned and the query was select, let the user know there was no results.
46 if (query.toUpperCase().includes("SELECT")) {
47 logger.info(clc.yellow("No results returned"));
48 }
49 }
50 } catch (err) {
51 spinner.fail(clc.red(`Failed executing query: ${err}`));
52 }
53}

Callers 1

mainShellLoopFunction · 0.90

Calls 2

startMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…