couchdb-dispatcher
> Massive getter by ID for CouchDB, with multiple collections
Last updated 5 months ago by alkihis .
ISC · Original npm · Tarball · package.json
$ cnpm install couchdb-dispatcher 
SYNC missed versions from official npm registry.

couchdb-dispatcher

Massive getter by ID for CouchDB, with multiple collections

Getting started

In order to install, simply use npm.

npm i couchdb-dispatcher

Then, import it in you file.

import { Routes, Route } from 'couchdb-dispatcher';

Usage

Dispatcher can hold two differents use cases: Dispatch into differents collection according to IDs, or serve access to a collection with a specific URL.

Dispatch into collections

According to some ID patterns, you can choose in which collection you want to fetch from.

import { EndpointAccepters, Routes } from 'couchdb-dispatcher';


// Set accepters
const accepters: EndpointAccepters = {
    'crispr_1': function(id: string) {
        return id.match(/arbitary_pattern/i);
    },
    'crispr_2': /test/i,
    'crispr_3': (id: string) => id.includes('cc')
};

// Set URL
const database_url = "http://localhost:5984";

// Create object
const routes = new Routes(accepters, database_url);

// Create a route that listen to request
routes.set({
    method: 'POST',
    route: '/bulk',
    get_keys: function (request, response) {
        if (request.body.keys && Array.isArray(request.body.keys)) {
            // If ok, return an array of ID string
            return request.body.keys;
        }

        // Otherwise, return nothing
        response.status(400).json({ error: "Request is invalid" });
    },
    post_data: function (_, response, data) {
        // Return database response as HTTP response
        response.json(data);
    }
})

Current Tags

  • 1.3.5                                ...           latest (5 months ago)

13 Versions

  • 1.3.5                                ...           5 months ago
  • 1.3.4                                ...           5 months ago
  • 1.3.3                                ...           5 months ago
  • 1.3.2                                ...           6 months ago
  • 1.3.1                                ...           6 months ago
  • 1.3.0                                ...           6 months ago
  • 1.2.0                                ...           6 months ago
  • 1.1.1                                ...           7 months ago
  • 1.1.0                                ...           7 months ago
  • 1.0.3                                ...           7 months ago
  • 1.0.2                                ...           7 months ago
  • 1.0.1                                ...           7 months ago
  • 1.0.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |