First stable version
This commit is contained in:
Vendored
+35
-20
@@ -1,22 +1,37 @@
|
||||
import { Command } from "commander";
|
||||
import init from "../functions/init";
|
||||
import path from "path";
|
||||
import grabDBDir from "../utils/grab-db-dir";
|
||||
import fs from "fs";
|
||||
import grabDBBackupFileName from "../utils/grab-db-backup-file-name";
|
||||
import chalk from "chalk";
|
||||
import trimBackups from "../utils/trim-backups";
|
||||
export default function () {
|
||||
return new Command("backup")
|
||||
.description("Backup Database")
|
||||
.action(async (opts) => {
|
||||
console.log(`Backing up database ...`);
|
||||
const { config } = await init();
|
||||
const { backup_dir, db_file_path } = grabDBDir({ config });
|
||||
const new_db_file_name = grabDBBackupFileName({ config });
|
||||
fs.cpSync(db_file_path, path.join(backup_dir, new_db_file_name));
|
||||
trimBackups({ config });
|
||||
console.log(`${chalk.bold(chalk.green(`DB Backup Success!`))}`);
|
||||
process.exit();
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const commander_1 = require("commander");
|
||||
const init_1 = __importDefault(require("../functions/init"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_db_dir_1 = __importDefault(require("../utils/grab-db-dir"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_db_backup_file_name_1 = __importDefault(require("../utils/grab-db-backup-file-name"));
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
const trim_backups_1 = __importDefault(require("../utils/trim-backups"));
|
||||
function default_1() {
|
||||
return new commander_1.Command("backup")
|
||||
.description("Backup Database")
|
||||
.action((opts) => __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`Backing up database ...`);
|
||||
const { config } = yield (0, init_1.default)();
|
||||
const { backup_dir, db_file_path } = (0, grab_db_dir_1.default)({ config });
|
||||
const new_db_file_name = (0, grab_db_backup_file_name_1.default)({ config });
|
||||
fs_1.default.cpSync(db_file_path, path_1.default.join(backup_dir, new_db_file_name));
|
||||
(0, trim_backups_1.default)({ config });
|
||||
console.log(`${chalk_1.default.bold(chalk_1.default.green(`DB Backup Success!`))}`);
|
||||
process.exit();
|
||||
}));
|
||||
}
|
||||
|
||||
Vendored
+18
-13
@@ -1,31 +1,36 @@
|
||||
#!/usr/bin/env bun
|
||||
import { program } from "commander";
|
||||
import schema from "./schema";
|
||||
import typedef from "./typedef";
|
||||
import backup from "./backup";
|
||||
import restore from "./restore";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const commander_1 = require("commander");
|
||||
const schema_1 = __importDefault(require("./schema"));
|
||||
const typedef_1 = __importDefault(require("./typedef"));
|
||||
const backup_1 = __importDefault(require("./backup"));
|
||||
const restore_1 = __importDefault(require("./restore"));
|
||||
/**
|
||||
* # Describe Program
|
||||
*/
|
||||
program
|
||||
commander_1.program
|
||||
.name(`bun-sqlite`)
|
||||
.description(`SQLite manager for Bun`)
|
||||
.version(`1.0.0`);
|
||||
/**
|
||||
* # Declare Commands
|
||||
*/
|
||||
program.addCommand(schema());
|
||||
program.addCommand(typedef());
|
||||
program.addCommand(backup());
|
||||
program.addCommand(restore());
|
||||
commander_1.program.addCommand((0, schema_1.default)());
|
||||
commander_1.program.addCommand((0, typedef_1.default)());
|
||||
commander_1.program.addCommand((0, backup_1.default)());
|
||||
commander_1.program.addCommand((0, restore_1.default)());
|
||||
/**
|
||||
* # Handle Unavailable Commands
|
||||
*/
|
||||
program.on("command:*", () => {
|
||||
console.error("Invalid command: %s\nSee --help for a list of available commands.", program.args.join(" "));
|
||||
commander_1.program.on("command:*", () => {
|
||||
console.error("Invalid command: %s\nSee --help for a list of available commands.", commander_1.program.args.join(" "));
|
||||
process.exit(1);
|
||||
});
|
||||
/**
|
||||
* # Parse Arguments
|
||||
*/
|
||||
program.parse(Bun.argv);
|
||||
commander_1.program.parse(process.argv);
|
||||
|
||||
Vendored
+36
-21
@@ -1,29 +1,44 @@
|
||||
import { Command } from "commander";
|
||||
import init from "../functions/init";
|
||||
import grabDBDir from "../utils/grab-db-dir";
|
||||
import fs from "fs";
|
||||
import chalk from "chalk";
|
||||
import grabSortedBackups from "../utils/grab-sorted-backups";
|
||||
import { select } from "@inquirer/prompts";
|
||||
import grabBackupData from "../utils/grab-backup-data";
|
||||
import path from "path";
|
||||
export default function () {
|
||||
return new Command("restore")
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const commander_1 = require("commander");
|
||||
const init_1 = __importDefault(require("../functions/init"));
|
||||
const grab_db_dir_1 = __importDefault(require("../utils/grab-db-dir"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
const grab_sorted_backups_1 = __importDefault(require("../utils/grab-sorted-backups"));
|
||||
const prompts_1 = require("@inquirer/prompts");
|
||||
const grab_backup_data_1 = __importDefault(require("../utils/grab-backup-data"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
function default_1() {
|
||||
return new commander_1.Command("restore")
|
||||
.description("Restore Database")
|
||||
.action(async (opts) => {
|
||||
.action((opts) => __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`Restoring up database ...`);
|
||||
const { config } = await init();
|
||||
const { backup_dir, db_file_path } = grabDBDir({ config });
|
||||
const backups = grabSortedBackups({ config });
|
||||
if (!backups?.[0]) {
|
||||
const { config } = yield (0, init_1.default)();
|
||||
const { backup_dir, db_file_path } = (0, grab_db_dir_1.default)({ config });
|
||||
const backups = (0, grab_sorted_backups_1.default)({ config });
|
||||
if (!(backups === null || backups === void 0 ? void 0 : backups[0])) {
|
||||
console.error(`No Backups to restore. Use the \`backup\` command to create a backup`);
|
||||
process.exit(1);
|
||||
}
|
||||
try {
|
||||
const selected_backup = await select({
|
||||
const selected_backup = yield (0, prompts_1.select)({
|
||||
message: "Select a backup:",
|
||||
choices: backups.map((b, i) => {
|
||||
const { backup_date } = grabBackupData({
|
||||
const { backup_date } = (0, grab_backup_data_1.default)({
|
||||
backup_name: b,
|
||||
});
|
||||
return {
|
||||
@@ -32,13 +47,13 @@ export default function () {
|
||||
};
|
||||
}),
|
||||
});
|
||||
fs.cpSync(path.join(backup_dir, selected_backup), db_file_path);
|
||||
console.log(`${chalk.bold(chalk.green(`DB Restore Success!`))}`);
|
||||
fs_1.default.cpSync(path_1.default.join(backup_dir, selected_backup), db_file_path);
|
||||
console.log(`${chalk_1.default.bold(chalk_1.default.green(`DB Restore Success!`))}`);
|
||||
process.exit();
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Backup Restore ERROR => ${error.message}`);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
Vendored
+35
-21
@@ -1,38 +1,52 @@
|
||||
import { Command } from "commander";
|
||||
import { SQLiteSchemaManager } from "../lib/sqlite/db-schema-manager";
|
||||
import init from "../functions/init";
|
||||
import grabDirNames from "../data/grab-dir-names";
|
||||
import path from "path";
|
||||
import dbSchemaToTypeDef from "../lib/sqlite/schema-to-typedef";
|
||||
import _ from "lodash";
|
||||
import appendDefaultFieldsToDbSchema from "../utils/append-default-fields-to-db-schema";
|
||||
import chalk from "chalk";
|
||||
export default function () {
|
||||
return new Command("schema")
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const commander_1 = require("commander");
|
||||
const db_schema_manager_1 = require("../lib/sqlite/db-schema-manager");
|
||||
const init_1 = __importDefault(require("../functions/init"));
|
||||
const grab_dir_names_1 = __importDefault(require("../data/grab-dir-names"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const schema_to_typedef_1 = __importDefault(require("../lib/sqlite/schema-to-typedef"));
|
||||
const append_default_fields_to_db_schema_1 = __importDefault(require("../utils/append-default-fields-to-db-schema"));
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
function default_1() {
|
||||
return new commander_1.Command("schema")
|
||||
.description("Build DB From Schema")
|
||||
.option("-v, --vector", "Recreate Vector Tables. This will drop and rebuild all vector tables")
|
||||
.option("-t, --typedef", "Generate typescript type definitions")
|
||||
.action(async (opts) => {
|
||||
.action((opts) => __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`Starting process ...`);
|
||||
const { config, dbSchema } = await init();
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
const { config, dbSchema } = yield (0, init_1.default)();
|
||||
const { ROOT_DIR } = (0, grab_dir_names_1.default)();
|
||||
const isVector = Boolean(opts.vector || opts.v);
|
||||
const isTypeDef = Boolean(opts.typedef || opts.t);
|
||||
const finaldbSchema = appendDefaultFieldsToDbSchema({ dbSchema });
|
||||
const manager = new SQLiteSchemaManager({
|
||||
const finaldbSchema = (0, append_default_fields_to_db_schema_1.default)({ dbSchema });
|
||||
const manager = new db_schema_manager_1.SQLiteSchemaManager({
|
||||
schema: finaldbSchema,
|
||||
recreate_vector_table: isVector,
|
||||
});
|
||||
await manager.syncSchema();
|
||||
yield manager.syncSchema();
|
||||
manager.close();
|
||||
if (isTypeDef && config.typedef_file_path) {
|
||||
const out_file = path.resolve(ROOT_DIR, config.typedef_file_path);
|
||||
dbSchemaToTypeDef({
|
||||
const out_file = path_1.default.resolve(ROOT_DIR, config.typedef_file_path);
|
||||
(0, schema_to_typedef_1.default)({
|
||||
dbSchema: finaldbSchema,
|
||||
dst_file: out_file,
|
||||
});
|
||||
}
|
||||
console.log(`${chalk.bold(chalk.green(`DB Schema setup success!`))}`);
|
||||
console.log(`${chalk_1.default.bold(chalk_1.default.green(`DB Schema setup success!`))}`);
|
||||
process.exit();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
Vendored
+32
-17
@@ -1,21 +1,36 @@
|
||||
import { Command } from "commander";
|
||||
import init from "../functions/init";
|
||||
import dbSchemaToTypeDef from "../lib/sqlite/schema-to-typedef";
|
||||
import path from "path";
|
||||
import grabDirNames from "../data/grab-dir-names";
|
||||
import appendDefaultFieldsToDbSchema from "../utils/append-default-fields-to-db-schema";
|
||||
import chalk from "chalk";
|
||||
export default function () {
|
||||
return new Command("typedef")
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const commander_1 = require("commander");
|
||||
const init_1 = __importDefault(require("../functions/init"));
|
||||
const schema_to_typedef_1 = __importDefault(require("../lib/sqlite/schema-to-typedef"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_dir_names_1 = __importDefault(require("../data/grab-dir-names"));
|
||||
const append_default_fields_to_db_schema_1 = __importDefault(require("../utils/append-default-fields-to-db-schema"));
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
function default_1() {
|
||||
return new commander_1.Command("typedef")
|
||||
.description("Build DB From Schema")
|
||||
.action(async (opts) => {
|
||||
.action((opts) => __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`Creating Type Definition From DB Schema ...`);
|
||||
const { config, dbSchema } = await init();
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
const finaldbSchema = appendDefaultFieldsToDbSchema({ dbSchema });
|
||||
const { config, dbSchema } = yield (0, init_1.default)();
|
||||
const { ROOT_DIR } = (0, grab_dir_names_1.default)();
|
||||
const finaldbSchema = (0, append_default_fields_to_db_schema_1.default)({ dbSchema });
|
||||
if (config.typedef_file_path) {
|
||||
const out_file = path.resolve(ROOT_DIR, config.typedef_file_path);
|
||||
dbSchemaToTypeDef({
|
||||
const out_file = path_1.default.resolve(ROOT_DIR, config.typedef_file_path);
|
||||
(0, schema_to_typedef_1.default)({
|
||||
dbSchema: finaldbSchema,
|
||||
dst_file: out_file,
|
||||
});
|
||||
@@ -24,7 +39,7 @@ export default function () {
|
||||
console.error(``);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`${chalk.bold(chalk.green(`Typedef gen success!`))}`);
|
||||
console.log(`${chalk_1.default.bold(chalk_1.default.green(`Typedef gen success!`))}`);
|
||||
process.exit();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user