Last active
September 3, 2016 19:54
-
-
Save Breta01/94d63e27c3c3029b501d4d9d32dba9f6 to your computer and use it in GitHub Desktop.
Implementing IndexedDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const memokingDB = (function() { | |
var mkDB = {}; | |
var datastore = null; | |
/** Open conection to the DB **/ | |
mkDB.open = function(callback) { | |
var request = indexedDB.open("memoking"); | |
request.onupgradeneeded = function() { | |
// The database did not previously exist, so create object stores and indexes. | |
var db = request.result; | |
var store = db.createObjectStore('stats', {keyPath: 'timestamp'}); | |
var gameIndex = store.createIndex("by_game", "game"); | |
var scoreIndex = store.createIndex("by_score", "score"); | |
// Populate with initial TEST data. | |
store.put({game: "Cards", score: 100, timestamp: 1}); | |
}; | |
request.onsuccess = function() { | |
datastore = request.result; | |
callback(); | |
}; | |
// Error handling | |
request.onerror = mkDB.onerror; | |
}; | |
/* | |
* | |
* Place for other funcions working with DB | |
* | |
*/ | |
return mkDB; | |
}()); | |
export default memokingDB; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment