Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/efishery/pouchy-store

Libraries to ease pouch-couch stack on offline first app
https://github.com/efishery/pouchy-store

offline pouchdb react

Last synced: 2 months ago
JSON representation

Libraries to ease pouch-couch stack on offline first app

Awesome Lists containing this project

README

        

# Pouchy Store

Pouchy Store is a library to help developer create [Offline First](http://offlinefirst.org/) 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 (

);
}
```
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](https://github.com/eFishery/pouchy-store-example)

## Contributor

[Dimas Gilang Saputra](https://github.com/sumartoyo)
[Anshorimuslim](https://github.com/ans-4175)

## Credits

[PouchDB](https://pouchdb.com/)
[CouchDB](http://couchdb.apache.org/)
[React Native SQLite Storage](https://www.npmjs.com/package/react-native-sqlite-storage)

## License
MIT