Skip to content

Instantly share code, notes, and snippets.

@reactnative
Created April 4, 2015 08:00
Show Gist options
  • Save reactnative/3ba45d552fc9c8176db6 to your computer and use it in GitHub Desktop.
Save reactnative/3ba45d552fc9c8176db6 to your computer and use it in GitHub Desktop.
react-native-sqlite
var sqlite = require('./react-native-sqlite');
sqlite.open("filename.sqlite", function (error, database) {
if (error) {
console.log("Failed to open database:", error);
return;
}
var sql = "SELECT a, b FROM table WHERE field=? AND otherfield=?";
var params = ["somestring", 99];
database.executeSQL(sql, params, rowCallback, completeCallback);
function rowCallback(rowData) {
console.log("Got row data:", rowData);
}
function completeCallback(error) {
if (error) {
console.log("Failed to execute query:", error);
return
}
console.log("Query complete!");
database.close(function (error) {
if (error) {
console.log("Failed to close database:", error);
return
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment