-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
3808 lines (2943 loc) · 247 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Mirco Zeiss</title>
<meta name="author" content="Mirco Zeiss">
<meta name="description" content="What does every app need? Users! What does every app therefore need to have? An authentication solution: signup new users
allow existing users to …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://mircozeiss.com">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="Mirco Zeiss" type="application/atom+xml">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Fjalla+One' rel='stylesheet' type='text/css'>
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="zeMirco">
<meta name="twitter:creator" content="zeMirco">
<meta name="twitter:url" content="http://mircozeiss.com">
<meta name="twitter:title" content="Mirco Zeiss">
<meta name="twitter:description" content="What does every app need? Users! What does every app therefore need to have? An authentication solution: signup new users
allow existing users to login
help users who forgot their password
etc. What …">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40074158-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="collapse-sidebar sidebar-footer" >
<header role="banner"><hgroup>
<h1><a href="/">Mirco Zeiss</a></h1>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:mircozeiss.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/about.html">About</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/lockit-an-express-authentication-solution/">Lockit - an Express Authentication Solution</a></h1>
<p class="meta">
<time datetime="2014-01-15T10:51:00+01:00" pubdate data-updated="true">Jan 15<span>th</span>, 2014</time>
| <a href="/lockit-an-express-authentication-solution/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>What does every app need? <strong>Users!</strong></p>
<p>What does every app therefore need to have? An <strong>authentication solution</strong>:</p>
<ul>
<li>signup new users</li>
<li>allow existing users to login</li>
<li>help users who forgot their password</li>
<li>etc.</li>
</ul>
<p>What’s the most annoying part to write when building a new app?
The <strong>user authentication solution</strong>.</p>
<p>Focus on building your app instead of reinventing the wheel and use <a href="https://github.com/zeMirco/lockit">lockit</a>.</p>
<h3>Concept</h3>
<p>Lockit is inspired by Ruby’s <a href="https://github.com/plataformatec/devise">devise</a>.
It consists of multiple single purpose modules that you could also use on their own.
The main module <code>lockit</code> is just a wrapper around those</p>
<ul>
<li><a href="https://github.com/zeMirco/lockit-login">lockit-login</a></li>
<li><a href="https://github.com/zeMirco/lockit-signup">lockit-signup</a></li>
<li><a href="https://github.com/zeMirco/lockit-delete-account">lockit-delete-account</a></li>
<li><a href="https://github.com/zeMirco/lockit-forgot-password">lockit-forgot-password</a></li>
<li><a href="https://github.com/zeMirco/lockit-sendmail">lockit-sendmail</a></li>
<li><a href="https://github.com/zeMirco/lockit-couchdb-adapter">lockit-couchdb-adapter</a></li>
<li><a href="https://github.com/zeMirco/lockit-mongodb-adapter">lockit-mongodb-adapter</a></li>
<li><a href="https://github.com/zeMirco/lockit-utilities">lockit-utilities</a></li>
<li><a href="https://github.com/zeMirco/lockit-template-blank">lockit-template-blank</a></li>
</ul>
<p>When you have problems please try to open an issue in the according repository.</p>
<h3>How to use</h3>
<p>Install the module and the adapter for your database (couchdb or mongodb) via npm</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>npm install lockit lockit-couchdb-adapter</span></code></pre></td></tr></table></div></figure>
<p>Create a <code>config.js</code> in your <code>app/</code> folder with your database settings</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// database settings for CouchDB</span>
</span><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="s1">'couchdb'</span><span class="p">;</span>
</span><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">dbUrl</span> <span class="o">=</span> <span class="s1">'http://127.0.0.1:5984/test'</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// or if you want to use MongoDB</span>
</span><span class='line'><span class="c1">// exports.db = 'mongodb';</span>
</span><span class='line'><span class="c1">// exports.dbUrl = 'mongodb://127.0.0.1/test';</span>
</span><span class='line'><span class="c1">// exports.dbCollection = 'users';</span>
</span></code></pre></td></tr></table></div></figure>
<p><strong>Important!</strong> If you are using CouchDB you need to create the necessary views first.
Lockit comes with a helper file that does it automatically for you. Simply run</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">config</span><span class="o">=</span><span class="p">[</span><span class="nx">PATH</span><span class="p">]</span> <span class="nx">node</span> <span class="nx">node_modules</span><span class="o">/</span><span class="nx">lockit</span><span class="o">/</span><span class="nx">createCouchViews</span><span class="p">.</span><span class="nx">js</span>
</span></code></pre></td></tr></table></div></figure>
<p>[PATH] should be the location of your config.js, i.e.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">config</span><span class="o">=</span><span class="p">.</span><span class="o">/</span><span class="nx">config</span><span class="p">.</span><span class="nx">js</span> <span class="nx">node</span> <span class="nx">node_modules</span><span class="o">/</span><span class="nx">lockit</span><span class="o">/</span><span class="nx">createCouchViews</span><span class="p">.</span><span class="nx">js</span>
</span></code></pre></td></tr></table></div></figure>
<p>If you don’t use CouchDB you can simply continue here.</p>
<p>Use both modules in your <code>app.js</code> file</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./config.js'</span><span class="p">);</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">lockit</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'lockit'</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>Activate the module by calling the main <code>lockit()</code> function</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// ... express stuff</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// use middleware before router so your own routes have access to</span>
</span><span class='line'><span class="c1">// req.session.email and req.session.username</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// sessions have to be enabled!</span>
</span><span class='line'><span class="nx">lockit</span><span class="p">(</span><span class="nx">app</span><span class="p">,</span> <span class="nx">config</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// ... more express stuff</span>
</span></code></pre></td></tr></table></div></figure>
<p>Include <a href="http://getbootstrap.com/">bootstrap</a> css in your views/layout.jade</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">link</span><span class="p">(</span><span class="nx">rel</span><span class="o">=</span><span class="s1">'stylesheet'</span><span class="p">,</span> <span class="nx">href</span><span class="o">=</span><span class="s1">'/css/bootstrap.min.css'</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Start your app like always with <code>node app.js</code>, open the browser and navigate to <a href="http://localhost:3000/signup">localhost:3000/signup</a>.
I’ve also included an <a href="https://github.com/zeMirco/lockit/tree/master/example">example app</a> that you can download and run locally.
It has a special route <code>/profile</code> which demonstrates how to get user information from db and show them
in the browser.</p>
<p>You’ll notice that nothing happens after you’ve signed up although
you should see a message that an email has been sent to you.
If you take a look at your database however, you should be able to see your just created user.
So the user is created but the email is simply not sent.</p>
<p>That’s because the email service is not set up yet.
By default all email communication is stubbed (no emails are sent).
You need to have your own email service in order to send emails when a user signs up or
requests a new password. Under the hood lockit uses <a href="https://github.com/andris9/Nodemailer">nodemailer</a> to send emails.
You can therefore use the same configuration in your <code>config.js</code> file.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// default settings</span>
</span><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">emailType</span> <span class="o">=</span> <span class="s1">'Stub'</span><span class="p">;</span>
</span><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">emailSettings</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">service</span><span class="o">:</span> <span class="s1">'none'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">auth</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">user</span><span class="o">:</span> <span class="s1">'none'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">pass</span><span class="o">:</span> <span class="s1">'none'</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">};</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// change them to something similar like</span>
</span><span class='line'><span class="c1">// exports.emailType = 'SMTP';</span>
</span><span class='line'><span class="c1">// exports.emailSettings = {</span>
</span><span class='line'><span class="c1">// service: 'Gmail',</span>
</span><span class='line'><span class="c1">// auth: {</span>
</span><span class='line'><span class="c1">// user: '[email protected]',</span>
</span><span class='line'><span class="c1">// pass: 'userpass'</span>
</span><span class='line'><span class="c1">// }</span>
</span><span class='line'><span class="c1">// };</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now you are good to go. You can also change all the other stuff like email template,
welcome text, title and subject of the emails, etc. Take a look at the <a href="https://github.com/zeMirco/lockit#configuration">lockit#configuration</a>
part at GitHub to see all possibilities.</p>
<h3>FAQ</h3>
<ol>
<li><p>How is this different to <a href="http://passportjs.org/">passport</a>?</p>
<p> Passport offers different strategies (local, OpenID, OAuth) for authentication.
It assumes that you already have users in your db and only handles login, logout and route restriction.
It does not send any emails on signup or when a user forgot a password.
You can think of Lockit as a layer before Passport. I haven’t tried it yet but it should work
to use Lockit for signup, forgot password, delete account and on top of that Passport with
the <a href="https://github.com/jaredhanson/passport-local">local strategy</a>.</p></li>
<li><p>Why didn’t you use <a href="http://www.mozilla.org/en-US/persona/">Persona</a>?</p>
<p> Well, I’ve tried Persona and like it a lot for simple web based solutions. However authentication
solutions should work on all devices and for all platforms. One big problem is that Persona does
not work with PhoneGap and other environments that break when opening popups. See the related
<a href="https://github.com/mozilla/persona/issues/2034">issue #2034</a>.</p></li>
<li><p>What about a SaaS solution like <a href="https://www.userapp.io/">userapp</a>?</p>
<p> User information is the most valuable, critical and sensible data.
Users trust you to handle them with care.
Therefore I don’t like giving them away.</p></li>
</ol>
<h3>Conclusion</h3>
<p>Please give <a href="https://github.com/zeMirco/lockit">lockit</a> a try. Leave comments, feedback and issues
on GitHub or here in the comments.</p>
<p>I’m not a security expert although I’ve read a lot about this topic while developing lockit.
So use it with care and probably do not use it for production yet. I’m sure there is room for improvements.</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/pouchdb-vs-couchbase-lite-a-performance-review/">PouchDB vs. Couchbase Lite - a Performance Review</a></h1>
<p class="meta">
<time datetime="2013-12-04T13:25:00+01:00" pubdate data-updated="true">Dec 4<span>th</span>, 2013</time>
| <a href="/pouchdb-vs-couchbase-lite-a-performance-review/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>Client side databases with offline support are very important for mobile hybrid apps where performance matters. I’ve developed several
apps with Cordova/Phonegap in the last months and always needed a database to save information on the client, that has offline
support and allows replicating data back to my cloud database. Two databases came up whenever I was looking for a solution - PouchDB and
Couchbase Lite Phonegap. PouchDB works entirely in the browser whereas Couchbase Lite works with native databases on iOS and Android
through a JavaScript API.</p>
<p>Today I’d like to draw a comparison between them focusing on performance. How fast do they write data and how fast do they
retrieve data? I chose four actions and did ten repetitions each</p>
<ul>
<li>bulk add documents</li>
<li>get all documents</li>
<li>get document by id</li>
<li>query database via view</li>
</ul>
<p>The code is on <a href="https://github.com/zeMirco/pouchdb-vs-couchbase">GitHub</a> so you can run the tests for yourself. My tests were done on my MacBook Pro running Mavericks
inside the iOS emulator. Therefore the exact values will be different depending on which hardware you use. The overall results and findings should
still be the same though.</p>
<h3>Bulk add documents</h3>
<p>The first action is adding random documents to each database. The first run was with 10000 and the second with 25000 documents.</p>
<p>The code snippets look like this:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// add array of documents to PouchDB</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">pouch_bulkAdd</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">max</span> <span class="o">=</span> <span class="mi">10000</span><span class="p">;</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">generate</span><span class="p">(</span><span class="nx">max</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'PouchDB - bulk add'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">db</span><span class="p">.</span><span class="nx">bulkDocs</span><span class="p">({</span><span class="nx">docs</span><span class="o">:</span> <span class="nx">data</span><span class="p">},</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'PouchDB - bulk add'</span><span class="p">);</span>
</span><span class='line'> <span class="c1">// save one user for later query</span>
</span><span class='line'> <span class="nx">dummyId</span> <span class="o">=</span> <span class="nx">res</span><span class="p">[</span><span class="mi">5000</span><span class="p">].</span><span class="nx">id</span><span class="p">;</span>
</span><span class='line'> <span class="p">})</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// add array of documents to Couchbase Lite</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">couchbase_bulkAdd</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">max</span> <span class="o">=</span> <span class="mi">10000</span><span class="p">;</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">generate</span><span class="p">(</span><span class="nx">max</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'Couchbase lite - bulk add'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">({</span>
</span><span class='line'> <span class="nx">type</span><span class="o">:</span> <span class="s1">'POST'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">url</span><span class="o">:</span> <span class="nx">globalUrl</span> <span class="o">+</span> <span class="s1">'performance/_bulk_docs'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">data</span><span class="o">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">({</span><span class="s1">'docs'</span><span class="o">:</span> <span class="nx">data</span><span class="p">}),</span>
</span><span class='line'> <span class="nx">contentType</span> <span class="o">:</span> <span class="s1">'application/json'</span>
</span><span class='line'> <span class="p">})</span>
</span><span class='line'> <span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'Couchbase lite - bulk add'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">dummyId</span> <span class="o">=</span> <span class="nx">res</span><span class="p">[</span><span class="mi">5000</span><span class="p">].</span><span class="nx">id</span><span class="p">;</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<table class="table table-condensed full-width">
<thead>
<tr>
<th>#</th>
<th>PouchDB (10000 docs)</th>
<th>CB Lite (10000 docs)</th>
<th> - </th>
<th>PouchDB (25000 docs)</th>
<th>CB Lite (25000 docs)</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2214 ms</td>
<td>2459 ms</td>
<td> - </td>
<td>5568 ms</td>
<td>6064 ms</td>
</tr>
<tr>
<td>2</td>
<td>2391 ms</td>
<td>2777 ms</td>
<td> - </td>
<td>5561 ms</td>
<td>6583 ms</td>
</tr>
<tr>
<td>3</td>
<td>1532 ms</td>
<td>2966 ms</td>
<td> - </td>
<td>5494 ms</td>
<td>6683 ms</td>
</tr>
<tr>
<td>4</td>
<td>1506 ms</td>
<td>3071 ms</td>
<td> - </td>
<td>5805 ms</td>
<td>6723 ms</td>
</tr>
<tr>
<td>5</td>
<td>1539 ms</td>
<td>3022 ms</td>
<td> - </td>
<td>5705 ms</td>
<td>6828 ms</td>
</tr>
<tr>
<td>6</td>
<td>1607 ms</td>
<td>3087 ms</td>
<td> - </td>
<td>5746 ms</td>
<td>6769 ms</td>
</tr>
<tr>
<td>7</td>
<td>1596 ms</td>
<td>3141 ms</td>
<td> - </td>
<td>5841 ms</td>
<td>6805 ms</td>
</tr>
<tr>
<td>8</td>
<td>1694 ms</td>
<td>3239 ms</td>
<td> - </td>
<td>5676 ms</td>
<td>6887 ms</td>
</tr>
<tr>
<td>9</td>
<td>1600 ms</td>
<td>3245 ms</td>
<td> - </td>
<td>5820 ms</td>
<td>6923 ms</td>
</tr>
<tr>
<td>10</td>
<td>1579 ms</td>
<td>3278 ms</td>
<td> - </td>
<td>5873 ms</td>
<td>6886 ms</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Ø</td>
<td style="background-color: lime;">1725.8 ms</td>
<td>3028.5 ms</td>
<td> - </td>
<td style="background-color: lime;">5708.9 ms</td>
<td>6715.1 ms</td>
</tr>
</tfoot>
</table>
<p><img src="https://s3.amazonaws.com/zeMirco/github/pouchdb-vs-couchbase/bulk-add.png" title="bulk add documents" ></p>
<h3>Get all documents</h3>
<p>The second action was getting all documents from each database, again with 10000 documents and then with 25000 documents.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// get all documents from PouchDB</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">pouch_allDocs</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'PouchDB - all docs'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">db</span><span class="p">.</span><span class="nx">allDocs</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="nx">log</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'PouchDB - all docs'</span><span class="p">);</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// get all documents from Couchbase Lite</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">couchbase_allDocs</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'Couchbase lite - all docs'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">$</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">globalUrl</span> <span class="o">+</span> <span class="s1">'performance/_all_docs'</span><span class="p">)</span>
</span><span class='line'> <span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'Couchbase lite - all docs'</span><span class="p">);</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<table class="table table-condensed full-width">
<thead>
<tr>
<th>#</th>
<th>PouchDB (10000 docs)</th>
<th>CB Lite (10000 docs)</th>
<th> - </th>
<th>PouchDB (25000 docs)</th>
<th>CB Lite (25000 docs)</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>345 ms</td>
<td>126 ms</td>
<td> - </td>
<td>852 ms</td>
<td>364 ms</td>
</tr>
<tr>
<td>2</td>
<td>325 ms</td>
<td>29 ms</td>
<td> - </td>
<td>796 ms</td>
<td>41 ms</td>
</tr>
<tr>
<td>3</td>
<td>315 ms</td>
<td>16 ms</td>
<td> - </td>
<td>800 ms</td>
<td>40 ms</td>
</tr>
<tr>
<td>4</td>
<td>315 ms</td>
<td>16 ms</td>
<td> - </td>
<td>782 ms</td>
<td>39 ms</td>
</tr>
<tr>
<td>5</td>
<td>311 ms</td>
<td>16 ms</td>
<td> - </td>
<td>806 ms</td>
<td>39 ms</td>
</tr>
<tr>
<td>6</td>
<td>314 ms</td>
<td>17 ms</td>
<td> - </td>
<td>791 ms</td>
<td>39 ms</td>
</tr>
<tr>
<td>7</td>
<td>315 ms</td>
<td>22 ms</td>
<td> - </td>
<td>791 ms</td>
<td>40 ms</td>
</tr>
<tr>
<td>8</td>
<td>308 ms</td>
<td>18 ms</td>
<td> - </td>
<td>787 ms</td>
<td>39 ms</td>
</tr>
<tr>
<td>9</td>
<td>315 ms</td>
<td>16 ms</td>
<td> - </td>
<td>821 ms</td>
<td>37 ms</td>
</tr>
<tr>
<td>10</td>
<td>313 ms</td>
<td>16 ms</td>
<td> - </td>
<td>801 ms</td>
<td>40 ms</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Ø</td>
<td>317.6 ms</td>
<td style="background-color: lime;">29.2 ms</td>
<td> - </td>
<td>802.7 ms</td>
<td style="background-color: lime;">71.8 ms</td>
</tr>
</tfoot>
</table>
<p><img src="https://s3.amazonaws.com/zeMirco/github/pouchdb-vs-couchbase/get-all-docs.png" title="get all documents" ></p>
<h3>Get document by id</h3>
<p>The third action was getting a single document by id. First one document was picked out of the 10000 and for the second run
out of 25000 documents.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// get a certain document by id</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">pouch_get</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'PouchDB - get single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">db</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">dummyId</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">doc</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'PouchDB - get single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">queryUser</span> <span class="o">=</span> <span class="nx">doc</span><span class="p">;</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// get a certain document by id</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">couchbase_get</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'Couchbase lite - get single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">$</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">globalUrl</span> <span class="o">+</span> <span class="s1">'performance/'</span> <span class="o">+</span> <span class="nx">dummyId</span><span class="p">)</span>
</span><span class='line'> <span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">doc</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'Couchbase lite - get single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">queryUser</span> <span class="o">=</span> <span class="nx">doc</span><span class="p">;</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<table class="table table-condensed full-width">
<thead>
<tr>
<th>#</th>
<th>PouchDB (10000 docs)</th>
<th>CB Lite (10000 docs)</th>
<th> - </th>
<th>PouchDB (25000 docs)</th>
<th>CB Lite (25000 docs)</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>5 ms</td>
<td>3 ms</td>
<td> - </td>
<td>8 ms</td>
<td>8 ms</td>
</tr>
<tr>
<td>2</td>
<td>2 ms</td>
<td>4 ms</td>
<td> - </td>
<td>2 ms</td>
<td>4 ms</td>
</tr>
<tr>
<td>3</td>
<td>2 ms</td>
<td>4 ms</td>
<td> - </td>
<td>3 ms</td>
<td>5 ms</td>
</tr>
<tr>
<td>4</td>
<td>3 ms</td>
<td>4 ms</td>
<td> - </td>
<td>3 ms</td>
<td>5 ms</td>
</tr>
<tr>
<td>5</td>
<td>2 ms</td>
<td>4 ms</td>
<td> - </td>
<td>3 ms</td>
<td>3 ms</td>
</tr>
<tr>
<td>6</td>
<td>3 ms</td>
<td>3 ms</td>
<td> - </td>
<td>4 ms</td>
<td>4 ms</td>
</tr>
<tr>
<td>7</td>
<td>3 ms</td>
<td>3 ms</td>
<td> - </td>
<td>3 ms</td>
<td>7 ms</td>
</tr>
<tr>
<td>8</td>
<td>2 ms</td>
<td>5 ms</td>
<td> - </td>
<td>3 ms</td>
<td>4 ms</td>
</tr>
<tr>
<td>9</td>
<td>2 ms</td>
<td>4 ms</td>
<td> - </td>
<td>3 ms</td>
<td>4 ms</td>
</tr>
<tr>
<td>10</td>
<td>2 ms</td>
<td>3 ms</td>
<td> - </td>
<td>4 ms</td>
<td>5 ms</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Ø</td>
<td style="background-color: lime;">2.6 ms</td>
<td>3.7 ms</td>
<td> - </td>
<td style="background-color: lime;">3.6 ms</td>
<td>4.9 ms</td>
</tr>
</tfoot>
</table>
<p><img src="https://s3.amazonaws.com/zeMirco/github/pouchdb-vs-couchbase/get-doc-by-id.png" title="get document by id" ></p>
<h3>Query db with view document and key</h3>
<p>When you run queries against each database you have to remember that Couchbase Lite needs view documents (like CouchDB)
compared to PouchDB that works with on-the-fly map/reduce functions. So whenever we initialize our app we have to save all
required view documents to Couchbase Lite (or check if they are already present). As you can see the mapping function is the
same for both databases.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// couchbase lite view</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">view</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'> <span class="s2">"id"</span><span class="o">:</span> <span class="s2">"_design/users"</span><span class="p">,</span>
</span><span class='line'> <span class="s2">"views"</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'> <span class="s2">"email"</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'> <span class="s2">"map"</span><span class="o">:</span> <span class="s2">"function(doc) { emit(doc.email, null) }"</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">};</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// save view to couchbase lite</span>
</span><span class='line'><span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">({</span>
</span><span class='line'> <span class="nx">type</span><span class="o">:</span> <span class="s1">'PUT'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">url</span><span class="o">:</span> <span class="nx">globalUrl</span> <span class="o">+</span> <span class="s1">'performance/_design/users'</span><span class="p">,</span>
</span><span class='line'> <span class="nx">data</span><span class="o">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">view</span><span class="p">),</span>
</span><span class='line'> <span class="nx">contentType</span> <span class="o">:</span> <span class="s1">'application/json'</span>
</span><span class='line'><span class="p">})</span>
</span><span class='line'><span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">log</span><span class="p">(</span><span class="s1">'view created'</span><span class="p">);</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now you can query each database.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// query pouchdb</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">pouch_query</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="c1">// mapping function</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">map</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">doc</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">emit</span><span class="p">(</span><span class="nx">doc</span><span class="p">.</span><span class="nx">email</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
</span><span class='line'> <span class="p">};</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'PouchDB - query single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="c1">// query PouchDB</span>
</span><span class='line'> <span class="nx">db</span><span class="p">.</span><span class="nx">query</span><span class="p">({</span><span class="nx">map</span><span class="o">:</span> <span class="nx">map</span><span class="p">},</span> <span class="p">{</span><span class="nx">key</span><span class="o">:</span> <span class="nx">queryUser</span><span class="p">.</span><span class="nx">email</span><span class="p">},</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'PouchDB - query single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="c1">// query the database</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">couchbase_query</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">time</span><span class="p">(</span><span class="s1">'Couchbase lite - query single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">({</span>
</span><span class='line'> <span class="nx">url</span><span class="o">:</span> <span class="nx">globalUrl</span> <span class="o">+</span> <span class="s1">'performance/_design/users/_view/email?key="'</span> <span class="o">+</span> <span class="nx">queryUser</span><span class="p">.</span><span class="nx">email</span> <span class="o">+</span> <span class="s1">'"'</span>
</span><span class='line'> <span class="p">})</span>
</span><span class='line'> <span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">doc</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">timeEnd</span><span class="p">(</span><span class="s1">'Couchbase lite - query single doc'</span><span class="p">);</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<table class="table table-condensed full-width">
<thead>