attempt at using html offline sqlite

by Terrance Smith

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    
</head>
<body>
    Ello

</body>
</html>

JavaScript

///http://www.html5rocks.com/en/tutorials/indexeddb/todo/
//instantiation
var html5rocks = {};
html5rocks.indexedDB = {};
html5rocks.indexedDB.db = null;
/*
//example 1
//Define an open method
html5rocks.indexedDB.open = function () {
    var request = indexedDB.open("todos","This is a description of the database.");
    request.onsuccess = function (e) {
        html5rocks.indexedDB.db = e.target.result;
        //more stuff later
    };
    request.onfailure = html5rocks.indexedDB.onerror;
    };
*/
//example 2
//Define an open method
html5rocks.indexedDB.open = function() {
    var request = indexedDB.open("todos", "This is a description of the database");

    //if request is successful preform the callback
    request.onsuccess = function(e) {
        var v = "1.0";
        html5rocks.indexedDB.db = e.target.result;

        var db = html5rocks.indexedDB.db;

        // We can only create Object stores in a setVersion transaction;
        if (v != db.version) {
            var setVrequest = db.setVersion(v);
        }

        // onsuccess is the only place we can create Object Stores
        setVrequest.onfailure = html5rocks.indexedDB.onerror;

        setVrequest.onsuccess = function(e) {
            //creates the object store
            var store = db.createObjectStore("todo", {
                keyPath: "timeStamp"
            });

            //Calls the object store
            html5rocks.indexedDB.getAllTodoItems();
        };
    };
    request.onfailure = html5rocks.indexedDB.onerror;
};

//Addin an entry
html5rocks.indexedDB.addTodo = function(todoText) {
    //get ref to the db
    var db = html5rocks.indexedDB.db;

    //init a read_write transaction
    var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE, 0);

    //get ref to object store
    var store = trans.objectStore("todo");

    //puts new object into object store
    var request = store.put({
        "text": todoText,
        "timeStamp": = new Date().getTime()
    });

   ...