SQLite3 bindings for React Native

Chances are that your app is going to need a Database to store user's preferences and data.

Today we're showing a binding for sqlite3 for React Native from @almost. It allows a database to be opened and for SQL queries to be run on it.

react-native-sqlite on GitHub

Here is an usage example from the same repo

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;
      }
    });
  }
});

React Native SQLite Example

You can also find an example of how to read an SQLite database from React Native using react-native-sqlite.