Skip to content

Instantly share code, notes, and snippets.

@dvberkel
Created November 23, 2012 07:54
Show Gist options
  • Save dvberkel/4134434 to your computer and use it in GitHub Desktop.
Save dvberkel/4134434 to your computer and use it in GitHub Desktop.
WebSQL demonstration
"use strict";
(function(){
var db = openDatabase("demo", "1.0", "demonstration of webSQL", 2 * 1024 * 1024);
db.transaction(function(tx){
tx.executeSql("create table if not exists entries (timestamp, description, value)");
});
db.transaction(function(tx){
tx.executeSql(
"insert into entries (timestamp, description, value) values (?, ?, ?)",
[(new Date()).getTime(), "1d6", Math.floor(6 * Math.random()) + 1]
);
});
db.transaction(function(tx){
tx.executeSql("select description, value from entries", [], function(rtx, result){
var data = {};
for (var i = 0, n = result.rows.length; i < n; i++) {
var key = result.rows.item(i).value
data[key] = (data[key] || 0) + 1
}
console.log(data);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment