Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created April 26, 2014 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/11324065 to your computer and use it in GitHub Desktop.
Save nolanlawson/11324065 to your computer and use it in GitHub Desktop.
websql_example.js
openDatabase('mydatabase', 1, 'mydatabase', 5000000, function (db) {
function onTransactionSuccess() {
console.log('yay, transaction succeeded!');
}
function onTransactionError() {
console.log('boo, transaction failed!');
}
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE rainstorms (mood TEXT NOT NULL PRIMARY KEY, severity INTEGER);', [], function () {
tx.executeSql('INSERT INTO rainstorms VALUES (?, ?)', ['somber', 6], function () {
tx.executeSql('SELECT * FROM rainstorms WHERE mood = ?', ['somber'], function (tx, res) {
var row = res.rows.item(0);
console.log('rainstorm was a ' + row.severity + ', I felt ' + row.mood);
})
});
});
}, onTransactionError, onTransactionSuccess);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment