import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"; import grabDirNames from "../data/grab-dir-names"; import type { BUN_MARIADB_DatabaseSchemaType } from "../types"; import path from "path"; const { BUN_MARIADB_LIVE_SCHEMA } = grabDirNames(); type Params = { schema: BUN_MARIADB_DatabaseSchemaType; }; export function writeLiveSchema({ schema }: Params) { 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) as BUN_MARIADB_DatabaseSchemaType; }