import { openDB } from 'idb';

// 初始化数据库
export const dbPromise = openDB('commandCentreDB', 1, {
  upgrade(db) {
    db.createObjectStore('data', { keyPath: 'key' });
  },
});

// 新增数据
export async function addIDBData(key: string, data: any) {
  const db = await dbPromise;
  await db.put('data', { key, value: data });
}

// 获取数据
export async function getIDBData(key: string) {
  const db = await dbPromise;
  return await db.get('data', key);
}

// 删除数据
export async function deleteIDBData(key: string) {
  const db = await dbPromise;
  await db.delete('data', key);
}
