| 49 | } |
| 50 | |
| 51 | function openDB(): Promise<IDBDatabase> { |
| 52 | return new Promise((resolve, reject) => { |
| 53 | const req = indexedDB.open(DB_NAME, DB_VERSION); |
| 54 | req.onupgradeneeded = () => { |
| 55 | const db = req.result; |
| 56 | if (!db.objectStoreNames.contains(STORE_WORKSPACES)) { |
| 57 | db.createObjectStore(STORE_WORKSPACES, { keyPath: 'id' }); |
| 58 | } |
| 59 | if (!db.objectStoreNames.contains(STORE_TABLE_DATA)) { |
| 60 | const tableStore = db.createObjectStore(STORE_TABLE_DATA, { keyPath: 'key' }); |
| 61 | tableStore.createIndex('workspaceId', 'workspaceId', { unique: false }); |
| 62 | } |
| 63 | }; |
| 64 | req.onsuccess = () => resolve(req.result); |
| 65 | req.onerror = () => reject(req.error); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | function txStore( |
| 70 | db: IDBDatabase, |