1. Sean Wilkinson
  2. qmachine

Commits

Sean Wilkinson  committed 88644fb

Preparations for an exodus from CouchDB

  • Participants
  • Parent commits c7937e2
  • Branches master

Comments (0)

Files changed (1)

File src/npm-package/lib/couch-log-ddoc.js

View file
  • Ignore whitespace
 
 //- couch-log-ddoc.js ~~
 //                                                      ~~ (c) SRW, 31 Mar 2013
-//                                                  ~~ last updated 10 Apr 2013
+//                                                  ~~ last updated 23 Apr 2013
 
 (function () {
     'use strict';
 
  // Pragmas
 
-    /*global exports: false, sum: false */
+    /*global exports: false, getRow: false, send: false, sum: false */
 
     /*jshint maxparams: 2, quotmark: single, strict: true */
 
     /*jslint couch: true, indent: 4, maxlen: 80, nomen: true */
 
     /*properties
-        box_frequency, hasOwnProperty, _id, ip, ip_frequency, ips, lists, map,
-        reduce, replace, shows, split, updates, url, views
+        'as-array', box_frequency, hasOwnProperty, _id, identity, ip,
+        ip_frequency, ips, lists, map, method, reduce, replace, shows, slice,
+        split, stringify, timestamp, updates, url, value, views
     */
 
  // Out-of-scope definitions
 
     exports._id = '_design/app';
 
-    exports.lists = {};
+    exports.lists = {
+        'as-array': function () {
+         // This function can be useful for dumping the entire contents of the
+         // database for export into another database:
+         //
+         //     $ curl -o couch-dump.json \
+         //         localhost:5984/traffic/_design/app/_list/as-array/identity
+         //
+            var first, row;
+            first = true;
+            send('[');
+            while ((row = getRow()) !== null) {
+                if (first === true) {
+                    first = false;
+                    send(JSON.stringify(row.value));
+                } else {
+                    send(',' + JSON.stringify(row.value));
+                }
+            }
+            send(']');
+            return;
+        }
+    };
 
     exports.shows = {};
 
             }
         },
 
+        identity: {
+            map: function (doc) {
+             // This function needs documentation.
+                if (doc._id.slice(0, 8) !== '_design/') {
+                    emit(null, {
+                        ip:         doc.ip,
+                        method:     doc.method,
+                        timestamp:  doc.timestamp,
+                        url:        doc.url
+                    });
+                }
+                return;
+            }
+        },
+
         ip_frequency: {
             map: function (doc) {
              // This function needs documentation.