Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/almost/react-native-sqlite
SQLite3 bindings for React Native
https://github.com/almost/react-native-sqlite
Last synced: 19 days ago
JSON representation
SQLite3 bindings for React Native
- Host: GitHub
- URL: https://github.com/almost/react-native-sqlite
- Owner: almost
- License: mit
- Created: 2015-04-03T23:19:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-31T16:27:57.000Z (almost 9 years ago)
- Last Synced: 2024-11-14T03:05:34.847Z (28 days ago)
- Language: Objective-C
- Size: 30.3 KB
- Stars: 537
- Watchers: 30
- Forks: 48
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-react-native-ui - react-native-sqlite ★474 - SQLite3 bindings for React Native (Components / Storage)
- awesome-react-native - react-native-sqlite ★539 - SQLite3 bindings for React Native (Components / Storage)
README
# react-native-sqlite
NOTE: This hasn't been maintained for a while and was never very complete to start with. Check out https://github.com/andpor/react-native-sqlite-storage for a more usable library!
A binding for sqlite3 for React Native. Allows a database to be opened and for SQL queries to be run on it.
Written by Thomas Parslow
([almostobsolete.net](http://almostobsolete.net) and
[tomparslow.co.uk](http://tomparslow.co.uk)) as part of Active Inbox
([activeinboxhq.com](http://activeinboxhq.com/)).## Installation
Install using npm with `npm install --save react-native-sqlite`
You then need to add the Objective C part to your XCode project. Drag
`AIBSQLite.xcodeproj` from the `node_modules/react-native-sqlite` folder into your XCode project. Click on the project in XCode, goto `Build Phases` then `Link Binary With Libraries` and add `libAIBSQLite.a` and `libsqlite3.dylib`.NOTE: Make sure you don't have the `AIBSQLite` project open seperately in XCode otherwise it won't work.
## Usage
```javascript
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
}
});
}
});
```## Database Location
It will first look for the database filename you give in the `Documents` directory inside the app sandbox. If it doesn't find anything there it will look in the app bundle and try and copy it to the `Documents` directory. If it doesn't find the database in either place then it will create a new blank database in the `Documents` directory.
In the future it should probably be made possible to open/create databases in the `tmp` and `Libraries` directories.
## Known Issues
- Doesn't support reading of BLOB fields right now. I'm not entirely sure what would be the best way to pass back binary data. Maybe Base64?
- Database needs to be closed manually. I'm not sure how I could do
this automatically.## Feedback Welcome!
Feedback, questions, suggestions and most of all Pull Requests are
very welcome. This is an early version and I want to figure out the
best way to continue it.I'm also available for freelance work!
I'm [@almostobsolete](http://twitter.com/almostobsolete) on Twitter my
email is [[email protected]](mailto:[email protected]) and
you can find me on the web at
[tomparslow.co.uk](http://tomparslow.co.uk) and
[almostobsolete.net](http://almostobsolete.net)