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.
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)
Dimas Gilang Saputra
Anshorimuslim
PouchDB
CouchDB
React Native SQLite Storage
MIT