"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryDB = void 0;
const tslib_1 = require("tslib");
const base_db_1 = require("../base-db");
/**
 * 封装数据增删查改，数据统一存储为 redis hashmap 类型
 * 本地开发或单机部署时用此模型，数据保存在内存中
 */
class MemoryDB extends base_db_1.BaseDB {
    /**
     * 本地无需做初始化，暂写作空实现
     */
    init() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () { });
    }
    get(field) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const hashmap = MemoryDB.db.get(this.key);
            if (!hashmap)
                return;
            return hashmap.get(field);
        });
    }
    getAll() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const hashmap = MemoryDB.db.get(this.key) || new Map();
            return Array.from(hashmap.values());
        });
    }
    upsert(field, value) {
        if (!MemoryDB.db.has(this.key)) {
            MemoryDB.db.set(this.key, new Map());
        }
        const hashMap = MemoryDB.db.get(this.key);
        hashMap.set(field, value);
    }
    delete(field) {
        const hashMap = MemoryDB.db.get(this.key);
        hashMap === null || hashMap === void 0 ? void 0 : hashMap.delete(field);
    }
}
exports.MemoryDB = MemoryDB;
MemoryDB.db = new Map();
