Giter Site home page Giter Site logo

dominicbarnes / node-couchdb-api Goto Github PK

View Code? Open in Web Editor NEW
43.0 4.0 10.0 1.23 MB

An async wrapper for the CouchDB API, following Node.JS conventions

Home Page: http://dbarnes.info/node-couchdb-api/

License: MIT License

JavaScript 99.97% Shell 0.03%

node-couchdb-api's Introduction

node-couchdb-api

This node.js module aims to provide a clean, asynchronous wrapper for the CouchDB API.

It uses callbacks that follow node.js conventions and aims to be as expressive as possible.

Installation

$ npm install couchdb-api

Usage

var couchdb = require("couchdb-api");

// connect to a couchdb server (defaults to http://localhost:5984)
var server = couchdb.srv();

// test it out!
server.info(function (err, response) {
console.log(response);

// should get { couchdb: "Welcome", version: "1.0.1" }
// if something went wrong, the `err` argument would provide the error that CouchDB provides
});

// select a database
var db = server.db("my-database");

db.info(function (err, response) {
console.log(response);

// should see the basic statistics for your test database
// if you chose a non-existant db, you'd get { error: "not_found", reason: "no_db_file" } in place of `err`
});

Refer to my website for documentation and resources.

Changelog

1.2.2

  • Fixing issues #17, #12 and #11

1.2.0

  • Complete documentation rewrite (now generated automatically via source code comments with dox)
  • Simplified the JSHint config by putting it into a single file at the root
  • Simplified the index.js entry-point. couchdb.srv() now only takes a single argument, a string URL.

1.1.5

  • Changed the package.json to allow for installs on node engine version 8

node-couchdb-api's People

Contributors

dancryer avatar dominicbarnes avatar pmanijak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-couchdb-api's Issues

Raw option

It would be useful to have the option to suppress a JSON parse on data returned from a database. I want to simply buffer the data and pass it on to others. If each NODE server that handles this has to decode and then stringify, well it is a lot of work for the server and not what is needed in every case.

tempView query argument doesn't work.

There are two related issues here:

First, db.tempView expects the query argument in args[2] instead of args[1].

Second, the query argument is not automatically encoded as a querystring, so it has to be passed as

var query = { "qs": { "key": JSON.stringify (["foo", "bar"]) } }

instead of:

var query = { "key": ["foo", "bar"] }

Some example code which illustrates this issue: https://gist.github.com/4518125

trouble using db.pull()

var couchdb = require('couchdb-api');
var user_pass = 'user:pass';
var dealscc = couchdb.srv(user_pass+'@ip','80');
var local_db = couchdb.srv(user_pass+'@localhost')

//local_db.allDbs();
var dbname = 'backoffice_app';
local_db.db(dbname)
    .pull(dealscc.db(dbname),
      function(err,data,resp){
          console.log(err + ' '+ data + ' ' + resp)
      })

the above code times out, i'm not sure what i'm doing wrong

Allow doc() instances to be initialized with a JSON string

Not so much of an issue as a feature request. Currently I have a JSON string containing data that I want represented as a couch document. With the current API that means parsing the JSON string into an object then iterating over every top-level key and setting its value on doc.body like so;

 var e = JSON.parse(data);
 var doc = db.doc();
 for (key in e) {
      doc.body[key] = e[key];
 };

It would be much more convenient if I could simply do this;

 var doc = db.doc(data);  // where 'data' is a JSON string, Buffer containing a JSON string or even a JSON object

problem with uploading streaming attachment

The combination of mime-type "application/json" and body ReadableStream results in an attachment containing the following:

{"path":"/tmp/TMPFILE","fd":null,"readable":true,"paused":false,"flags":"r","mode":438,"bufferSize":65536}

I don't think you are suppressing your content handlers when uploading streaming attachments.

Migrating node-couchdb-api to node 0.8.8+

We have a handful of apps that are using couchdb (and in particular, the node-couchdb-api module).

Unfortunately, trying to migrate from 0.6 (which worked well) to 0.8 failed. I traced the issue (at least for us) down to how authentication with the couchdb server was being handled. For some reason there was a leading square bracket ([) when the url was parsed.

With a little workaround to add in authentication after creation, everything seems to be working fine in 0.8!

Essentially, you just create the database server connection as if there is no authentication, then add the auth param to the server's url setter. Here's what we ended up doing.

var dbServer      = couchdb.srv(COUCHDB_HOST, COUCHDB_PORT, false, false);
dbServer.url      = {
  hostname: COUCHDB_HOST,
  port:     COUCHDB_PORT,
  protocol: COUCHDB_HTTP,
  auth:     COUCHDB_AUTH
};

We'd love to keep using couchdb and this module, but having things break when moving to the current stable version of node is a bit frustrating. Perhaps there's some MongoDB in our future, but until then hopefully this will help others migrate their couch apps, too. :)

API v1.1.1 returns unparsed string instead of object when querying list function

Hi!

I am querying a list function (http://dominicbarnes.us/node-couchdb-api/api/view/list.html) in my project and noticed that the behaviour changed from v1.0.0 to v1.1.1.
While the "response" in v1.0.0 returned an object, the "response" in v.1.1.1 contains the unparsed string.

1.0.0: Value: [object Object] - Typeof: object
1.1.1: Value: {"total":19790} - Typeof: string

Use this ddoc for testing:

{
   "_id": "_design/list-test",
   "language": "javascript",
   "views": {
       "view-func": {
           "map": "function(oDocument)\n{\nemit(oDocument._id, 1)\n}"
       }
   },
   "lists": {
       "list-func": "function(oHead, oViewRequest)\n{\n    var iTotalSum = 0;\n    while (oCurrRow = getRow())\n    {\n        iTotalSum += oCurrRow.value;\n    }\n\n    send(toJSON({total: iTotalSum}));\n}"
   }
}

and this script for executing with node:

var couchdb = require("couchdb-api");

/** default values: "localhost", 5984 **/
var server = couchdb.srv("localhost", 5984);

var db = server.db("database");

db.ddoc("list-test").view("view-func").list("list-func", function (err, response) {
    console.log("Value: "+response+" - Typeof: "+(typeof response));
});

Is this a bug or do i need to call it differently? The documentation says it should be an object (http://dominicbarnes.us/node-couchdb-api/api/callbacks.html)

Thx!

No license!

You should specify a license under which this is published :)

reconnect to changes on continuous feed

Presently, the library will disconnect when receiving "last_seq" from couchdb when listening to continuous changes, but it won't reconnect. It would be helpful if it did and save the user some code.

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.