Created
January 10, 2013 07:21
-
-
Save davidcornu/4500178 to your computer and use it in GitHub Desktop.
Cradle - Response value variations
This file contains hidden or 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
{ | |
"dependencies": { | |
"async": "~0.1.22", | |
"cradle": "~0.6.4", | |
"colors": "~0.6.0-1" | |
} | |
} |
This file contains hidden or 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
require('colors'); | |
var async = require('async') | |
var cradle = require('cradle') | |
var db = (new cradle.Connection).database('cradle-test') | |
var q = [] | |
q.push(function(done){ db.create(done) }) | |
q.push(function(res, done){ | |
console.log('Test database created') | |
done() | |
}) | |
q.push(function(done){ | |
db.save('exists', {'ingredient': 'potatoes'}, function(err, res){ done(err) }) | |
}) | |
q.push(function(done){ | |
db.save('_design/food', { | |
'views': { | |
'by_ingredient': { | |
'map': 'function(doc){ emit(doc.ingredient, doc) }' | |
} | |
} | |
}, function(err, res){ done(err) }) | |
}) | |
q.push(function(done){ | |
console.log('With a single key'.green) | |
db.get('exists', function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('With a nonexistent single key'.green) | |
db.get('doesnotexist', function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('With multiple nonexistent keys'.green) | |
db.get(['doesnotexist', 'doesnotexisteither'], function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('With multiple keys, one nonexistent'.green) | |
db.get(['doesnotexist', 'exists'], function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('View with single key'.green) | |
db.view('food/by_ingredient', {key: 'exists'}, function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('View with single nonexistent key'.green) | |
db.view('food/by_ingredient', {key: 'doesnotexist'}, function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('View with multiple nonexistent keys'.green) | |
db.view('food/by_ingredient', {keys: ['doesnotexist', 'doesnotexisteither']}, function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
console.log('View with multiple keys, one nonexistent'.green) | |
db.view('food/by_ingredient', {keys: ['potatoes', 'doesnotexist']}, function(err, res){ | |
console.log({err: err, res: res}) | |
done() | |
}) | |
}) | |
q.push(function(done){ | |
db.destroy(done) | |
}) | |
q.push(function(res, done){ | |
console.log('Test database deleted') | |
done() | |
}) | |
async.waterfall(q, function(err){ | |
if (err) console.error(err) | |
console.log('Done') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output