react-native-sqlite 是 React Native 上的一个 sqlite3 绑定,它可以打开数据库并让 SQL 查询运行其中。目前还只是早期版本, API 还有可能会改变。
示例代码:
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 } }); } });