pouchdb-adapters-rn
PouchDB adapter for ReactNative using HTTP (e.g. a remote CouchDB or CouchDB-like database) or SQLite as its data store.
This package has made changes in pouchdb-adapter-websql and pouch-adapter-http for compatibility with react-native.
It supports PouchDB till version 7.0.0
Prerequisites
- A SQLite module
- rn-fetch-blob
Installation
npm install --save-exact pouchdb-adapters-rnnpm install --save-exact react-native-sqlite-2@1.6.0npm install --save https://github.com/kkbhav/react-native-fetch-blob.git#workreact-native link rn-fetch-blobreact-native link react-native-sqlite-2
- Extra step for iOS
In Xcode, add libsqlite3.tbd
to your project's Build Phases
➜ Link Binary With Libraries
.
Usage
; var db = 'mydb' adapter: 'pouchdb-adapters-rn';// orvar remote = 'http://127.0.0.1:5984/mydb';// orvar remote1 = 'http://127.0.0.1:5984/mydb' adapter: 'pouchdb-adapters-rn-http';
- Updated API For RemoteDB
-
All API's calls will return attachment as base64(default) string or a file-uri
-
remote.getAttachment(docId, attachmentId, options, callback)
- extra options values(optional)
- path: string, Path to save the file(optional, if not passed base64 string will be returned)
- name: name of the file(optional, only used when file parameter is passed)
- extra options values(optional)
-
remote.get(docId, options, callback)
- extra options values(optional)
- path: string, Path to save the file(optional, if not passed base64 string will be returned)
- extra options values(optional)
-
remote.putAttachment(docId, attachmentId, [rev], attachment, type, [callback])
- attachment: file-uri or base64(cannot process blob types)
-
remote.put(doc) or remote.bulkDocs(docs)
- accepts file-uri or base64 in attachment data,
Example doc
const doc =_id: 'somethings'_attachments:'photo':'content-type': 'image/jpg''data': '/Users/pouch/image.jpg'remote; - accepts file-uri or base64 in attachment data,
- Updated API For LocalDB
-
All API's calls will return attachment as base64(default) string or a file-uri
-
db.getAttachment(docId, attachmentId, options, callback)
- extra options values(optional)
- path: boolean to return attachment as fileUri(optional, if not passed base64 string will be returned)
- extra options values(optional)
-
db.allDocs(options)
- extra options values(optional)
- path: boolean to return attachment as fileUri(optional, if not passed base64 string will be returned)
- extra options values(optional)
-
db.get(docId)
- will return attachment as base64 if requested
-
db.putAttachment(docId, attachmentId, [rev], attachment, type, [callback])
- attachment: file-uri or base64(cannot process blob types)
-
db.bulkDocs(docs)
- accepts path in attachment data, Example docs
const docs =_id: 'somethings'_attachments:'photo':'content-type': 'image/jpg''data': '/Users/pouch/image.jpg'db; -
db.put(doc)
- accepts path in attachment data, Example docs
const doc =_id: 'somethings'_attachments:'photo':'content-type': 'image/jpg''data': '/Users/pouch/image.jpg'db;
For full API documentation and guides on PouchDB, see PouchDB.com. For details on PouchDB sub-packages, see the Custom Builds documentation.
Supports PouchDB till version 7.0.0