import path from "node:path"; import { JSONFilePreset } from "lowdb/node"; import { app } from "electron"; import { Low } from "node_modules/lowdb/lib/core/Low"; import { StructuredMetadata } from "./dicom"; interface ICreateDatabase { name: string; } type SeriesTableType = StructuredMetadata & { createTime?: number; updateTime?: number; }; interface DbTable { series: SeriesTableType[]; } const defaultData: DbTable = { series: [] }; export let db: Low<{ series: SeriesTableType[] }>; export const createDatabase = async (config: ICreateDatabase) => { const { name } = config; db = await JSONFilePreset( path.join(app.getPath("userData"), name), defaultData ); }; // Update db.json // await db.update(({ posts }) => posts.push("hello world")); // Alternatively you can call db.write() explicitely later to write to db.json // db.data.posts.push("hello world"); // await db.write(); // console.log(db);