Created
November 23, 2012 07:54
-
-
Save dvberkel/4134434 to your computer and use it in GitHub Desktop.
WebSQL demonstration
This file contains 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
"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