GithubHelp home page GithubHelp logo

mgesmundo / feathers-couchdb2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lontongcorp/feathers-couchdb

0.0 2.0 0.0 18 KB

Feathers couchdb adapter service using node-cradle

License: MIT License

JavaScript 100.00%

feathers-couchdb2's Introduction

feathers-coucdb

Build Status

CouchDB CRUD service for FeathersJS using cradle

Installation

npm install cradle feathers-couchdb --save

Documentation

Please refer to the cradle for more details about connection options and Feathers database adapter.

Getting Started

Create CouchDB service:

var cradle = require('cradle');
var service = require('feathers-couchdb');

var app = feathers();

//var Connection = new(cradle.Connection)('http://192.168.1.79:5984');
var Connection = new(cradle.Connection)(
    'user.cloudant.com', 443,
    {
        secure: true,
        auth: {
            username: 'user',
            password: '<pass>'
        },
        cache: true
    }
);

var opts = {
  connection: Connection,
  Model: 'messages'
};

app.service('/messages', service(opts));

This will create a messages endpoint and connect to a local messages database. Each model represents each database in CouchDB that will created automatically if not exist.

Create Document

To insert new document(s), provide an array as body.

[{
	"name": "Luke Skywalker",
	"force": "light"
},{
	"name": "Han Solo",
	"force": "neutral"
},{
	"name": "Yoda",
	"force": "light"
}]

For single document, you can provide _id as key rather than generated uuid by CouchDB.

{
    "_id": "vader",
	"name": "Darth Vader",
	"force": "dark"
}

To update and delete you need this _id.

View

To add _design document for view query, create as normal Create Document with _id start with _design

{
    "_id": "_design/hero",
    "views": {
        "all": {
            "map": "function (doc) { if (doc.name) emit(doc.name, doc); }"
        }
    },
    "validate_doc_update": "function (newDoc, oldDoc, usrCtx) {if (! /^(light|dark|neutral)$/.test(newDoc.force)) throw({forbidden: {error: 'invalid value', reason: 'force must be dark, light, or neutral'}})}"
}

will create .view('_design/hero/_views/all') map-reduce function.

Query

To query data, simply FIND to _design document giving its namespace as param q

/messages/?q=hero/all

can also add other params as well $skip, $limit, $select

NOTE This plugin also provide non-designed view and try to create temporary view inside database. If _temp_view option is not available, like cloudant, this will create new view design and remove it immediately after. Please be aware this process slower than having saved design doc.

{
    "$skip": 0,
    "$limit": 10,
    "$select": ['name', 'force'],
    "$or": [
        { "force": 'light' },
        { "force": 'neutral' },
        {
          "name": {
            "$in": ['han','solo','yoda']
          }
        }
    ]
};

Limitation

$sort is not implemented yet.

Credits

Adapted from original works by FeathersJS team

License

Licensed under the MIT license.

feathers-couchdb2's People

Contributors

lontongcorp avatar

Watchers

James Cloos avatar Marcello Gesmundo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.