First Commit. Based off bun-sqlite
This commit is contained in:
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import type { BunSQLiteConfigReturn } from "../types";
|
||||
export default function init(): Promise<BunSQLiteConfigReturn>;
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { AppData } from "../data/app-data";
|
||||
import grabDirNames from "../data/grab-dir-names";
|
||||
export default async function init() {
|
||||
try {
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
const { ConfigFileName } = AppData;
|
||||
const ConfigFilePath = path.join(ROOT_DIR, ConfigFileName);
|
||||
if (!fs.existsSync(ConfigFilePath)) {
|
||||
console.log("ConfigFilePath", ConfigFilePath);
|
||||
console.error(`Please create a \`${ConfigFileName}\` file at the root of your project.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const ConfigImport = await import(ConfigFilePath);
|
||||
const Config = ConfigImport["default"];
|
||||
if (!Config.db_name) {
|
||||
console.error(`\`db_name\` is required in your config`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!Config.db_schema_file_name) {
|
||||
console.error(`\`db_schema_file_name\` is required in your config`);
|
||||
process.exit(1);
|
||||
}
|
||||
let db_dir = ROOT_DIR;
|
||||
if (Config.db_dir) {
|
||||
db_dir = path.resolve(ROOT_DIR, Config.db_dir);
|
||||
if (!fs.existsSync(Config.db_dir)) {
|
||||
fs.mkdirSync(Config.db_dir, { recursive: true });
|
||||
}
|
||||
}
|
||||
const DBSchemaFilePath = path.join(db_dir, Config.db_schema_file_name);
|
||||
const DbSchemaImport = await import(DBSchemaFilePath);
|
||||
const DbSchema = DbSchemaImport["default"];
|
||||
const backup_dir = Config.db_backup_dir || AppData["DefaultBackupDirName"];
|
||||
const BackupDir = path.resolve(db_dir, backup_dir);
|
||||
if (!fs.existsSync(BackupDir)) {
|
||||
fs.mkdirSync(BackupDir, { recursive: true });
|
||||
}
|
||||
return { config: Config, dbSchema: DbSchema };
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Initialization ERROR => ` + error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { BUN_MARIADB_DatabaseSchemaType } from "../types";
|
||||
type Params = {
|
||||
schema: BUN_MARIADB_DatabaseSchemaType;
|
||||
};
|
||||
export declare function writeLiveSchema({ schema }: Params): void;
|
||||
export declare function readLiveSchema(): BUN_MARIADB_DatabaseSchemaType | undefined;
|
||||
export {};
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import grabDirNames from "../data/grab-dir-names";
|
||||
import path from "path";
|
||||
const { BUN_MARIADB_LIVE_SCHEMA } = grabDirNames();
|
||||
export function writeLiveSchema({ schema }) {
|
||||
mkdirSync(path.dirname(BUN_MARIADB_LIVE_SCHEMA), { recursive: true });
|
||||
writeFileSync(BUN_MARIADB_LIVE_SCHEMA, JSON.stringify(schema));
|
||||
}
|
||||
export function readLiveSchema() {
|
||||
if (!existsSync(BUN_MARIADB_LIVE_SCHEMA)) {
|
||||
return undefined;
|
||||
}
|
||||
const live_schema = readFileSync(BUN_MARIADB_LIVE_SCHEMA, "utf-8");
|
||||
return JSON.parse(live_schema);
|
||||
}
|
||||
Reference in New Issue
Block a user