Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

endyjasmi/feathers-pouchdb

Repository files navigation

feathers-pouchdb

Dependency Status Download Status

Create a PouchDB service for FeatherJS.

Installation

npm install pouchdb-core pouchdb-find pouchdb-adapter-leveldb feathers-pouchdb --save

Documentation

Please refer to the Feathers database adapter documentation for more details or directly at:

  • PouchDB - The detailed documentation for this adapter
  • Extending - How to extend a database adapter
  • Pagination and Sorting - How to use pagination and sorting for the database adapter
  • Querying - The common adapter querying mechanism

Limitation

  • Currently this plugin DOES NOT fully support pagination because of the way CouchDB Mango Query is designed to make use map reduce index. The skip and limit does work though, just not the total attribute though.

Complete Example

Here's an example of a Feathers server that uses feathers-pouchdb.

const PouchDBCore = require('pouchdb-core');
const PouchDBFind = require('pouchdb-find');
const PouchDBLevelDBAdapter = require('pouchdb-adapter-leveldb');
const feathers = require('feathers');
const rest = require('feathers-rest');
const hooks = require('feathers-hooks');
const bodyParser = require('body-parser');
const errorHandler = require('feathers-errors/handler');
const service = require('feathers-pouchdb');

const PouchDB = PouchDBCore.plugin(PouchDBLevelDBAdapter)
  .plugin(PouchDBFind);

// Initialize the application
const app = feathers()
  .configure(rest())
  .configure(hooks())
  // Needed for parsing bodies (login)
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({ extended: true }))
  // Initialize your feathers service
  .use('/messages', service({ Model: new PouchDB('./messages') }))
  .use(errorHandler());

app.listen(3030);

console.log('Feathers app started on 127.0.0.1:3030');

You can run this example and going to localhost:3030/messages. You should see an empty array. That's because you don't have any Todos yet but you now have full CRUD for your new messages service.

License

Copyright (c) 2017

Licensed under the MIT license.