Vue Pouch DB
Vue Pouch DB is a VueJS Plugin that binds PouchDB with Vue and keeps a synchronised state with the database. Has support for Mango queries which are processed locally within the VuePouchDB state.
Install
Install from NPM:
npm install vue-pouch-db --save
Usage
Import the Library and Install it into the Vue Instance
// Import the Library; // VuePouchDB InstanceVue;
Vue Pouch DB Bucket
The bucket is a global config object (schema), that you can set configurations globally or per database.
Currently the following keys are plugin specific, these keys have specific functionality in the Bucket Config Object:
- config
- plugins
- actions
// Bucket - Vue Pouch DB Config Object// This is a general and fast overview// How to define bucket initially in the instanceconst bucket = // Main config Object. This is the top level // config object. Where global config // are shared with each database. config: // Remote Server remote: "COUCHDB SERVER" // Is DB Remote Only?, default: false remoteOnly: false // db.allDocs({options}) allDocs: include_docs: true // new Pouch({options}) options: ajax: cache: true // Pouch.sync({option}) for every Instance sync: since: 0 live: true retry: true // db.changes({option}) changes: since: 'now' live: true include_docs: true // Global onChange events // for each database. // The functions here are passed to each DB // db.changes().on(() => {}) { console; } { console; } { console; } { console; } { console; } { console; } { // 'cancel' var is a function to be called // when something bad happens. It will // Cancel the watch event on CouchDB } // List of PouchDB plugins plugins: // Actions are shared across the // bucket instance. // Think of them as helper methods to bundle // several sets of commands into a single method. // Can be accessed through this.$bucket.[method name] actions: { // this is $bucket instance this _id: 'document_id' data: {} {}; } // Databases // You can define / instanciate // a per database config file. // this will put the database into the internal // state and also, you can define custom "options" // for the database Instance (on: new PouchDB(options)) _users: // Is remote only ? // The _users database lives only // in the server, so its only remote remoteOnly: true // 'projects' key -> Database Name, ex: couchdb.com/projects projects: // PouchDB.sync Options sync: push: // config for push pull: filter: 'projects/by_user' query_params: "name": "sadi" ; // Vue Application Startupconst app = // Include the Bucket Instance // into the root Vue application bucket methods: // Simple example how to delete a // document in CouchDB through VuePouchDB // Keep in mind, that the state is synced // and when the request is sent to couchdb // the state will update the object and // add the property _deleted: true { this$bucket; } ;
For more information regarding the configuration objects, please check PouchDB API
API
this.$bucket
Example
Vue;
this.dbsetup
Vue({ dbsetup: {} })
is a shorthand method to instantiate a database within
a component, or to have it referenced internally, without the need to
call a method or predefine it in the Bucket config object.
Example
Vue;
mapQueries({})
mapQueries is a functionality built on top of VuePouchDB, which takes the database state and filters it.
It mainly works with Mango queries, and uses sift library to do the querying of the documents.
Example
// Import mapQueries method; // Inside a Vue componentVue;
MIT License
Copyright (c) 2017 Sadi Qevani
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.