Skip to content

🐨 - PouchDB is a pocket-sized database, with some patches for running on React Native

License

Notifications You must be signed in to change notification settings

caffpain/pouchdb-react-native

 
 

Repository files navigation

PouchDB for React Native

Build Status Coverage Status Greenkeeper badge npm version jsDelivr Hits

A PouchDB fork for React Native with binary attachments support.

Using PouchDB

Check out a small example.

Install

  1. Install dev package:

    yarn add -D babel-plugin-module-resolver
    
  2. Install polyfill packages:

    yarn add events process base-64 react-native-get-random-values react-native-quick-md5
  3. Install pouchdb packages:

    yarn add @craftzdog/pouchdb-core-react-native @craftzdog/pouchdb-binary-utils-react-native pouchdb-adapter-http pouchdb-mapreduce pouchdb-replication react-native-pouchdb-md5

    Note: @craftzdog/pouchdb-replication-react-native is no longer needed.

  4. Install storage adapter packages:

    yarn add pouchdb-adapter-react-native-sqlite react-native-sqlite-2
  5. Install CocoaPods:

    cd ios && pod install

Configure

  1. Make a shim.js:

    import "react-native-get-random-values";
    import { decode, encode } from "base-64";
    
    if (typeof process === "undefined") {
      global.process = require("process");
    } else {
      const bProcess = require("process");
      for (var p in bProcess) {
        if (!(p in process)) {
          process[p] = bProcess[p];
        }
      }
    }
    
    if (!global.btoa) {
      global.btoa = encode;
    }
    
    if (!global.atob) {
      global.atob = decode;
    }
    
    process.browser = true;

    then, require it at the beginning of your index.js.

  2. Edit your babel.config.js like so:

    module.exports = {
      presets: ['module:metro-react-native-babel-preset'],
      plugins: [
        [
          'module-resolver',
          {
            alias: {
              'pouchdb-md5': 'react-native-pouchdb-md5',
              'pouchdb-binary-utils':
                '@craftzdog/pouchdb-binary-utils-react-native',
            },
          },
        ],
      ],
    };
    

See also

Contributing

We're always looking for new contributors! If you'd like to try your hand at writing code, writing documentation, designing the website, writing a blog post, or answering questions on StackOverflow, then we'd love to have your input.

If you have a pull request that you'd like to submit, please read the contributing guide for info on style, commit message format, and other (slightly!) nitpicky things like that. PouchDB is heavily tested, so you'll also want to check out the testing guide.

About

🐨 - PouchDB is a pocket-sized database, with some patches for running on React Native

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.6%
  • HTML 0.5%
  • Shell 0.5%
  • Java 0.3%
  • Objective-C 0.1%
  • Ruby 0.0%