Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carbureted/react-native-pouchdb
Hacky way to run pouchdb in react-native
https://github.com/carbureted/react-native-pouchdb
Last synced: 2 months ago
JSON representation
Hacky way to run pouchdb in react-native
- Host: GitHub
- URL: https://github.com/carbureted/react-native-pouchdb
- Owner: carbureted
- Created: 2016-01-22T02:45:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-13T06:05:23.000Z (almost 9 years ago)
- Last Synced: 2024-11-08T08:04:21.089Z (3 months ago)
- Language: JavaScript
- Size: 120 KB
- Stars: 40
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-react-native - react-native-pouchdb ★38 - Run pouchdb in React Native! (Components / Storage)
- awesome-react-native - react-native-pouchdb ★38 - Run pouchdb in React Native! (Components / Storage)
- awesome-react-native - react-native-pouchdb ★38 - Run pouchdb in React Native! (Components / Storage)
- awesome-react-native - react-native-pouchdb ★38 - Run pouchdb in React Native! (Components / Storage)
- awesome-react-native-ui - react-native-pouchdb ★30 - Run pouchdb in React Native! (Components / Storage)
README
# react-native-pouchdb
Hacky and mostly untested way to run pouchdb in react-native! I haven't encountered any glaring problems during development, but would not use this in a space shuttle app.First, install [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage).
Then, install react-native-pouchdb.
`npm install --save react-native-pouchdb`
Then, use it with the websql adapter.
```
var db = new PouchDB('test', {
adapter: 'websql'
});
```Now you have all the normal pouchdb goodness!
```
var db = new PouchDB('test', {
adapter: 'websql'
});var remote = 'https://my.remote.couch'
var remoteDB = new PouchDB(remote)var sync = db.sync(remoteDB, {
live: true,
retry: true
}).on('change', function(change) {
console.log(change, 'change!')
}).on('error', function(error) {
console.log(error, 'error!')
})db.info().then(console.log.bind(console));
function showTodos() {
db.allDocs({include_docs: true, descending: true}, function(err, doc) {
console.log(doc.rows, doc.rows.length, 'show docs')
});
}function addTodo(text) {
var todo = {
_id: new Date().toISOString(),
title: text,
completed: false
};
db.put(todo, function callback(err, result) {
if (!err) {
console.log('Successfully posted a todo!', result);
showTodos()
}
else {
console.log(err, 'err')
}
});
}addTodo("testing todo")
db.changes({
since: 'now'
}).on('change', function (change) {
console.log('thats a change')
}).on('error', function (err) {
console.log('change error?')
});
```