Files
bun-sqlite/src/commands/admin/index.ts
T
tbenandClaude Opus 5.5 87da436f81 Port bun-mariadb conventions: init globals, db handler, split schema sync
- init() loads config, schema and the SQLite client once into globals
- all CRUD queries go through lib/db-handler.ts (optional per-call config)
- split db-schema-manager.ts into lib/schema/* with FK-aware table ordering
- add bun:test tests for schema ordering, FK constraints and schema sync
- config/schema files can be .ts/.js/.json/.yaml/.yml; db_schema_file_name
  is now optional (defaults to schema.* in db_dir)
- add export/import commands (database snapshot + schema archives)
- package exports map, type re-exports, hardened publish.sh
- validate table name in delete

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 02:37:35 +01:00

41 lines
1.4 KiB
TypeScript

import { Command } from "commander";
import chalk from "chalk";
import { select } from "@inquirer/prompts";
import listTables from "./list-tables";
import runSQL from "./run-sql";
export default function () {
return new Command("admin")
.description("View Tables and Data, Run SQL Queries, Etc.")
.action(async () => {
const db = global.SQLITE_CLIENT;
console.log(chalk.bold(chalk.blue("\nBun SQLite Admin\n")));
try {
while (true) {
const paradigm = await select({
message: "Choose an action:",
choices: [
{ name: "Tables", value: "list_tables" },
{ name: "SQL", value: "run_sql" },
{ name: chalk.dim("✕ Exit"), value: "exit" },
],
});
if (paradigm === "exit") break;
if (paradigm === "list_tables") {
const result = await listTables({ db });
if (result === "__exit__") break;
}
if (paradigm === "run_sql") await runSQL({ db });
}
} catch (error: any) {
console.error(error.message);
}
db.close();
process.exit();
});
}