2 * jqCouchDB - jQuery plugin for couchdb connections
3 * @requires jQuery > v1.0.3
4 * @requires couchDB >= v0.7.0a5575
6 * http://protoblogr.net
8 * Copyright (c) 2007 Jerry Jalava (protoblogr.net)
9 * Dual licensed under the MIT and GPL licenses:
10 * http://www.opensource.org/licenses/mit-license.php
11 * http://www.gnu.org/licenses/gpl.html
20 var dbc = $.jqCouch.connection('db');
21 dbc.exists('database_name');
23 if ($.jqCouch.connection('db').create('database_name').ok) {
24 alert("database created");
29 var dc = $.jqCouch.connection('doc');
30 var rev = dc.get('database/document1')._rev;
32 var doc = {_id:"0",a:1,b:1};
33 if ($.jqCouch.connection('doc').save('database_name', doc)._id !== false) {
34 alert("Created document with rev: "+doc._rev+", a="+doc.a);
37 //Get all documents from database. (With cache)
38 var dc = $.jqCouch.connection('doc');
39 dc.update_config('cache', true);
40 if (var total_documents = dc.all('database_name').total_rows) {
41 var all_documents = dc.all('database_name').rows;
43 //Get all documents from database. (Without cache)
44 var dc = $.jqCouch.connection('doc');
45 var all = dc.all('database_name');
46 if (all.total_rows > 0) {
47 var all_documents = all.rows;
52 var vc = $.jqCouch.connection('view');
53 if (vc.exists('database_name', 'event') !== false) {
54 alert("View "event" exists");
57 if ($.jqCouch.connection('view').exists('database_name', 'event/all') !== false) {
58 alert("View "event/all" exists");
61 More examples can be found from the testsuite
67 * Generates new connection instance
68 * @param {String} type Connection type to initiate
69 * @param {Mixed}(String/Function) map_fun Global result mapping function (Optional)
70 * @param {Object} config Global configuration for connection (Optional)
71 * @returns Connection handler
74 function jqCouch_connection(type
, map_fun
, config
) {
75 var default_config
= {
79 this.id
= jQuery
.jqCouch
._generate_id();
81 this.map_fun
= map_fun
|| null;
83 this.config
= jQuery
.extend({}, default_config
, config
);
87 this.destroy = function() {
91 if (typeof eval('jqCouch_'+this.type
) == 'function') {
92 eval('var fn = eval(jqCouch_'+this.type
+'); handler = fn.apply(fn, [this.map_fun, config, this]);');
95 handler
.last_error
= typeof handler
.last_error
== 'undefined' ? {} : handler
.last_error
;
96 handler
.update_config = function(key
, value
) {
97 this.config
[key
] = value
;
100 handler
.last_results
= typeof handler
.last_results
== 'undefined' ? {} : handler
.last_results
;
101 handler
.purge_cache = function() {
102 handler
.last_results
= {};
112 * @param {Mixed}(String/Function) map_fun Global result mapping function (Optional)
113 * @param {Object} config Global configuration for connection (Optional)
114 * @param {Function} conn Connection constructor instance
115 * @see jqCouch_connection
116 * @returns Connection handler
119 function jqCouch_db(map_fun
, config
, conn
) {
120 var default_config
= {
123 this.config
= jQuery
.extend({}, default_config
, config
);
125 this.instance
= conn
;
128 this.exists = function(path
, mf
) {
129 if (typeof path
== 'undefined') {
130 var path
= this.config
.path
;
133 if (this.info(path
, mf
).db_name
) {
140 this.info = function(path
, mf
) {
141 if (typeof path
== 'undefined') {
142 var path
= this.config
.path
;
144 if (path
.substr(path
.length
-1,1) != '/') {
148 var map_fn
= mf
|| map_fun
;
152 var lr_key
= encodeURIComponent(path
).toString();
153 if ( typeof this.last_results
[lr_key
] != 'undefined'
154 && this.config
.cache
)
156 return this.last_results
[lr_key
];
160 url
: _self
.config
.server_url
+ path
,
162 global
: _self
.config
.ajax_setup
.global
,
163 cache
: _self
.config
.ajax_setup
.cache
,
166 contentType
: 'application/json',
167 error: function(req
) {
168 results
= jQuery
.extend({
170 }, jqCouch_map_error(req
));
171 _self
.last_error
= results
;
174 success: function(data
) {
175 results
= jqCouch_map_results(data
, map_fn
);
180 if (this.config
.cache
) {
181 this.last_results
[lr_key
] = results
;
187 this.create = function(path
, mf
) {
188 if (typeof path
== 'undefined') {
189 var path
= this.config
.path
;
191 if (path
.substr(path
.length
-1,1) != '/') {
195 var map_fn
= mf
|| map_fun
;
202 url
: _self
.config
.server_url
+ path
,
204 global
: _self
.config
.ajax_setup
.global
,
205 cache
: _self
.config
.ajax_setup
.cache
,
208 contentType
: 'application/json',
209 error: function(req
) {
210 results
= jQuery
.extend({
212 }, jqCouch_map_error(req
));
213 _self
.last_error
= results
;
216 success: function(data
) {
217 results
= jqCouch_map_results(data
, map_fn
);
225 this.del = function(path
, mf
) {
226 if (typeof path
== 'undefined') {
227 var path
= this.config
.path
;
229 if (path
.substr(path
.length
-1,1) != '/') {
233 var map_fn
= mf
|| map_fun
;
240 url
: _self
.config
.server_url
+ path
,
242 global
: _self
.config
.ajax_setup
.global
,
243 cache
: _self
.config
.ajax_setup
.cache
,
246 contentType
: 'application/json',
247 error: function(req
) {
248 results
= jQuery
.extend({
250 }, jqCouch_map_error(req
));
251 _self
.last_error
= results
;
254 success: function(data
) {
255 results
= jqCouch_map_results(data
, map_fn
);
263 this.all = function(mf
) {
268 var map_fn
= mf
|| map_fun
;
270 var lr_key
= encodeURIComponent(_self
.config
.server_url
+ '_all_dbs').toString();
271 if ( typeof this.last_results
[lr_key
] != 'undefined'
272 && this.config
.cache
)
274 return this.last_results
[lr_key
];
278 url
: _self
.config
.server_url
+ '_all_dbs',
280 global
: _self
.config
.ajax_setup
.global
,
281 cache
: _self
.config
.ajax_setup
.cache
,
284 contentType
: 'application/json',
285 error: function(req
) {
286 results
= jqCouch_map_error(req
);
287 _self
.last_error
= results
;
290 success: function(data
) {
291 results
= jqCouch_map_results(data
, map_fn
);
296 if (this.config
.cache
) {
297 this.last_results
[lr_key
] = results
;
303 this.restart = function(mf
) {
308 var map_fn
= mf
|| map_fun
;
311 url
: _self
.config
.server_url
+ '_restart',
313 global
: _self
.config
.ajax_setup
.global
,
315 error: function(req
) {
316 results
= jQuery
.extend({
318 }, jqCouch_map_error(req
));
319 _self
.last_error
= results
;
322 success: function(data
) {
323 results
= jqCouch_map_results(data
, map_fn
);
336 * Handles Doc actions
337 * @param {Mixed}(String/Function) map_fun Global result mapping function (Optional)
338 * @param {Object} config Global configuration for connection (Optional)
339 * @param {Function} conn Connection constructor instance
340 * @see jqCouch_connection
341 * @returns Connection handler
344 function jqCouch_doc(map_fun
, config
, conn
) {
345 var default_config
= {
348 this.config
= jQuery
.extend({}, default_config
, config
);
350 this.instance
= conn
;
353 this.get = function(path
, args
, mf
) {
354 if ( typeof path
== 'undefined'
357 var path
= this.config
.path
;
360 var map_fn
= mf
|| map_fun
;
366 path
+= jQuery
.jqCouch
._generate_query_str(args
);
368 var lr_key
= encodeURIComponent(path
).toString();
369 if ( typeof this.last_results
[lr_key
] != 'undefined'
370 && this.config
.cache
)
372 return this.last_results
[lr_key
];
376 url
: _self
.config
.server_url
+ path
,
378 global
: _self
.config
.ajax_setup
.global
,
379 cache
: _self
.config
.ajax_setup
.cache
,
382 contentType
: 'application/json',
383 error: function(req
) {
384 results
= jQuery
.extend({
386 }, jqCouch_map_error(req
));
387 _self
.last_error
= results
;
390 success: function(data
) {
391 results
= jqCouch_map_results(data
, map_fn
);
396 if (this.config
.cache
) {
397 this.last_results
[lr_key
] = results
;
403 this.all = function(path
, args
, mf
) {
404 if ( typeof path
== 'undefined'
407 var path
= this.config
.path
;
409 if (path
.substr(path
.length
-1,1) != '/') {
413 path
+= jQuery
.jqCouch
._generate_query_str(args
);
415 var map_fn
= mf
|| map_fun
;
421 var lr_key
= encodeURIComponent(path
).toString();
422 if ( typeof this.last_results
[lr_key
] != 'undefined'
423 && this.config
.cache
)
425 return this.last_results
[lr_key
];
429 url
: _self
.config
.server_url
+ path
,
431 global
: _self
.config
.ajax_setup
.global
,
432 cache
: _self
.config
.ajax_setup
.cache
,
435 contentType
: 'application/json',
436 error: function(req
) {
437 results
= jQuery
.extend({
439 }, jqCouch_map_error(req
));
440 _self
.last_error
= results
;
443 success: function(data
) {
444 results
= jqCouch_map_results(data
, map_fn
);
449 if (this.config
.cache
) {
450 this.last_results
[lr_key
] = results
;
456 this.bulk_save = function(path
, data
, args
, mf
) {
457 if ( typeof path
== 'undefined'
460 var path
= this.config
.path
;
462 if (path
.substr(path
.length
-1,1) != '/') {
465 path
+= '_bulk_docs';
466 path
+= jQuery
.jqCouch
._generate_query_str(args
);
468 var map_fn
= mf
|| map_fun
;
476 url
: _self
.config
.server_url
+ path
,
478 global
: _self
.config
.ajax_setup
.global
,
479 cache
: _self
.config
.ajax_setup
.cache
,
482 contentType
: 'application/json',
483 data
: jQuery
.jqCouch
.toJSON(data
),
485 error: function(req
) {
486 results
= jQuery
.extend({
488 }, jqCouch_map_error(req
));
489 _self
.last_error
= results
;
492 success: function(data
) {
493 results
= jqCouch_map_results(data
, map_fn
);
501 this.save = function(path
, data
, mf
) {
502 if ( typeof path
== 'undefined'
505 var path
= this.config
.path
;
507 if (path
.substr(path
.length
-1,1) != '/') {
511 var map_fn
= mf
|| map_fun
;
514 if ( typeof data
._id
== 'undefined'
517 results
= this.post(path
, data
, mf
);
519 results
= this.put(path
+ data
._id
, data
, map_fn
);
525 data
._id
= results
.id
;
526 data
._rev
= results
.rev
;
532 this.post = function(path
, data
, mf
) {
533 if ( typeof path
== 'undefined'
536 var path
= this.config
.path
;
539 var map_fn
= mf
|| map_fun
;
546 url
: _self
.config
.server_url
+ path
,
548 global
: _self
.config
.ajax_setup
.global
,
549 cache
: _self
.config
.ajax_setup
.cache
,
552 contentType
: 'application/json',
553 data
: jQuery
.jqCouch
.toJSON(data
),
555 error: function(req
) {
556 results
= jQuery
.extend({
558 }, jqCouch_map_error(req
));
559 _self
.last_error
= results
;
562 success: function(data
) {
563 results
= jqCouch_map_results(data
, map_fn
);
571 this.put = function(path
, data
, mf
) {
572 if ( typeof path
== 'undefined'
575 var path
= this.config
.path
;
578 var map_fn
= mf
|| map_fun
;
585 url
: _self
.config
.server_url
+ path
,
587 data
: jQuery
.jqCouch
.toJSON(data
),
589 global
: _self
.config
.ajax_setup
.global
,
590 cache
: _self
.config
.ajax_setup
.cache
,
593 contentType
: 'application/json',
594 error: function(req
) {
595 results
= jQuery
.extend({
597 }, jqCouch_map_error(req
));
598 _self
.last_error
= results
;
601 success: function(data
) {
602 results
= jqCouch_map_results(data
, map_fn
);
610 this.del = function(path
, doc_or_rev
, mf
) {
611 if ( typeof path
== 'undefined'
614 var path
= this.config
.path
;
616 if ( typeof doc_or_rev
== 'object'
617 && typeof doc_or_rev
._id
!= 'undefined'
618 && typeof doc_or_rev
._rev
!= 'undefined')
620 if (path
.substr(path
.length
-1,1) != '/') {
623 path
+= doc_or_rev
._id
;
624 path
+= '?rev=' + doc_or_rev
._rev
;
626 if (typeof doc_or_rev
== 'string') {
627 path
+= '?rev=' + doc_or_rev
;
630 var map_fn
= mf
|| map_fun
;
637 url
: _self
.config
.server_url
+ path
,
639 global
: _self
.config
.ajax_setup
.global
,
640 cache
: _self
.config
.ajax_setup
.cache
,
643 contentType
: 'application/json',
644 error: function(req
) {
645 results
= jQuery
.extend({
647 }, jqCouch_map_error(req
));
648 _self
.last_error
= results
;
651 success: function(data
) {
652 results
= jqCouch_map_results(data
, map_fn
);
657 if ( typeof doc_or_rev
== 'object'
660 doc_or_rev
._rev
= results
.rev
;
661 doc_or_rev
._deleted
= true;
672 * Handles View actions
673 * @param {Mixed}(String/Function) map_fun Global result mapping function (Optional)
674 * @param {Object} config Global configuration for connection (Optional)
675 * @param {Function} conn Connection constructor instance
676 * @see jqCouch_connection
677 * @returns Connection handler
680 function jqCouch_view(map_fun
, config
, conn
) {
681 var default_config
= {
683 language
: "text/javascript"
685 this.config
= jQuery
.extend({}, default_config
, config
);
687 this.instance
= conn
;
690 //TODO: add chance to create if doesnt exist
691 this.exists = function(path
, view
, mf
) {
692 if (typeof path
== 'undefined') {
693 var path
= this.config
.path
;
696 if (typeof view
== 'undefined') {
700 if (this.info(path
, view
, mf
).views
) {
707 this.info = function(path
, view
, mf
) {
712 if (typeof view
== 'undefined') {
716 if (typeof path
== 'undefined') {
717 var path
= this.config
.path
;
719 if (path
.substr(path
.length
-1,1) != '/') {
724 var view_parts
= false;
725 if (view
.toString().match(/\//)) {
726 view_parts
= view
.split("/");
727 path
+= view_parts
[0];
732 path
+= '?revs_info=true';
734 var map_fn
= mf
|| map_fun
;
736 var lr_key
= encodeURIComponent(path
).toString();
737 if ( typeof this.last_results
[lr_key
] != 'undefined'
738 && this.config
.cache
)
740 return this.last_results
[lr_key
];
744 url
: _self
.config
.server_url
+ path
,
746 global
: _self
.config
.ajax_setup
.global
,
747 cache
: _self
.config
.ajax_setup
.cache
,
750 contentType
: 'application/json',
751 error: function(req
) {
752 results
= jQuery
.extend({
755 }, jqCouch_map_error(req
));
756 _self
.last_error
= results
;
759 success: function(data
) {
761 && typeof data
.views
[view_parts
[1]] == 'undefined')
765 results
= jqCouch_map_results(data
, map_fn
);
766 if (typeof results
['views'] == 'undefined') {
767 results
['views'] = false;
773 if (this.config
.cache
) {
774 this.last_results
[lr_key
] = results
;
780 this.get = function(path
, name
, args
, mf
) {
785 if ( typeof path
== 'undefined'
788 var path
= this.config
.path
;
790 if (path
.substr(path
.length
-1,1) != '/') {
793 if (! path
.toString().match(/_view\//)) {
797 if (typeof name
== 'undefined') {
801 if (! name
.toString().match(/\//)) {
806 var map_fn
= mf
|| map_fun
;
808 path
+= jQuery
.jqCouch
._generate_query_str(args
);
810 var lr_key
= encodeURIComponent(path
).toString();
811 if ( typeof this.last_results
[lr_key
] != 'undefined'
812 && this.config
.cache
)
814 return this.last_results
[lr_key
];
818 url
: _self
.config
.server_url
+ path
,
820 global
: _self
.config
.ajax_setup
.global
,
821 cache
: _self
.config
.ajax_setup
.cache
,
824 contentType
: 'application/json',
825 error: function(req
) {
826 results
= jQuery
.extend({
828 }, jqCouch_map_error(req
));
829 _self
.last_error
= results
;
832 success: function(data
) {
833 results
= jqCouch_map_results(data
, map_fn
);
838 if (this.config
.cache
) {
839 this.last_results
[lr_key
] = results
;
845 this.save = function(path
, data
, mf
) {
849 if (typeof data
!= 'object') {
853 if ( typeof path
== 'undefined'
856 var path
= this.config
.path
;
858 if (path
.substr(path
.length
-1,1) != '/') {
862 if (typeof data
._id
== 'undefined') {
866 if (! data
._id
.toString().match(/_design/)) {
867 data
._id
= '_design/' + data
._id
;
870 if (typeof data
['language'] == 'undefined') {
871 data
.language
= this.config
.language
;
874 for (var name
in data
.views
) {
875 if (typeof(data
.views
[name
]['toSource']) == 'function') {
876 data
.views
[name
] = data
.views
[name
].toSource();
878 data
.views
[name
] = data
.views
[name
].toString();
882 results
= this.put(path
+ data
._id
, data
, mf
);
887 data
._id
= results
.id
;
888 data
._rev
= results
.rev
;
894 this.put = function(path
, data
, mf
) {
895 if ( typeof path
== 'undefined'
898 var path
= this.config
.path
;
901 var map_fn
= mf
|| map_fun
;
908 url
: _self
.config
.server_url
+ path
,
910 data
: jQuery
.jqCouch
.toJSON(data
),
912 global
: _self
.config
.ajax_setup
.global
,
913 cache
: _self
.config
.ajax_setup
.cache
,
916 contentType
: 'application/json',
917 error: function(req
) {
918 results
= jQuery
.extend({
920 }, jqCouch_map_error(req
));
921 _self
.last_error
= results
;
924 success: function(data
) {
925 results
= jqCouch_map_results(data
, map_fn
);
933 this.del = function(path
, doc_or_rev
, mf
) {
934 if ( typeof path
== 'undefined'
937 var path
= this.config
.path
;
939 if ( typeof doc_or_rev
== 'object'
940 && typeof doc_or_rev
._id
!= 'undefined'
941 && typeof doc_or_rev
._rev
!= 'undefined')
943 if (path
.substr(path
.length
-1,1) != '/') {
946 path
+= doc_or_rev
._id
;
947 path
+= '?rev=' + doc_or_rev
._rev
;
949 if (typeof doc_or_rev
== 'string') {
950 path
+= '?rev=' + doc_or_rev
;
953 var map_fn
= mf
|| map_fun
;
960 url
: _self
.config
.server_url
+ path
,
962 global
: _self
.config
.ajax_setup
.global
,
963 cache
: _self
.config
.ajax_setup
.cache
,
966 contentType
: 'application/json',
967 error: function(req
) {
968 results
= jQuery
.extend({
970 }, jqCouch_map_error(req
));
971 _self
.last_error
= results
;
974 success: function(data
) {
975 results
= jqCouch_map_results(data
, map_fn
);
980 if ( typeof doc_or_rev
== 'object'
983 doc_or_rev
._rev
= results
.rev
;
984 doc_or_rev
._deleted
= true;
990 this.temp = function(path
, map
, args
, mf
) {
991 if ( typeof path
== 'undefined'
994 var path
= this.config
.path
;
996 if (path
.substr(path
.length
-1,1) != '/') {
999 path
+= '_temp_view';
1000 path
+= jQuery
.jqCouch
._generate_query_str(args
);
1002 var lr_key
= encodeURIComponent(path
).toString();
1003 if ( typeof this.last_results
[lr_key
] != 'undefined'
1004 && this.config
.cache
)
1006 return this.last_results
[lr_key
];
1009 var map_fn
= mf
|| map_fun
;
1011 if (typeof map
== 'string') {
1015 if (typeof map
['toSource'] == 'function') {
1016 map
= map
.toSource();
1018 map
= map
.toString();
1026 url
: _self
.config
.server_url
+ path
,
1028 global
: _self
.config
.ajax_setup
.global
,
1029 cache
: _self
.config
.ajax_setup
.cache
,
1033 contentType
: 'application/javascript',
1035 error: function(req
) {
1036 results
= jQuery
.extend({
1038 }, jqCouch_map_error(req
));
1039 _self
.last_error
= results
;
1042 success: function(data
) {
1043 results
= jqCouch_map_results(data
, map_fn
);
1048 if (this.config
.cache
) {
1049 this.last_results
[lr_key
] = results
;
1060 * Default result wrapper
1061 * @param {Object} data Results from query
1062 * @param {Mixed}(String/Function) map result mapping function (Optional)
1063 * @see jqCouch_db, jqCouch_doc, jqCouch_view
1064 * @returns Finished results
1067 function jqCouch_map_results(data
, map
) {
1068 if (typeof map
== 'undefined') {
1072 if (typeof map
== 'function') {
1073 var res
= map
.apply(map
, [data
]);
1074 return jQuery
.extend({}, res
|| {});
1077 if (typeof map
== 'string') {
1078 var fn
= eval('('+map
+')');
1079 var res
= fn
.apply(fn
, [data
]);
1080 return jQuery
.extend({}, res
|| {});
1083 return (data
|| {});
1088 * Default error wrapper
1089 * @param {Object} req XHR Request object
1090 * @see jqCouch_db, jqCouch_doc, jqCouch_view
1091 * @returns Rendered error
1094 function jqCouch_map_error(req
) {
1097 response
: eval("(" + req
.responseText
+ ")")
1105 _connection_types
: [
1119 _generate_id: function() {
1120 var rk
= Math
.floor(Math
.random()*4013);
1121 return (10016486 + (rk
* 22423));
1124 _generate_query_str: function(qa
) {
1126 if (typeof qa
!= 'undefined') {
1128 $.each(qa
, function(k
,v
){
1129 qs
+= k
+ '=' + v
+ '&';
1131 qs
= qs
.substr(0, qs
.length
-1);
1137 parseJSON: function(json_str
) {
1139 return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
1140 json_str
.replace(/"(\\.|[^"\\])*"/g, ''))) &&
1141 eval('(' + json_str
+ ')');
1146 toJSON: function (item
, item_type
) {
1158 var a
= ['['], b
, f
, i
, l
= x
.length
, v
;
1159 for (i
= 0; i
< l
; i
+= 1) {
1162 if (typeof v
== 'string') {
1173 bool: function (x
) {
1180 return isFinite(x
) ? String(x
) : 'null';
1184 if (x
instanceof Array
) {
1187 var a
= ['{'], b
, f
, i
, v
;
1191 if (typeof v
== 'string') {
1195 a
.push(s
.str(i
), ':', v
);
1205 if (/["\\\x00-\x1f]/.test(x
)) {
1206 x
= x
.replace(/([\x00-\x1f\\"])/g, function(a
, b
) {
1213 Math
.floor(c
/ 16).toString(16) +
1214 (c
% 16).toString(16);
1217 return '"' + x
+ '"';
1220 var conv = function (x
) {
1221 var itemtype
= typeof x
;
1244 var itemtype
= item_type
|| typeof item
;
1262 return s
.bool(item
);
1265 throw("Unknown type for $.jqcouch.toJSON");
1271 * Defines globally used default settings for jqCouch
1272 * @param {Object} defaults Config dictionary
1273 * @see $.jqCouch._default_config
1275 set_defaults: function(defaults
) {
1276 $.jqCouch
._default_config
= $.extend({}, $.jqCouch
._default_config
, defaults
|| {});
1281 * Initiates new connection and returns it.
1282 * Possible parameter combinations:
1283 * type OR type, map_fun OR type, config OR type, map_fun, config
1284 * @param {String} type Type of connection to initiate
1285 * @param {Mixed}(String/Function) map_fun Global result mapping function
1286 * @param {Object} config Global configuration for connection
1287 * @see jqCouch_connection
1288 * @returns Connection handler
1291 connection: function() {
1292 if (arguments
.length
<= 0) {
1296 if (typeof $.jqCouch
._connections
!= 'object') {
1297 $.jqCouch
._connections
= {};
1302 var user_config
= {};
1304 if ($.inArray(arguments
[0], $.jqCouch
._connection_types
) != -1) {
1305 type
= arguments
[0];
1310 if (arguments
.length
> 1) {
1311 if (typeof arguments
[1] == 'object') {
1312 user_config
= arguments
[1];
1314 map_fun
= arguments
[1];
1318 if ( arguments
.length
== 3
1319 && typeof arguments
[2] == 'object')
1321 user_config
= arguments
[2];
1324 var config
= $.extend({}, $.jqCouch
._default_config
, user_config
);
1326 var connection
= new jqCouch_connection(type
, map_fun
, config
);
1327 if (! connection
.instance
.inited
) {
1331 $.jqCouch
._connections
[connection
.id
] = connection
;
1336 destroy_connection: function(id
) {
1337 if ( typeof $.jqCouch
._connections
[id
] != 'undefined'
1338 || $.jqCouch
._connections
[id
] != 'null')
1340 $.jqCouch
._connections
[id
].destroy();
1341 $.jqCouch
._connections
[id
] = null;
1343 $.jqCouch
._connections
= $.grep($.jqCouch
._connections
, function(n
,i
){