Skip to content

Libraries to ease pouch-couch stack on offline first app

License

Notifications You must be signed in to change notification settings

eFishery/pouchy-store

Repository files navigation

Pouchy Store

Pouchy Store is a library to help developer create Offline First apps out of the box with synchronizing capabilities locally-remotely. Pouchy Store could be used for NodeJS/ReactJS and ReactNative. Pouchy Store built on top of PouchDB (local) and CouchDB (remote) stack.

How To Use

Install this library using npm i pouchy-store

Import PouchyStore from library in your Model Class

import {PouchyStore} from 'pouchy-store';
import config from '../config';

class ModelStore extends PouchyStore {
  get name() {
    return 'model';
  }

  get urlRemote() {
    return config.couchDBUrl;
  }

  get optionsRemote() {
    return {
      auth: config.couchDBAuth,
    };
  }
}

export default new ModelStore();

Use your model class in your app (React Example)

import ModelStore from './storage/modelstore';
import {UsePouchy} from 'pouchy-store';

const Home = props => {
    const [isInit, setInit] = useState(false);
    const leadInitializing = async () => {
        await ModelStore.initialize();
        await ModelStore.initializeRemote();
        setInit(true);
    };
    
    // you can use any options on couchDB query, and pouchDB-find
    // fetch-id used to force-update when option changes
    const [dataModel] = usePouchy(ModelStore, {
        selector: {
          _id: {
            $eq: 'someUUID',
          },
        },
        field: ['name','_id']
        limit: 10,
        sort: ['name'],
    }, 'fetch-id');
    
    useEffect(() => {
        if (!isInit) {
            initiate();
        }
    }, [isInit]);
    
    return (
        <SomeComponentWithFlatList dataForFlatList={dataModel}/>
    );
}

Available API for CRUD operation:

	/* manipulation of array data */
	addItem(payload)
	addItemWithId(id, payload)
	editItem(id, payload)
	deleteItem(id)

Code Example

Pouchy Store Example on React

Contributor

Dimas Gilang Saputra
Anshorimuslim

Credits

PouchDB
CouchDB
React Native SQLite Storage

License

MIT

About

Libraries to ease pouch-couch stack on offline first app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published