cvpilot-tool/apps/desktop/electron/core/db.ts

25 lines
569 B
TypeScript
Raw Normal View History

2024-08-29 16:59:25 +08:00
import path from "node:path";
import { JSONFilePreset } from "lowdb/node";
import { app } from "electron";
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();