tinycoll
Version:
A minimal reactive document store with Mongo-like querying, reactivity, TTL support, and optional persistence.
21 lines (20 loc) • 495 B
JavaScript
// file-storage.ts
import { readFile, writeFile } from 'fs/promises';
export class FileStorage {
#filePath;
constructor(options) {
this.#filePath = options.filePath;
}
async get() {
try {
const text = await readFile(this.#filePath, 'utf-8');
return JSON.parse(text);
}
catch {
return [];
}
}
async set(_, value) {
await writeFile(this.#filePath, JSON.stringify(value, null, 2));
}
}