Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Created May 12, 2010 07:58
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 philippbosch/398316 to your computer and use it in GitHub Desktop.
Save philippbosch/398316 to your computer and use it in GitHub Desktop.
...
<input type="text" id="username">
...
$(document).ready(function() {
var username = localStorage.getItem('username');
if (username) $('#twitter_username').val(username);
});
$('#twitter_username').change(function() {
localStorage.setItem('username', $(this).val());
});
...
<script src="jqtouch/jquery.js"></script>
<script src="jqtouch/jqtouch.js"></script>
<script src="json2.js"></script>
<script src="jquery.couch.js"></script>
<script src="app.js"></script>
...
var db = $.couch.db('databasename');
var document = {
'name': 'Philipp',
'size': 185,
'city': 'Berlin'
};
db.saveDoc(document, {
'success': function() {
alert('Document was successfully saved.');
}
});
db.allDocs({
'success': function(result) {
for (var i in result.rows) {
db.openDoc(result.rows[i].id, {
'success': function(row) {
console.log(row.name + ', ' + row.city);
}
})
}
}
})
var dbShortName = 'People';
var dbVersion = '1.0';
var dbDisplayName = 'People';
var dbMaxSize = 65536;
var db = openDatabase(dbShortName, dbVersion, dbDisplayName, dbMaxSize);
db.transaction(function(transaction) {
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS people (' +
' id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,' +
' name VARCHAR(100) NOT NULL,' +
' age INTEGER' +
');'
);
});
db.transaction(function(transaction) {
transaction.executeSql(
'INSERT INTO people ' +
' (name, age) ' +
'VALUES ' +
' (?,?)'
, ["Lena Meyer-Landrut", 18],
function(transaction, result) {
alert('Data successfully inserted.');
},
function(transaction, error) {
alert('Oops. Error was "' + error.message + '" (Code: ' + error.code + ')');
return true;
});
});
db.transaction(function(transaction) {
transaction.executeSql(
'SELECT * FROM people ' +
'WHERE age >= 18',
null,
function(transaction, result) {
for (var i=0; i<result.rows.length; i++) {
var row = result.rows.item(i);
console.log(row);
}
},
function(transaction, error) {
alert('Oops. Error was "' + error.message + '" (Code: ' + error.code + ')');
return true;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment