Skip to content

Instantly share code, notes, and snippets.

@Breta01
Last active September 3, 2016 19:54
Show Gist options
  • Save Breta01/94d63e27c3c3029b501d4d9d32dba9f6 to your computer and use it in GitHub Desktop.
Save Breta01/94d63e27c3c3029b501d4d9d32dba9f6 to your computer and use it in GitHub Desktop.
Implementing IndexedDB
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