Storage API

From many great additions of HTML5, one of the most welcomed has been the Local Storage. Any fairly complex application needs to store some amount of data in a non-volatile persistent storage. One of the disadvantages of client side applications has always been lack of a good way to store data to the client. We had Cookies but they offered very limited storage.

Though HTML5 provides the Local Storage, the problem is that, this storage is just variable-to-value storage which is inconsistent with the idea of SQL tables most developers are comfortable with. Teleiotes manages this great hazel for you to provide an API that lets you store and retrieve data in an SQL similar fashion (create, drop, insert, select, del). Teleiotes uses JavaScript Object Navigation (JSON) for this purpose.

Table Creation

 

 

var storage = new t.Storage();
if (storage.check()) {
     storage.init();
     storage.create("Fighters", ["name", "race", "age"]);
}

Table Drop

 

 

var storage = new t.Storage();
if (storage.check()) {
     storage.init();
     storage.drop("Fighters");
}

Insert

 

 

var storage = new t.Storage();
if (storage.check()) {
     storage.init();
     storage.insert("Fighters", {name: "Kitana", race: "Edenian", age: 10000});
     storage.insert("Fighters", {name: "Sonya", race: "Human", age: 25});
     storage.insert("Fighters", {name: "Tanya", race: "Outworlder", age: 5000});
}

Delete

 

var storage = new t.Storage();
            if (storage.check()) {
                storage.init();
                storage.del("Fighters"); // delete from Fighters
                storage.del("Fighters", "name", "Sonya"); // delete from Fighters where name like "Sonya"
                storage.del("Fighters", "age", 500, "ge"); // delete from Fighters where age >= 500
                /*
                    predicates: eq, gt, lt, ge, le
                */
            }

 

 

Select

 

var storage = new t.Storage();
            if (storage.check()) {
                storage.init();
                storage.select("Fighters"); // select * from Fighters
                storage.select("Fighters", "name", "Sonya"); // select * from Fighters where name like "Sonya"
                storage.select("Fighters", "age", 500, "ge"); // select * from Fighters where age >= 500
                /*
                    predicates: eq, gt, lt, ge, le
                */
            }


 

Please note that as of now, Teleiotes 2.0 does not provide any kind of fallback mechanism for the browsers that do not support the Local Storage. We may provide an alternative mechanism in following releases.

Last edited Dec 27, 2011 at 6:52 PM by mihsathe, version 4

Comments

No comments yet.