leanback 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +5 -6
- data/Gemfile.lock +65 -14
- data/README.md +465 -33
- data/Rakefile +8 -17
- data/VERSION +1 -1
- data/leanback.gemspec +26 -85
- data/lib/leanback.rb +129 -587
- data/spec/leanback_spec.rb +356 -0
- metadata +40 -117
- data/Changelog.rdoc +0 -146
- data/documentation/static/2011/11/20/i-moved-leanback-documentation/index.html +0 -180
- data/documentation/static/2011/11/20/index.html +0 -146
- data/documentation/static/2011/11/index.html +0 -146
- data/documentation/static/2011/index.html +0 -146
- data/documentation/static/2013/06/02/index.html +0 -146
- data/documentation/static/2013/06/02/released-leanback-v0-3-4/index.html +0 -180
- data/documentation/static/2013/06/09/index.html +0 -146
- data/documentation/static/2013/06/09/released-leanback-v0-4-0/index.html +0 -179
- data/documentation/static/2013/06/index.html +0 -158
- data/documentation/static/2013/index.html +0 -158
- data/documentation/static/author/admin/index.html +0 -175
- data/documentation/static/basic-couchdb-operations/index.html +0 -259
- data/documentation/static/category/uncategorized/index.html +0 -170
- data/documentation/static/couchdb-configuration/index.html +0 -189
- data/documentation/static/couchdb-security/index.html +0 -218
- data/documentation/static/count-by-multiple-documents/index.html +0 -221
- data/documentation/static/count-documents-by-key/index.html +0 -177
- data/documentation/static/css/2c-l-fixed.css +0 -1
- data/documentation/static/css/2c-l-fixed.dev.css +0 -62
- data/documentation/static/css/2c-r-fixed.css +0 -1
- data/documentation/static/css/2c-r-fixed.dev.css +0 -60
- data/documentation/static/css/3c-c-fixed.css +0 -1
- data/documentation/static/css/3c-c-fixed.dev.css +0 -84
- data/documentation/static/css/3c-l-fixed.css +0 -1
- data/documentation/static/css/3c-l-fixed.dev.css +0 -61
- data/documentation/static/css/3c-r-fixed.css +0 -1
- data/documentation/static/css/3c-r-fixed.dev.css +0 -62
- data/documentation/static/css/holy-grail-fluid.css +0 -5
- data/documentation/static/css/plugins.css +0 -5
- data/documentation/static/css/print.css +0 -5
- data/documentation/static/css/screen.css +0 -1
- data/documentation/static/design-documents-and-permanent-views/index.html +0 -454
- data/documentation/static/error-handling/index.html +0 -157
- data/documentation/static/find-document-by-multiple-keys/index.html +0 -269
- data/documentation/static/find-documents-by-key/index.html +0 -243
- data/documentation/static/index.html +0 -161
- data/documentation/static/leanback/index.html +0 -130
- data/documentation/static/leanback/installation/index.html +0 -119
- data/documentation/static/setting-the-bind_address-port/index.html +0 -151
- data/documentation/static/style.css +0 -16
- data/spec/admin_party/database_spec.rb +0 -400
- data/spec/no_admin_party/cloudant_spec.rb +0 -365
- data/spec/no_admin_party/database_spec.rb +0 -491
- data/spec/no_admin_party/non_admin_user_spec.rb +0 -67
- data/test/helper.rb +0 -18
- data/test/main.rb +0 -295
- data/test/my_view.json +0 -8
- data/test/my_views.json +0 -8
- data/test/start.json +0 -8
- data/test/test_leanback.rb +0 -319
- data/test/view_age.json +0 -8
@@ -1,221 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en-US">
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
5
|
-
<title>Count documents by multiple keys</title>
|
6
|
-
|
7
|
-
<link rel="stylesheet" href="http://www.whisperservers.com/leanback/wp-content/themes/hybrid/style.css" type="text/css" media="all" />
|
8
|
-
<link rel="profile" href="http://gmpg.org/xfn/11" />
|
9
|
-
<link rel="pingback" href="http://www.whisperservers.com/leanback/xmlrpc.php" />
|
10
|
-
|
11
|
-
<meta name="generator" content="WordPress 3.5.1 - really-static 0.5" />
|
12
|
-
<meta name="template" content="Hybrid 1.0" />
|
13
|
-
<meta name="robots" content="index,follow" />
|
14
|
-
<meta name="author" content="admin" />
|
15
|
-
<meta name="copyright" content="Copyright (c) June 2013" />
|
16
|
-
<meta name="revised" content="Sunday, June 9th, 2013, 3:49 pm" />
|
17
|
-
<link rel="alternate" type="application/rss+xml" title="Leanback » Feed" href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/feed/" />
|
18
|
-
|
19
|
-
<link rel="alternate" type="application/rss+xml" title="Leanback » Count documents by multiple keys Comments Feed" href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/feed/" />
|
20
|
-
<script type='text/javascript' src='http://www.whisperservers.com/leanback/wp-includes/js/comment-reply.min.js?ver=3.5.1'></script>
|
21
|
-
<script type='text/javascript' src='http://www.whisperservers.com/leanback/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>
|
22
|
-
<link rel='prev' title='Find document by multiple Keys' href='http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-document-by-multiple-keys/' />
|
23
|
-
<link rel='canonical' href='http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/' />
|
24
|
-
|
25
|
-
<link rel="stylesheet" href="http://www.whisperservers.com/leanback/wp-content/plugins/wp-syntax/wp-syntax.css" type="text/css" media="screen" />
|
26
|
-
|
27
|
-
</head>
|
28
|
-
|
29
|
-
<body class="wordpress ltr en_US parent-theme y2013 m06 d09 h16 sunday logged-out singular singular-page singular-page-173 page-template-default page-173 primary-active secondary-inactive subsidiary-inactive">
|
30
|
-
|
31
|
-
|
32
|
-
<div id="body-container">
|
33
|
-
|
34
|
-
|
35
|
-
<div id="header-container">
|
36
|
-
|
37
|
-
<div id="header">
|
38
|
-
|
39
|
-
<div id="site-title"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/" title="Leanback" rel="home"><span>Leanback</span></a></div>
|
40
|
-
<div id="site-description"><span>Simple Ruby interface to CouchDB</span></div>
|
41
|
-
|
42
|
-
</div><!-- #header -->
|
43
|
-
|
44
|
-
</div><!-- #header-container -->
|
45
|
-
|
46
|
-
|
47
|
-
<div id="container">
|
48
|
-
|
49
|
-
|
50
|
-
<div id="content" class="hfeed content">
|
51
|
-
|
52
|
-
<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail"><span class="trail-before"><span class="breadcrumb-title">Browse:</span></span> <a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/" title="Leanback" rel="home" class="trail-begin">Home</a> <span class="sep">/</span> <span class="trail-end">Count documents by multiple keys</span></div></div>
|
53
|
-
|
54
|
-
<div id="post-173" class="hentry page publish post-1 odd author-admin">
|
55
|
-
|
56
|
-
<h1 class="page-title entry-title"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/" title="Count documents by multiple keys" rel="bookmark">Count documents by multiple keys</a></h1>
|
57
|
-
<div class="entry-content">
|
58
|
-
<p>First we login to CouchDB and generate the auth_session token for making requests.</p>
|
59
|
-
|
60
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">hash = Couchdb.<span style="color:#9900CC;">login</span><span style="color:#006600; font-weight:bold;">(</span>username = <span style="color:#996600;">'samson'</span>,password =<span style="color:#996600;">'sam123'</span><span style="color:#006600; font-weight:bold;">)</span>
|
61
|
-
auth_session = hash<span style="color:#006600; font-weight:bold;">[</span><span style="color:#996600;">"AuthSession"</span><span style="color:#006600; font-weight:bold;">]</span></pre></div></div>
|
62
|
-
|
63
|
-
<p>To count the number of documents in the friends database with gender = male and age = 34</p>
|
64
|
-
|
65
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> keys = <span style="color:#006600; font-weight:bold;">{</span>:gender <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'male'</span>,:age <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'34'</span><span style="color:#006600; font-weight:bold;">}</span>
|
66
|
-
Couchdb.<span style="color:#9900CC;">count_by_keys</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'friends'</span>, <span style="color:#ff3333; font-weight:bold;">:keys</span> <span style="color:#006600; font-weight:bold;">=></span> keys<span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
67
|
-
<span style="color:#008000; font-style:italic;"># => 8</span></pre></div></div>
|
68
|
-
|
69
|
-
<p>This returns an integer of the number of matching documents</p>
|
70
|
-
<p>To count the number of documents in the friends database with gender = male, age = 34 and lastname = smith</p>
|
71
|
-
|
72
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> keys = <span style="color:#006600; font-weight:bold;">{</span>:gender <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'male'</span>,:age <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'34'</span>, <span style="color:#ff3333; font-weight:bold;">:lastname</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'smith'</span><span style="color:#006600; font-weight:bold;">}</span>
|
73
|
-
Couchdb.<span style="color:#9900CC;">count_by_keys</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'friends'</span>, <span style="color:#ff3333; font-weight:bold;">:keys</span> <span style="color:#006600; font-weight:bold;">=></span> keys<span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
74
|
-
<span style="color:#008000; font-style:italic;">#=> 2</span></pre></div></div>
|
75
|
-
|
76
|
-
<p>If you are running an admin party (i.e you have no admins in CouchDB), simply use the same methods, with no auth_session parameter.</p>
|
77
|
-
|
78
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">keys = <span style="color:#006600; font-weight:bold;">{</span>:gender <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'male'</span>,:age <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'34'</span><span style="color:#006600; font-weight:bold;">}</span>
|
79
|
-
Couchdb.<span style="color:#9900CC;">count_by_keys</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'friends'</span>, <span style="color:#ff3333; font-weight:bold;">:keys</span> <span style="color:#006600; font-weight:bold;">=></span> keys<span style="color:#006600; font-weight:bold;">}</span><span style="color:#006600; font-weight:bold;">)</span>
|
80
|
-
<span style="color:#008000; font-style:italic;">#=> 8</span></pre></div></div>
|
81
|
-
|
82
|
-
<p><strong>How it works</strong><br />
|
83
|
-
The method</p>
|
84
|
-
|
85
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> keys = <span style="color:#006600; font-weight:bold;">{</span>:gender <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'male'</span>,:age <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'34'</span><span style="color:#006600; font-weight:bold;">}</span>
|
86
|
-
Couchdb.<span style="color:#9900CC;">count_by_keys</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'friends'</span>, <span style="color:#ff3333; font-weight:bold;">:keys</span> <span style="color:#006600; font-weight:bold;">=></span> keys<span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span></pre></div></div>
|
87
|
-
|
88
|
-
<p>sends a</p>
|
89
|
-
|
90
|
-
<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">GET http://127.0.0.1:5984/contacts/_design/gender_age_keys_counter/_view/count_by_keys_gender_age?startkey=["male","34"]&endkey=["male","34"]</pre></div></div>
|
91
|
-
|
92
|
-
<p>This returns the number of contacts with gender = male and age = 34. If the design_document (_design/gender_age_counter) and the view (count_by_keys_gender_age) doesn’t exist, Leanback will create it in the database. See the source for the generated design_document;</p>
|
93
|
-
|
94
|
-
<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">{</span>
|
95
|
-
<span style="color: #3366CC;">"_id"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"_design/gender_age_keys_counter"</span><span style="color: #339933;">,</span>
|
96
|
-
<span style="color: #3366CC;">"_rev"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"10-92674ebbb4bca65add937f764b37623d"</span><span style="color: #339933;">,</span>
|
97
|
-
<span style="color: #3366CC;">"language"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"javascript"</span><span style="color: #339933;">,</span>
|
98
|
-
<span style="color: #3366CC;">"views"</span><span style="color: #339933;">:</span> <span style="color: #009900;">{</span>
|
99
|
-
<span style="color: #3366CC;">"count_by_keys_gender_age"</span><span style="color: #339933;">:</span> <span style="color: #009900;">{</span>
|
100
|
-
<span style="color: #3366CC;">"map"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"function(doc){ if(doc.gender && doc.age) emit([doc.gender,doc.age],doc);}"</span><span style="color: #339933;">,</span>
|
101
|
-
<span style="color: #3366CC;">"reduce"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"_count"</span>
|
102
|
-
<span style="color: #009900;">}</span>
|
103
|
-
<span style="color: #009900;">}</span>
|
104
|
-
<span style="color: #009900;">}</span></pre></div></div>
|
105
|
-
|
106
|
-
</div><!-- .entry-content -->
|
107
|
-
|
108
|
-
|
109
|
-
</div><!-- .hentry -->
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
<div id="disqus_thread">
|
114
|
-
</div>
|
115
|
-
|
116
|
-
<script type="text/javascript">
|
117
|
-
/* <![CDATA[ */
|
118
|
-
var disqus_url = 'http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/';
|
119
|
-
var disqus_identifier = '173 http://www.whisperservers.com/leanback/?page_id=173';
|
120
|
-
var disqus_container_id = 'disqus_thread';
|
121
|
-
var disqus_domain = 'disqus.com';
|
122
|
-
var disqus_shortname = 'obi-akubue';
|
123
|
-
var disqus_title = "Count documents by multiple keys";
|
124
|
-
var disqus_config = function () {
|
125
|
-
var config = this; // Access to the config object
|
126
|
-
|
127
|
-
/*
|
128
|
-
All currently supported events:
|
129
|
-
* preData — fires just before we request for initial data
|
130
|
-
* preInit - fires after we get initial data but before we load any dependencies
|
131
|
-
* onInit - fires when all dependencies are resolved but before dtpl template is rendered
|
132
|
-
* afterRender - fires when template is rendered but before we show it
|
133
|
-
* onReady - everything is done
|
134
|
-
*/
|
135
|
-
|
136
|
-
config.callbacks.preData.push(function() {
|
137
|
-
// clear out the container (its filled for SEO/legacy purposes)
|
138
|
-
document.getElementById(disqus_container_id).innerHTML = '';
|
139
|
-
});
|
140
|
-
config.callbacks.onReady.push(function() {
|
141
|
-
// sync comments in the background so we don't block the page
|
142
|
-
DISQUS.request.get('?cf_action=sync_comments&post_id=173');
|
143
|
-
});
|
144
|
-
};
|
145
|
-
var facebookXdReceiverPath = 'http://www.whisperservers.com/leanback/wp-content/plugins/disqus-comment-system/xd_receiver.htm';
|
146
|
-
/* ]]> */
|
147
|
-
</script>
|
148
|
-
|
149
|
-
<script type="text/javascript">
|
150
|
-
/* <![CDATA[ */
|
151
|
-
var DsqLocal = {
|
152
|
-
'trackbacks': [
|
153
|
-
],
|
154
|
-
'trackback_url': "http:\/\/www.whisperservers.com\/leanback\/wp-content\/plugins\/really-static\/static\/count-by-multiple-documents\/trackback\/" };
|
155
|
-
/* ]]> */
|
156
|
-
</script>
|
157
|
-
|
158
|
-
<script type="text/javascript">
|
159
|
-
/* <![CDATA[ */
|
160
|
-
(function() {
|
161
|
-
var dsq = document.createElement('script'); dsq.type = 'text/javascript';
|
162
|
-
dsq.async = true;
|
163
|
-
dsq.src = 'http://' + disqus_shortname + '.' + disqus_domain + '/embed.js?pname=wordpress&pver=2.67';
|
164
|
-
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
165
|
-
})();
|
166
|
-
/* ]]> */
|
167
|
-
</script>
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
</div><!-- .content .hfeed -->
|
174
|
-
|
175
|
-
|
176
|
-
<div id="primary" class="sidebar aside">
|
177
|
-
|
178
|
-
|
179
|
-
<div id="hybrid-nav-menu-3" class="widget nav-menu widget-nav-menu"><div class="widget-wrap widget-inside"><h3 class="widget-title">Leanback</h3><div class="menu-sidebar-container"><ul id="menu-sidebar" class="nav-menu"><li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-13"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/leanback/">Leanback</a><ul class="sub-menu"><li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/leanback/installation/">Install</a></li><li id="menu-item-15" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/basic-couchdb-operations/">Basic CouchDB Operations</a></li><li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-documents-by-key/">Find documents by key</a></li><li id="menu-item-167" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-167"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-document-by-multiple-keys/">Find document by multiple Keys</a></li><li id="menu-item-140" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-140"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-documents-by-key/">Count documents by key</a></li><li id="menu-item-175" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-173 current_page_item menu-item-175"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/">Count documents by multiple keys</a></li><li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-45"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/design-documents-and-permanent-views/">Working with CouchDB views</a></li><li id="menu-item-67" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-67"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/error-handling/">Error handling</a></li><li id="menu-item-96" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-96"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/couchdb-configuration/">CouchDB Configuration</a></li><li id="menu-item-102" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-102"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/couchdb-security/">CouchDB Security</a></li><li id="menu-item-105" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-105"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/setting-the-bind_address-port/">CouchDB Bind_Address & Port</a></li></ul></li><li id="menu-item-142" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-142"><a href="https://github.com/obi-a/leanback/blob/master/Changelog.rdoc">Changes</a></li><li id="menu-item-78" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-78"><a href="https://github.com/obi-a/leanback">Source Code</a></li></ul></div></div></div>
|
180
|
-
|
181
|
-
</div><!-- #primary .aside -->
|
182
|
-
|
183
|
-
|
184
|
-
</div><!-- #container -->
|
185
|
-
|
186
|
-
<div id="footer-container">
|
187
|
-
|
188
|
-
|
189
|
-
<div id="footer">
|
190
|
-
|
191
|
-
<div class="footer-insert"><p class="copyright">Copyright © 2013 <a href="http://obi-akubue.org">obi-akubue.org</a>.</p></div>
|
192
|
-
</div><!-- #footer -->
|
193
|
-
|
194
|
-
|
195
|
-
</div><!-- #footer-container -->
|
196
|
-
|
197
|
-
</div><!-- #body-container -->
|
198
|
-
|
199
|
-
|
200
|
-
<script type="text/javascript">
|
201
|
-
|
202
|
-
var _gaq = _gaq || [];
|
203
|
-
_gaq.push(['_setAccount', 'UA-20190925-6']);
|
204
|
-
_gaq.push(['_trackPageview']);
|
205
|
-
|
206
|
-
(function() {
|
207
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
208
|
-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
209
|
-
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
|
210
|
-
})();
|
211
|
-
</script>
|
212
|
-
|
213
|
-
<a style='color:transparent;position:absolute;left:-99999px;z-index:-99999' href='http://www.wpdownloadmanager.com/' title='Premium Wordpress Plugin download manager'>Premium Wordpress Plugin</a>
|
214
|
-
<script type='text/javascript' src='http://www.whisperservers.com/leanback/wp-content/themes/hybrid/library/js/drop-downs.js?ver=20110705'></script>
|
215
|
-
|
216
|
-
</body>
|
217
|
-
</html>
|
218
|
-
<!-- Dynamic page generated in 0.467 seconds. -->
|
219
|
-
<!-- Cached page generated by WP-Super-Cache on 2013-06-09 16:30:32 -->
|
220
|
-
|
221
|
-
<!-- super cache -->
|
@@ -1,177 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en-US">
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
5
|
-
<title>Count documents by key</title>
|
6
|
-
|
7
|
-
<link rel="stylesheet" href="http://www.whisperservers.com/leanback/wp-content/themes/hybrid/style.css" type="text/css" media="all" />
|
8
|
-
<link rel="profile" href="http://gmpg.org/xfn/11" />
|
9
|
-
<link rel="pingback" href="http://www.whisperservers.com/leanback/xmlrpc.php" />
|
10
|
-
|
11
|
-
<meta name="generator" content="WordPress 3.5.1 - really-static 0.5" />
|
12
|
-
<meta name="template" content="Hybrid 1.0" />
|
13
|
-
<meta name="robots" content="index,follow" />
|
14
|
-
<meta name="author" content="admin" />
|
15
|
-
<meta name="copyright" content="Copyright (c) May 2013" />
|
16
|
-
<meta name="revised" content="Sunday, June 9th, 2013, 3:25 pm" />
|
17
|
-
<link rel="alternate" type="application/rss+xml" title="Leanback » Feed" href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/feed/" />
|
18
|
-
|
19
|
-
<script type='text/javascript' src='http://www.whisperservers.com/leanback/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>
|
20
|
-
<link rel='prev' title='CouchDB Bind_Address & Port' href='http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/setting-the-bind_address-port/' />
|
21
|
-
<link rel='next' title='Find document by multiple Keys' href='http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-document-by-multiple-keys/' />
|
22
|
-
<link rel='canonical' href='http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-documents-by-key/' />
|
23
|
-
|
24
|
-
<link rel="stylesheet" href="http://www.whisperservers.com/leanback/wp-content/plugins/wp-syntax/wp-syntax.css" type="text/css" media="screen" />
|
25
|
-
|
26
|
-
</head>
|
27
|
-
|
28
|
-
<body class="wordpress ltr en_US parent-theme y2013 m06 d09 h16 sunday logged-out singular singular-page singular-page-137 page-template-default page-137 primary-active secondary-inactive subsidiary-inactive">
|
29
|
-
|
30
|
-
|
31
|
-
<div id="body-container">
|
32
|
-
|
33
|
-
|
34
|
-
<div id="header-container">
|
35
|
-
|
36
|
-
<div id="header">
|
37
|
-
|
38
|
-
<div id="site-title"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/" title="Leanback" rel="home"><span>Leanback</span></a></div>
|
39
|
-
<div id="site-description"><span>Simple Ruby interface to CouchDB</span></div>
|
40
|
-
|
41
|
-
</div><!-- #header -->
|
42
|
-
|
43
|
-
</div><!-- #header-container -->
|
44
|
-
|
45
|
-
|
46
|
-
<div id="container">
|
47
|
-
|
48
|
-
|
49
|
-
<div id="content" class="hfeed content">
|
50
|
-
|
51
|
-
<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail"><span class="trail-before"><span class="breadcrumb-title">Browse:</span></span> <a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/" title="Leanback" rel="home" class="trail-begin">Home</a> <span class="sep">/</span> <span class="trail-end">Count documents by key</span></div></div>
|
52
|
-
|
53
|
-
<div id="post-137" class="hentry page publish post-1 odd author-admin">
|
54
|
-
|
55
|
-
<h1 class="page-title entry-title"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-documents-by-key/" title="Count documents by key" rel="bookmark">Count documents by key</a></h1>
|
56
|
-
<div class="entry-content">
|
57
|
-
<p>First we login to CouchDB and generate the auth_session token for making requests.</p>
|
58
|
-
|
59
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">hash = Couchdb.<span style="color:#9900CC;">login</span><span style="color:#006600; font-weight:bold;">(</span>username = <span style="color:#996600;">'samson'</span>,password =<span style="color:#996600;">'sam123'</span><span style="color:#006600; font-weight:bold;">)</span>
|
60
|
-
auth_session = hash<span style="color:#006600; font-weight:bold;">[</span><span style="color:#996600;">"AuthSession"</span><span style="color:#006600; font-weight:bold;">]</span></pre></div></div>
|
61
|
-
|
62
|
-
<p>To count the number of documents with a key (example: to count the number of documents with email = nancy@mail.com )</p>
|
63
|
-
|
64
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'nancy@mail.com'</span><span style="color:#006600; font-weight:bold;">}</span> , auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
65
|
-
|
66
|
-
<span style="color:#008000; font-style:italic;"># => 1</span></pre></div></div>
|
67
|
-
|
68
|
-
<p>This returns an integer of the number of documents that match the key.</p>
|
69
|
-
<p>To get the number of contacts with lastname = ‘Smith’</p>
|
70
|
-
|
71
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:lastname</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'Smith'</span><span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
72
|
-
|
73
|
-
<span style="color:#008000; font-style:italic;"># => 2</span></pre></div></div>
|
74
|
-
|
75
|
-
<p>To count all female contacts</p>
|
76
|
-
|
77
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:gender</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'female'</span><span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
78
|
-
|
79
|
-
<span style="color:#008000; font-style:italic;"># => 8</span></pre></div></div>
|
80
|
-
|
81
|
-
<p>If you are running an admin party (i.e you have no admins in CouchDB), simply use the same methods, with no auth_session parameter.</p>
|
82
|
-
|
83
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span> <span style="color:#ff3333; font-weight:bold;">:database</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:gender</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'female'</span><span style="color:#006600; font-weight:bold;">)</span></pre></div></div>
|
84
|
-
|
85
|
-
<p><strong>How it works</strong><br />
|
86
|
-
The method</p>
|
87
|
-
|
88
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'nancy@mail.com'</span><span style="color:#006600; font-weight:bold;">}</span>, auth_session<span style="color:#006600; font-weight:bold;">)</span></pre></div></div>
|
89
|
-
|
90
|
-
<p>sends a</p>
|
91
|
-
|
92
|
-
<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">GET http://127.0.0.1:5984/contacts/_design/email_counter/_view/count_email?key="nancy@mail.com"</pre></div></div>
|
93
|
-
|
94
|
-
<p>This returns the number of contacts with email = ‘nancy@mail.com’. If the design_document (_design/email_counter) and the view (count_email) doesn’t exist, Leanback will create it in the database. See the source for the generated design_document;</p>
|
95
|
-
|
96
|
-
<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">{</span>
|
97
|
-
<span style="color: #3366CC;">"_id"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"_design/email_counter"</span><span style="color: #339933;">,</span>
|
98
|
-
<span style="color: #3366CC;">"_rev"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"1-d5ec21ea6ce87f99a511dd02c196ce8f"</span><span style="color: #339933;">,</span>
|
99
|
-
<span style="color: #3366CC;">"language"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"javascript"</span><span style="color: #339933;">,</span>
|
100
|
-
<span style="color: #3366CC;">"views"</span><span style="color: #339933;">:</span> <span style="color: #009900;">{</span>
|
101
|
-
<span style="color: #3366CC;">"count_email"</span><span style="color: #339933;">:</span> <span style="color: #009900;">{</span>
|
102
|
-
<span style="color: #3366CC;">"map"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"function(doc){ if(doc.email) emit(doc.email,null);}"</span><span style="color: #339933;">,</span>
|
103
|
-
<span style="color: #3366CC;">"reduce"</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"_count"</span>
|
104
|
-
<span style="color: #009900;">}</span>
|
105
|
-
<span style="color: #009900;">}</span>
|
106
|
-
<span style="color: #009900;">}</span></pre></div></div>
|
107
|
-
|
108
|
-
<p>If you ran</p>
|
109
|
-
|
110
|
-
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:lastname</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'Smith'</span><span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span>
|
111
|
-
Couchdb.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#006600; font-weight:bold;">{</span>:database <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'contacts'</span>, <span style="color:#ff3333; font-weight:bold;">:gender</span> <span style="color:#006600; font-weight:bold;">=></span> <span style="color:#996600;">'female'</span><span style="color:#006600; font-weight:bold;">}</span>,auth_session<span style="color:#006600; font-weight:bold;">)</span></pre></div></div>
|
112
|
-
|
113
|
-
<p>you will notice the following design_documents have been added to the database</p>
|
114
|
-
|
115
|
-
<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">_design/lastname_counter
|
116
|
-
_design/gender_counter</pre></div></div>
|
117
|
-
|
118
|
-
</div><!-- .entry-content -->
|
119
|
-
|
120
|
-
|
121
|
-
</div><!-- .hentry -->
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
</div><!-- .content .hfeed -->
|
130
|
-
|
131
|
-
|
132
|
-
<div id="primary" class="sidebar aside">
|
133
|
-
|
134
|
-
|
135
|
-
<div id="hybrid-nav-menu-3" class="widget nav-menu widget-nav-menu"><div class="widget-wrap widget-inside"><h3 class="widget-title">Leanback</h3><div class="menu-sidebar-container"><ul id="menu-sidebar" class="nav-menu"><li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-13"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/leanback/">Leanback</a><ul class="sub-menu"><li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/leanback/installation/">Install</a></li><li id="menu-item-15" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/basic-couchdb-operations/">Basic CouchDB Operations</a></li><li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-documents-by-key/">Find documents by key</a></li><li id="menu-item-167" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-167"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/find-document-by-multiple-keys/">Find document by multiple Keys</a></li><li id="menu-item-140" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-137 current_page_item menu-item-140"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-documents-by-key/">Count documents by key</a></li><li id="menu-item-175" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-175"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/count-by-multiple-documents/">Count documents by multiple keys</a></li><li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-45"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/design-documents-and-permanent-views/">Working with CouchDB views</a></li><li id="menu-item-67" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-67"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/error-handling/">Error handling</a></li><li id="menu-item-96" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-96"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/couchdb-configuration/">CouchDB Configuration</a></li><li id="menu-item-102" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-102"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/couchdb-security/">CouchDB Security</a></li><li id="menu-item-105" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-105"><a href="http://www.whisperservers.com/leanback/wp-content/plugins/really-static/static/setting-the-bind_address-port/">CouchDB Bind_Address & Port</a></li></ul></li><li id="menu-item-142" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-142"><a href="https://github.com/obi-a/leanback/blob/master/Changelog.rdoc">Changes</a></li><li id="menu-item-78" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-78"><a href="https://github.com/obi-a/leanback">Source Code</a></li></ul></div></div></div>
|
136
|
-
|
137
|
-
</div><!-- #primary .aside -->
|
138
|
-
|
139
|
-
|
140
|
-
</div><!-- #container -->
|
141
|
-
|
142
|
-
<div id="footer-container">
|
143
|
-
|
144
|
-
|
145
|
-
<div id="footer">
|
146
|
-
|
147
|
-
<div class="footer-insert"><p class="copyright">Copyright © 2013 <a href="http://obi-akubue.org">obi-akubue.org</a>.</p></div>
|
148
|
-
</div><!-- #footer -->
|
149
|
-
|
150
|
-
|
151
|
-
</div><!-- #footer-container -->
|
152
|
-
|
153
|
-
</div><!-- #body-container -->
|
154
|
-
|
155
|
-
|
156
|
-
<script type="text/javascript">
|
157
|
-
|
158
|
-
var _gaq = _gaq || [];
|
159
|
-
_gaq.push(['_setAccount', 'UA-20190925-6']);
|
160
|
-
_gaq.push(['_trackPageview']);
|
161
|
-
|
162
|
-
(function() {
|
163
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
164
|
-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
165
|
-
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
|
166
|
-
})();
|
167
|
-
</script>
|
168
|
-
|
169
|
-
<a style='color:transparent;position:absolute;left:-99999px;z-index:-99999' href='http://www.wpdownloadmanager.com/' title='Premium Wordpress Plugin download manager'>Premium Wordpress Plugin</a>
|
170
|
-
<script type='text/javascript' src='http://www.whisperservers.com/leanback/wp-content/themes/hybrid/library/js/drop-downs.js?ver=20110705'></script>
|
171
|
-
|
172
|
-
</body>
|
173
|
-
</html>
|
174
|
-
<!-- Dynamic page generated in 0.691 seconds. -->
|
175
|
-
<!-- Cached page generated by WP-Super-Cache on 2013-06-09 16:30:32 -->
|
176
|
-
|
177
|
-
<!-- super cache -->
|
@@ -1 +0,0 @@
|
|
1
|
-
#body-container{overflow:hidden;width:960px;margin:0 auto}#container{overflow:hidden;float:left;width:960px}.content{overflow:hidden;float:left;width:620px}.no-widgets .content,.no-default-widgets .content{width:960px}#primary{position:relative;float:right;width:300px}#secondary{position:relative;clear:right;float:right;width:300px}#subsidiary{overflow:hidden}#subsidiary .widget{overflow:hidden;float:left;width:300px;margin:0 20px 0 0}#footer-container{clear:both;overflow:hidden}#footer{clear:both;overflow:hidden}
|
@@ -1,62 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Two columns with content floated left.
|
3
|
-
*
|
4
|
-
* @since 0.6
|
5
|
-
* @package Hybrid
|
6
|
-
* @subpackage CSS
|
7
|
-
*/
|
8
|
-
|
9
|
-
#body-container {
|
10
|
-
overflow: hidden;
|
11
|
-
width: 960px;
|
12
|
-
margin: 0 auto;
|
13
|
-
}
|
14
|
-
|
15
|
-
#container {
|
16
|
-
overflow: hidden;
|
17
|
-
float: left;
|
18
|
-
width: 960px;
|
19
|
-
}
|
20
|
-
|
21
|
-
.content {
|
22
|
-
overflow: hidden;
|
23
|
-
float: left;
|
24
|
-
width: 620px;
|
25
|
-
}
|
26
|
-
.no-widgets .content, .no-default-widgets .content {
|
27
|
-
width: 960px;
|
28
|
-
}
|
29
|
-
|
30
|
-
#primary {
|
31
|
-
position: relative;
|
32
|
-
float: right;
|
33
|
-
width: 300px;
|
34
|
-
}
|
35
|
-
|
36
|
-
#secondary {
|
37
|
-
position: relative;
|
38
|
-
clear: right;
|
39
|
-
float: right;
|
40
|
-
width: 300px;
|
41
|
-
}
|
42
|
-
|
43
|
-
#subsidiary {
|
44
|
-
overflow: hidden;
|
45
|
-
}
|
46
|
-
|
47
|
-
#subsidiary .widget {
|
48
|
-
overflow: hidden;
|
49
|
-
float: left;
|
50
|
-
width: 300px;
|
51
|
-
margin: 0 20px 0 0;
|
52
|
-
}
|
53
|
-
|
54
|
-
#footer-container {
|
55
|
-
clear: both;
|
56
|
-
overflow: hidden;
|
57
|
-
}
|
58
|
-
|
59
|
-
#footer {
|
60
|
-
clear: both;
|
61
|
-
overflow: hidden;
|
62
|
-
}
|