Code Monkey home page Code Monkey logo

couchquery's Introduction

couchQuery

a simple couchdb module for nodejs

Install

npm install couchquery

require

var couch = require('couchquery');

setting

couch.set.hostname='localhost'    //Default
couch.set.port='5984'             //Default
couch.set.path='/'                //Default

save a document

couch.db('db_name').saveDoc(doc,callback) or couch.db('db_name').doc('doc_id').save(doc,callback)

For example

var doc={"title":"foo","author":"TongChia","content":"bar..","date":new Date()}
couch.db('articles').doc('CustomID').save(doc,function(obj){console.log(obj)})

Or use UUID created by default

couch.db('articles').saveDoc(doc,function(obj){console.log(obj)})

get a document

couch.db('db_name').doc('doc_id').get(callback) // return a object

For example working whit express

couch.db('articles').doc('uuid').get(function(object){res.render('blog', object)})

temporary view

couch.db('db_name').query(mapFun,reduceFun,callback)

For example

couch.db('articles').query('function(doc){emit(doc.date,doc.title)}',null,function(obj){res.send(obj)})

view

couch.db('db_name').view(viewName,keys,callback)

{String} viewName : 'design/view' {String/Array(2)/Object} keys : 'foo' / ['foo','bar'] / {"startkey":"2012/12/23","endkey":"2014/01/02","descending":true}

For example

couch.db('articles').view('list/date',['foo','bar'],function(obj){console.log(obj)})

Others

couch.allDbs(callback)

couch.newUUID(callback)

couch.db('db_name').info(callback)

couch.db('db_name').create(callback)

couch.db('db_name').remove(callback)

couch.db('db_name').allDocs(callback)

couch.db('db_name').createDoc(doc,callback)

couch.db('db_name').getDoc(docId,callback)

couch.db('db_name').doc('doc_id').remove(callback)

PS

All callback return an object

If it can not found database or doc return {"notFound":true}

If create database but exists return {"exist":true} you can choose delete or use it

Other failed return {"failed":true}

Sorry my english

Welcome suggestions

couchquery's People

Contributors

tongchia avatar

Watchers

 avatar  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.