import { app } from 'electron' import LocalDb from '../core/db' import type { Model } from '../core/db/types' export class StorageService { public static instance = new this() public localDb: LocalDb public constructor(public key = 'WEBMINI_DB_DEFAULT') { this.localDb = new LocalDb(app.getPath('userData')) } /** * 查询 * @param id * @param key * @returns */ public async get(id: string, key = this.key) { return await this.localDb.get(key, id) } /** * 更新 * @param doc * @param key * @returns */ public async put(doc: PouchDB.Core.PutDocument, key = this.key) { const result = await this.localDb.get(key, doc._id) doc._rev = result ? result._rev : '' return await this.localDb.put(key, doc) } /** * 删除 * @param doc * @param key * @returns */ public async remove(doc: PouchDB.Core.RemoveDocument, key = this.key) { return await this.localDb.remove(key, doc) } }