Are there any document storages on react native?
Asked Answered
A

5

8

It would be great to have something similar to PouchDB.

Current key-value storage (AsyncStorage) is definitely not enough to store and query data.

Aught answered 4/4, 2015 at 23:56 Comment(0)
D
6

You may be able to use asyncstorage-down with PouchDB. Normally the method for using LevelDOWN adapters in Node.js is like so:

var PouchDB = require('pouchdb');
var db = new PouchDB('mydb', {db: require('asyncstorage-down')})

I haven't tested this, though.

Edit: well lucky you; a lot of work has been put into this recently: pouchdb-async-storage. Expect a blog post soon about how to get this working.

Denote answered 2/5, 2015 at 19:8 Comment(2)
Is pouchdb-async-storage still being maintained? It looks like there hasn't been a commit in 6 months. I am heavily considering using this in a large scale react native app, but am a bit afraid of the pouchdb/react native compatibility issues i'm finding all over the webs.Edmon
(I'm the original author.) No, it's not super maintained. If I have some time, I'll probably go the SQLite route instead, i.e. github.com/nolanlawson/… combined with github.com/almost/react-native-sqlite (which might just work already, as a matter of fact).Denote
O
1

PouchDB is built for the browser, so it could probably work on React Native with a little effort.

Have you seen https://github.com/almost/react-native-sqlite ?

Onder answered 2/5, 2015 at 2:21 Comment(3)
Yes, I've seen. It's not a document storage.Aught
Might I ask what you can do with a doc store that you cannot do with SQLite?Onder
Store unstructured data and be able to search through collections of these data easily?Teacake
C
1

I had some Problems getting PouchDB working on react-native, but did not want to Install SQLLite. So I build an Adapter for Async Storage.

GitHub npm

It Polyfills the missing Packages for React + Added an async Storage adapter base on "asyncstorage-down". Properly that helps.

Crabbing answered 18/4, 2016 at 8:45 Comment(0)
P
1

I tried using Stockulus' async storage adaptor (https://github.com/stockulus/pouchdb-react-native) but had problems with replicating to a remote CouchDB server.

Now I am using React native SQLite Storage (https://github.com/andpor/react-native-sqlite-storage) and the PouchDB custom build pattern (https://pouchdb.com/2016/06/06/introducing-pouchdb-custom-builds.html) like this:

'use strict';

import PouchDB from 'pouchdb-core'

// POLYFILLS - adapted from https://github.com/pouchdb/pouchdb/issues/3787#issuecomment-234618747
global.Buffer = global.Buffer || require('buffer').Buffer;
global.atob = global.atob || require('atob');
global.btoa = global.btoa || require('btoa');
require('blob-polyfill');

import SQLite from 'react-native-sqlite-storage';
global.openDatabase = SQLite.openDatabase; // Expose for websql adapter
GLOBAL.openDatabase = SQLite.openDatabase;

PouchDB
    .plugin(require('pouchdb-adapter-websql'))
    .plugin(require('pouchdb-adapter-http'))
    .plugin(require('pouchdb-replication'))

export default PouchDB

I know the global is ugly. We just started using it and replication is working better. We also had to polyfill a bunch of node stuff. This is used by pouchdb-core but not specified as a dependancy in pouchdb-core. Would love feedback.

Currently using these packages:

"events": "^1.1.1",
"pouchdb-adapter-http": "6.0.6",
"pouchdb-adapter-websql": "6.0.6",
"pouchdb-core": "6.0.6",
"pouchdb-replication": "6.0.6",
"atob": "^2.0.3",
"blob-polyfill": "^1.0.20150320",
"btoa": "^1.1.2",
"buffer": "^5.0.0",

Thanks

Psalms answered 12/10, 2016 at 15:57 Comment(0)
T
0

You can easily implement PouchDB on top on SQLLite - it has several configuration choices. You may need a SQLite Plugin to make it work. I have done this for Cordova in fact and it worked quite well. I believe PouchDB (which is pure JavaScript and therefore can be used out-of-the-box for ReactNative) has an adapter that works with the full featured SQLite3 Plugin.

React Native version of this plugin is available here:

https://github.com/andpor/react-native-sqlite-storage

The original Cordova plugin link can be found on the project github as well.

Teacake answered 30/10, 2015 at 22:3 Comment(2)
I have to take this back. There seem to be a mariad of issues with require on JS side which renders PouchDB based solution not feasible right now.Teacake
some just published a React Native PouchDB module on npm what uses react-native-sqlite-storage as plugin. npmjs.com/package/react-native-pouchdbTeacake

© 2022 - 2024 — McMap. All rights reserved.