summaryrefslogtreecommitdiff
path: root/src/db.js
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2025-11-08 18:55:03 +0100
committerLeo Goetz <dev@leogtz.de>2025-11-08 18:55:03 +0100
commit16a0e9a9d2c24af28142ed3420ef6cb373c454f7 (patch)
treeb948472cea12b505ae3f2cc04b66801207ebc6aa /src/db.js
parent91a6ac10e416dcf2c29b6e37e3dfe19672eb0f84 (diff)
started making the command and json db
Diffstat (limited to 'src/db.js')
-rw-r--r--src/db.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/db.js b/src/db.js
new file mode 100644
index 0000000..39fdc29
--- /dev/null
+++ b/src/db.js
@@ -0,0 +1,17 @@
+import fs from "node:fs/promises";
+
+const DB_PATH = new URL("../db.json", import.meta.url).pathname;
+
+export const getDB = async () => {
+ const db = await fs.readFile(DB_PATH, "utf-8");
+ return JSON.parse(db);
+};
+
+export const saveDB = async (db) => {
+ await fs.writeFile(DB_PATH, JSON.stringify(db, null, 2));
+ return db;
+};
+
+export const insertDB = async (note) => {
+ const db = await getDB();
+};