@antr/purse
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Purse

Store things in PouchDB with ease.

Install

npm install @antris/purse

Usage

// PouchDB, uuid imported previously
import { db } from '@antris/purse';

// Pass your PouchDB to Purse
const myDb = db({ PouchDb, dbName: 'my-db'})

const myDoc = myDb.singleDoc({
    // function to find the document from PouchDB, also accepts a _id as a string
    findDoc: (doc) => doc.type === 'fruitPreferences',
    // function to create a new document if an existing document is not found
    createDoc: () => { return {
        _id: uuid(),
        type: 'fruitPreferences',
        likes: [],
        dislikes: []
    } }
})

// myDoc = { initialState: Promise, persist: (updatedDoc) => void }

Initial state

myDoc.initialState.then((doc) => {
    console.log(doc)
})

Persist data in PouchDB

After some editing, you might want to save the data. As long as you still have your myDoc available, you can simply call its persist function:

myDoc.persist(newDoc)

Purse keeps track of the _rev for you, so it is not required.

License

Licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @antr/purse

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

6.89 kB

Total Files

6

Last publish

Collaborators

  • antris