Skip to content

Instantly share code, notes, and snippets.

@arackaf
Created December 2, 2017 03:01
Show Gist options
  • Save arackaf/93533d357e2f35238f7023e960ebd2a3 to your computer and use it in GitHub Desktop.
Save arackaf/93533d357e2f35238f7023e960ebd2a3 to your computer and use it in GitHub Desktop.
self.addEventListener("activate", () => {
let open = indexedDB.open("books", 1);
open.onupgradeneeded = evt => {
let db = open.result;
if (!db.objectStoreNames.contains("books") || !db.objectStoreNames.contains("syncInfo")) {
if (!db.objectStoreNames.contains("books")) {
let bookStore = db.createObjectStore("books", { keyPath: "_id" });
bookStore.createIndex("imgSync", "imgSync", { unique: false });
}
if (!db.objectStoreNames.contains("syncInfo")) {
db.createObjectStore("syncInfo", { keyPath: "id" });
evt.target.transaction
.objectStore("syncInfo")
.add({ id: 1, lastImgSync: null, lastImgSyncStarted: null, lastLoadStarted: +new Date(), lastLoad: null });
}
evt.target.transaction.oncomplete = fullSync;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment