import { IRPCActionType } from '@/utils/enum' interface IFilter { orderBy?: 'asc' | 'desc' limit?: number offset?: number } interface IGetResult { total: number data: IResult[] } interface IObject { id?: string [propName: string]: any } type IResult = T & { id: string createdAt: number updatedAt: number } export class GalleryDB implements IGalleryDB { async #actionHandler(method: string, ...args: any[]): Promise { return await window.electron.triggerRPC(method, ...args) } async get(filter?: IFilter): Promise | undefined> { return await this.#actionHandler>(IRPCActionType.GALLERY_GET_DB, filter) } async insert(value: T): Promise | undefined> { return await this.#actionHandler>(IRPCActionType.GALLERY_INSERT_DB, value) } async insertMany(value: T[]): Promise[] | undefined> { return await this.#actionHandler[]>(IRPCActionType.GALLERY_INSERT_DB_BATCH, value) } async updateById(id: string, value: IObject): Promise { return (await this.#actionHandler(IRPCActionType.GALLERY_UPDATE_BY_ID_DB, id, value)) || false } async getById(id: string): Promise | undefined> { return await this.#actionHandler | undefined>(IRPCActionType.GALLERY_GET_BY_ID_DB, id) } async removeById(id: string): Promise { return await this.#actionHandler(IRPCActionType.GALLERY_REMOVE_BY_ID_DB, id) } } export default new GalleryDB()