UNPKG

enmap-wrapper

Version:

Object Oriented Wrapper for Enmap

45 lines 1.13 kB
// src/Database.ts import Enmap from "enmap"; import Stumper from "stumper"; var Database = class { constructor(options) { this.options = options; this.db = new Enmap(options); this.name = options.name || "Database"; } wipe() { Stumper.info(`Wiping ${this.name} database`, "common:Database:wipe"); this.db.clear(); } getNumOfKeys() { return this.db.count; } getAllValues() { const arr = Array.from(this.db); return arr.map((val) => val[1]); } getAllKeys() { return Array.from(this.db.keys()); } getAllKeysAndValues() { const arr = Array.from(this.db); return arr.map((val) => { return { key: val[0], value: val[1] }; }); } close() { Stumper.warning(`Closing database: ${this.name}`, "common:Database:close"); this.db.close(); } // Exists because Enmap's ensure() method expects an object as the value // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types ensure(key, value) { if (!this.db.has(key)) { this.db.set(key, value); } } }; export { Database }; //# sourceMappingURL=index.mjs.map