| 12 | } |
| 13 | |
| 14 | async open() { |
| 15 | this.db = await new Promise((resolve, reject) => { |
| 16 | const req = self.indexedDB.open(IDB_NAME, IDB_VER); |
| 17 | req.onupgradeneeded = () => { |
| 18 | const db = req.result; |
| 19 | if (!db.objectStoreNames.contains('cas')) db.createObjectStore('cas'); |
| 20 | if (!db.objectStoreNames.contains('lockfile')) db.createObjectStore('lockfile'); |
| 21 | }; |
| 22 | req.onsuccess = () => resolve(req.result); |
| 23 | req.onerror = () => reject(req.error); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | _tx(store, mode) { |
| 28 | return this.db.transaction(store, mode).objectStore(store); |