2 * couchdb.js - couchdb interface
4 * author: hackbard@hackdaworld.org
13 init: function(type,host,port,prefix) {
20 if(prefix!==undefined)
21 couchdb.prefix=prefix;
23 cdb_xhr: function(type,url,data,cb) {
27 success: function(ret) {
28 var ro=JSON.parse(ret);
32 cl("couchdb: exists - "+
36 cl("couchdb: not found"+
40 cl("couchdb: error - "+
46 cl("couchdb: xhr success - "+url);
51 error: function(xhr,stat,err) {
52 cl("conn: "+url+", error: "+err+
54 cl("executing callback anyways ...");
58 if((data!==undefined)&&(data!==null))
59 ao.data=JSON.stringify(data);
62 item_count: function(db,callback) {
63 var url=couchdb.type+"://"+couchdb.host+":"+couchdb.port+"/"+
64 couchdb.prefix+db+"/_all_docs?limit=0";
65 couchdb.cdb_xhr('GET',url,null,function(ret) {
66 callback(ret.total_rows);
69 get_item: function(db,key,callback) {
70 var url=couchdb.type+"://"+couchdb.host+":"+couchdb.port+"/"+
71 couchdb.prefix+db+"/"+key;
72 couchdb.cdb_xhr('GET',url,null,function(ret) {
76 get_db: function(db,callback) {
77 var url=couchdb.type+"://"+couchdb.host+":"+couchdb.port+"/"+
78 couchdb.prefix+db+"/_all_docs?include_docs=true";
79 couchdb.cdb_xhr('GET',url,null,function(ret) {
83 add_item: function(db,key,data,callback) {
84 var url=couchdb.type+"://"+couchdb.host+":"+couchdb.port+"/"+
85 couchdb.prefix+db+"/"+k;
86 couchdb.cdb_xhr('PUT',url,data,function(ret) {