-
-
Save dscape/e20560c9879efdcbc28c to your computer and use it in GitHub Desktop.
Support gist for http://writings.nunojob.com/2011/08/nano-minimalistic-couchdb-client-for-nodejs.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nano = require('nano')('http://localhost:5984'); | |
var db_name = "test"; | |
var db = nano.use(db_name); | |
function insert_doc(doc, tried) { | |
db.insert(doc, | |
function (error,http_headers,http_body) { | |
if(error) { | |
if(error.message === 'no_db_file' && tried < 1) { | |
// create database and retry | |
return nano.db.create(db_name, function () { | |
insert_doc(doc, tried+1); | |
}); | |
} | |
else { return console.log(error); } | |
} | |
console.log(http_body); | |
}); | |
} | |
insert_doc({nano: true}, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
, nano = require('nano')('http://localhost:5984') | |
, app = module.exports = express.createServer() | |
, db_name = "test" | |
, db = nano.use(db_name); | |
app.get("/", function(request,response) { | |
db.attachment.get("new", "logo.png").pipe(response); | |
}); | |
app.listen(3333); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nano = require('nano')('http://localhost:5984'); | |
var request = require('request'); | |
var db_name = "test"; | |
var db = nano.use(db_name); | |
// {} for empty body as parameter is required but will be piped in | |
request.get("http://nodejs.org/logo.png").pipe( | |
db.attachment.insert("new", "logo.png", {}, "image/png") | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nano = require('nano')('http://localhost:5984'); | |
nano.request({db: "_uuids"}, function(_,_,uuids){ console.log(uuids); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment