https://github.com/mikeal/browsercouch
CouchDB in the browser
https://github.com/mikeal/browsercouch
Last synced: 2 months ago
JSON representation
CouchDB in the browser
- Host: GitHub
- URL: https://github.com/mikeal/browsercouch
- Owner: mikeal
- Created: 2009-10-12T00:19:32.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2010-04-20T19:37:41.000Z (about 15 years ago)
- Last Synced: 2025-03-29T11:41:36.552Z (3 months ago)
- Language: JavaScript
- Homepage: http://mikeal.github.com/browsercouch/
- Size: 386 KB
- Stars: 99
- Watchers: 6
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
BrowserCouch
============CouchDB in the browser - persistant, syncing client side storage.
Status
------I'm a few weeks away from what I'd call a 'stable' release. Please feel
free to fork or suggest improvements, but I'd hold off on using this
in a live setting until I can get some issues ironed out.Thanks,
Example
-------
###GET:var database = BrowserCouch('foo');
database.onload(function(){
database.get('bar', function(d){console.log(d)});
});
###SYNCdatabase.sync('http://localhost:5984/foo', {continuous:true});
###MAP REDUCEvar test_data = [
{_id : "0", hello : 'world'},
{_id : "1", chunky : 'monkey'},
{_id : "2", foo : 'bar'},
{_id : "3", black : 'hat'},
{_id : "4", black : 'tea'},
{_id : "5", words : 'two foo three'},
{_id : "6", words: 'two'}
];
var db = BrowserCouch('bar');
db.onload(function(){
db.put(test_data, function(){});
});
Some time later ...
var db = BrowserCouch('bar');
db.onload(function(){
db.view({
map : function(doc, emit){
if (doc.words){
var words = doc.words.split(" ");
for (var i = 0; i < words.length; i++)
emit(words[i], 1);
}
},
reduce : function(keys, values){
var sum = 0;
for (var i = 0; i < values.length; i++)
sum += values[i];
return sum;
},
finished : function(view){
console.log(view.findRow('two')); // Should emit 2
}
});
});
(See the unit tests for more examples)