1.0.2 • Published 3 years ago

@antr/purse v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago