MCPcopy
hub / github.com/kriasoft/graphql-starter-kit / interactive

Function interactive

db/cli.ts:292–313  ·  view source on GitHub ↗

* Launches an interactive terminal with Knex.js.

(options?: {
  env?: string;
  schema?: string;
  args?: string[];
})

Source from the content-addressed store, hash-verified

290 * Launches an interactive terminal with Knex.js.
291 */
292async function interactive(options?: {
293 env?: string;
294 schema?: string;
295 args?: string[];
296}) {
297 const db = getDatabase(options);
298 Object.defineProperty(globalThis, "db", { value: db });
299
300 // Fetch the current database version
301 const [x] = await db.select(
302 db.raw("version(), current_database() as database"),
303 );
304
305 console.log(`Connected to ${chalk.greenBright(x.database)}. Usage example:`);
306 console.log(``);
307 console.log(` await db.table("user").first()`);
308 console.log(` await db.select(db.raw("version()"))`);
309 console.log(` await db.fn.newUserId()`);
310 console.log(``);
311 console.log(`Type ${chalk.greenBright(".exit")} to exit the REPL shell`);
312 repl.start(chalk.blueBright(`#> `)).on("exit", () => db?.destroy());
313}
314
315/**
316 * Exports database data to a backup file.

Callers 1

cli.tsFile · 0.85

Calls 1

getDatabaseFunction · 0.85

Tested by

no test coverage detected