Skip to content

Commit

Permalink
use async for file operations
Browse files Browse the repository at this point in the history
  • Loading branch information
probablyArth committed Apr 7, 2024
1 parent 2066fb5 commit 7a1ef06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Model.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -159,8 +159,8 @@ export class Model<T> {
/**
* 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" });
}
}
6 changes: 3 additions & 3 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7a1ef06

Please sign in to comment.