Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var global = this,
- dbOpen, db, store, index, result;
- document.addEventListener('DOMContentLoaded', function () {
- dbOpen = webkitIndexedDB.open( 'test_' + (+new Date()), 'This is my temporary indexedDB');
- console.log( "dbOpen", dbOpen );
- for ( var prop in dbOpen ) {
- console.log(prop, typeof dbOpen[prop]);
- }
- dbOpen.addEventListener('success', function (event) {
- // IDBSuccessEvent
- console.log("event", event);
- // IDBDatabase
- console.log("event.result", event.result);
- // Alias IDBDatabase
- db = event.result;
- for ( var prop in db ) {
- //console.log(prop, db[prop]);
- // name tempDB
- // version a version id
- // objectStores DOMStringList
- // createObjectStore function createObjectStore() { [native code] }
- // removeObjectStore function removeObjectStore() { [native code] }
- // setVersion function setVersion() { [native code] }
- // transaction function transaction() { [native code] }
- // close function close() { [native code] }
- }
- var vdb = db.setVersion('a version id');
- vdb.addEventListener('success', function (event) {
- console.log("event", event);
- console.log("event.result", event.result);
- console.log("db.version", db.version);
- // objectStores [methods: contains, item]
- console.log("db.objectStores", db.objectStores);
- console.log("typeof db.objectStores", typeof db.objectStores);
- // object
- console.log("db.objectStores.length", db.objectStores.length);
- // 0
- for ( var prop in db.objectStores ) {
- console.log(prop, db.objectStores[prop], typeof db.objectStores[prop]);
- // length 0
- // item function item() { [native code] }
- // contains function contains() { [native code] }
- }
- store = db.createObjectStore('cooler', null);
- //store = db.objectStores.item(0);
- console.log(store);
- console.log(db.objectStores.item(0));
- index = store.createIndex('anIndex', 'foo', true);
- console.log("store", store); // null ?
- console.log("db.objectStores", db.objectStores);
- console.log("db.objectStores.length", db.objectStores.length);
- console.log("db.objectStores.contains('cooler')", db.objectStores.contains('cooler'));
- console.log("index", index);
- console.log("store.indexNames.contains('anIndex')", store.indexNames.contains('anIndex'));
- /*
- transaction = db.transaction();
- store = transaction.objectStore('cooler');
- result = store.add({ 'foo': 'bar'}, 'key');
- console.log("result", result);
- */
- }, false);
- }, false);
- }, false);
- // Constants
- console.log(webkitIDBKeyRange.SINGLE, 0);
- console.log(webkitIDBKeyRange.LEFT_OPEN, 1);
- console.log(webkitIDBKeyRange.RIGHT_OPEN, 2);
- console.log(webkitIDBKeyRange.LEFT_BOUND, 4);
- console.log(webkitIDBKeyRange.RIGHT_BOUND, 8);
- console.log(webkitIDBDatabaseException.UNKNOWN_ERR, 0);
- console.log(webkitIDBDatabaseException.NON_TRANSIENT_ERR, 1);
- console.log(webkitIDBDatabaseException.NOT_FOUND_ERR, 2);
- console.log(webkitIDBDatabaseException.CONSTRAINT_ERR, 3);
- console.log(webkitIDBDatabaseException.DATA_ERR, 4);
- console.log(webkitIDBDatabaseException.NOT_ALLOWED_ERR, 5);
- console.log(webkitIDBDatabaseException.SERIAL_ERR, 11);
- console.log(webkitIDBDatabaseException.RECOVERABLE_ERR, 21);
- console.log(webkitIDBDatabaseException.TRANSIENT_ERR, 31);
- console.log(webkitIDBDatabaseException.TIMEOUT_ERR, 32);
- console.log(webkitIDBDatabaseException.DEADLOCK_ERR, 33);
- console.log(webkitIDBRequest.LOADING, 1);
- console.log(webkitIDBRequest.DONE, 2);
- console.log(webkitIDBCursor.NEXT, 0);
- console.log(webkitIDBCursor.NEXT_NO_DUPLICATE, 1);
- console.log(webkitIDBCursor.PREV, 2);
- console.log(webkitIDBCursor.PREV_NO_DUPLICATE, 3);
- console.log(webkitIDBTransaction.READ_WRITE, 0);
- console.log(webkitIDBTransaction.READ_ONLY, 1);
- console.log(webkitIDBTransaction.SNAPSHOT_READ, 2);
- console.log(webkitIDBTransaction.VERSION_CHANGE, 3);
Add Comment
Please, Sign In to add comment