poll.horse/src/FlatFileStorage.ts
Wolvan 0545d90c3f Implement different backend types
Including to the previous flatfile storage, a new storage for MySQL has
been added to store polls in a database.
The amount of possible Poll Options has also been reduced to 20.
2022-01-08 16:12:04 +01:00

27 lines
No EOL
748 B
TypeScript

"use strict";
import Storage from "./Storage";
import persist from "node-persist";
import { BackendPoll as Poll } from "./Poll";
export default class FlatFileStorage extends Storage {
#storage: persist.LocalStorage;
constructor(options: persist.InitOptions) {
super();
console.debug("Initiating FlatFileStorage.");
this.#storage = persist.create(options);
}
async init() {
await this.#storage.init();
return this;
}
getItem(key: string): Promise<Poll> {
return this.#storage.getItem(key);
}
setItem(key: string, value: Poll, options?: persist.DatumOptions): Promise<persist.WriteFileResult> {
return this.#storage.setItem(key, value, options);
}
}