diff --git a/src/Model.ts b/src/Model.ts index 4a4ae65..867104b 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -1,4 +1,4 @@ -import { writeFileSync } from "fs"; +import { writeFile } from "fs/promises"; import { data, filePath } from "./db"; import { getIndex, search, searchOne } from "./utils/queryHelpers"; import { randomUUID } from "crypto"; @@ -159,8 +159,8 @@ export class Model { /** * Commits the memory changes to the actual database */ - commit() { + async commit() { data[this.tableName] = this.data; - writeFileSync(filePath, JSON.stringify(data), { encoding: "utf-8" }); + await writeFile(filePath, JSON.stringify(data), { encoding: "utf-8" }); } } diff --git a/src/db.ts b/src/db.ts index 95c40ea..d75ab33 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1,11 +1,11 @@ -import { readFileSync } from "fs"; +import { readFile } from "fs/promises"; export let data: any; export let filePath: string; -export function Init(path: string) { +export async function Init(path: string) { filePath = path; - const readData = readFileSync(path, { encoding: "utf-8" }); + const readData = await readFile(path, { encoding: "utf-8" }); if (readData == "") { data = {}; return;