Last active
September 3, 2016 18:37
-
-
Save Breta01/954286dceb1b31cc37f657af8dcb06fc 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
/** Create a new stat **/ | |
mkDB.createStat = function(title, score, callback) { | |
var db = datastore; | |
var transaction = db.transaction(['stats'], 'readwrite'); | |
var objStore = transaction.objectStore('stats'); | |
// Create a timestamp for the stat item. (this is key value) | |
var timestamp = new Date().getTime(); | |
// Create an object for the stat | |
var stat = { | |
game: title, | |
score: score, | |
timestamp: timestamp | |
}; | |
// Create the datastore request. | |
var request = objStore.put(stat); | |
// Handle a successful datastore put. | |
request.onsuccess = function(e) { | |
callback(); | |
}; | |
// Handle errors. | |
request.onerror = mkDB.onerror; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment