Skip to content

Instantly share code, notes, and snippets.

@mrkurt
Created June 30, 2010 19:06
Show Gist options
  • Save mrkurt/459086 to your computer and use it in GitHub Desktop.
Save mrkurt/459086 to your computer and use it in GitHub Desktop.
/*jslint debug: false, passfail: false, onevar: true,
white: false, regexp: false, nomen: false, plusplus: false, browser: true */
/*global ars, openDatabase */
ars.api.offline = {
available : false,
db : openDatabase('ars', '0.1', 'Ars Technica Offline Content', 5 * 1024 * 1024),
init : function(){
var db = ars.api.offline.db;
db.transaction(function(tx){
tx.executeSql('DROP TABLE IF EXISTS entries');
tx.executeSql('CREATE TABLE IF NOT EXISTS entries (endpoint unique, digest, is_full, title, date, updated_at, entry)');
tx.executeSql('CREATE TABLE IF NOT EXISTS queries (id unique, endpoint unique)');
tx.executeSql('CREATE TABLE IF NOT EXISTS query_results(query_id, endpoint)');
});
ars.api.entry.onload = ars.api.offline.store_entry;
},
store_entry : function(entry){
var db = ars.api.offline.db;
console.debug('Storing entry');
db.transaction(function(tx){
tx.executeSql(
'INSERT INTO entries(endpoint, digest, is_full, title, date, updated_at, entry) VALUES(?, ?, ?, ?, ?, ?, ?)',
[entry.endpoint, entry.digest, entry.fully_loaded, entry.title, entry.date, entry.updated_at, ars.api.offline.entry_encoder(entry)]
);
});
},
entry_encoder : JSON.stringify,
entry_decoder : JSON.parse
};
ars.api.offline.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment