cvpilot-tool/apps/desktop/electron/core/db.ts
2024-08-29 16:59:25 +08:00

28 lines
676 B
TypeScript

import path from "node:path";
import { JSONFilePreset } from "lowdb/node";
import { app } from "electron";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const initDb = async () => {
// Read or create db.json
const defaultData = { posts: [] };
const db = await JSONFilePreset(
path.join(app.getPath("userData"), "db.json"),
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);
};
initDb();