Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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