* Launches an interactive terminal with Knex.js.
(options?: {
env?: string;
schema?: string;
args?: string[];
})
| 290 | * Launches an interactive terminal with Knex.js. |
| 291 | */ |
| 292 | async 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. |