Created
June 2, 2012 17:46
-
-
Save kovrov/2859328 to your computer and use it in GitHub Desktop.
Simple QML storage wrapper for settings
This file contains hidden or 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
.pragma library | |
function Settings(applicationName, applicationVersion) { | |
this.db = openDatabaseSync(applicationName, applicationVersion) | |
this.db.transaction(function(tx) { | |
tx.executeSql('CREATE TABLE IF NOT EXISTS settings(name TEXT UNIQUE, value TEXT)') | |
}) | |
} | |
Settings.prototype.set = function(name, value) { | |
this.db.transaction(function(tx) { | |
var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);', [name,value]) | |
if (rs.rowsAffected === 0) { | |
throw { message: "should not happen" } | |
} | |
}) | |
return value | |
} | |
Settings.prototype.get = function(name) { | |
var res | |
this.db.transaction(function(tx) { | |
var rs = tx.executeSql('SELECT value FROM settings WHERE name=?;', [name]) | |
if (rs.rows.length > 0) { | |
res = rs.rows.item(0).value | |
} | |
}) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment