Created
February 24, 2013 21:03
-
-
Save glynrob/5025607 to your computer and use it in GitHub Desktop.
Indexed DB API connect
This file contains hidden or 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
function openDb() { | |
var req = indexedDB.open(DB_NAME, DB_VERSION); | |
req.onsuccess = function (evt) { // success connection to the database so display rows | |
db = this.result; | |
displayRows(); | |
}; | |
req.onerror = function (evt) { // error - display error | |
displayActionFailure("DB error: "+ evt.target.errorCode); | |
}; | |
req.onupgradeneeded = function (evt) { // upgrade version has changed so upgrade | |
var store = evt.currentTarget.result.createObjectStore( | |
DB_TABLE_NAME, { keyPath: 'id', autoIncrement: true }); | |
store.createIndex('title', 'title', { unique: false }); // create fields | |
//store.createIndex('contents', 'contents', { unique: false }); // any other data you wish to add to the list | |
}; | |
} | |
function getObjectStore(storename, mode) { | |
var tx = db.transaction(storename, mode); | |
return tx.objectStore(storename); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment