[Groonga-commit] droonga/express-droonga at 71095f8 [master] Implement load command

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 25 11:26:17 JST 2014


Kouhei Sutou	2014-04-25 11:26:17 +0900 (Fri, 25 Apr 2014)

  New Revision: 71095f8ed4fe5566ff6604a8b222774f1f395221
  https://github.com/droonga/express-droonga/commit/71095f8ed4fe5566ff6604a8b222774f1f395221

  Message:
    Implement load command
    
    TODO:
    
      * validation
      * unit tests

  Modified files:
    lib/adapter/api/groonga.js
    package.json

  Modified: lib/adapter/api/groonga.js (+53 -0)
===================================================================
--- lib/adapter/api/groonga.js    2014-04-22 18:21:29 +0900 (43d501e)
+++ lib/adapter/api/groonga.js    2014-04-25 11:26:17 +0900 (c00f0c9)
@@ -1,4 +1,9 @@
 var command = require('../command');
+var jsonParser = require('jsonparse');
+
+var statusCodes = {
+  SUCCESS: 0
+};
 
 module.exports = {
   'groonga': new command.HTTPRequestResponse({
@@ -6,5 +11,53 @@ module.exports = {
     onRequest: function(request, connection) {
       connection.emit(request.params.commandName, request.query);
     }
+  }),
+  'groonga-load': new command.HTTPRequestResponse({
+    method: 'POST',
+    path:   '/d/load',
+    onRequest: function(request, connection, response) {
+      var parser = new jsonParser();
+      var nRecords = 0;
+      var nResponses = 0;
+      var nAdded = 0;
+      var isEnd = false;
+      var startTimeInMilliseconds = Date.now();
+
+      parser.onValue = function(value) {
+        if (parser.stack.length != 1) {
+          return;
+        }
+
+        nRecords++;
+        var message = {
+          table: request.query.table, // TODO: validate it
+          key: value._key,
+          values: {}
+        };
+        connection.emit('add', message, function(error, message) {
+          nResponses++;
+          if (!error && message) {
+            nAdded++;
+          }
+          if (isEnd && nRecords == nResponses) {
+            var statusCode = statusCodes.SUCCESS;
+            var elapsedTimeInMilliseconds =
+              Date.now() - startTimeInMilliseconds;
+            var header = [
+              statusCode,
+              startTimeInMilliseconds / 1000,
+              elapsedTimeInMilliseconds / 1000,
+            ];
+            response.jsonp([header, [nAdded]]);
+          }
+        });
+      };
+      request.on('data', function(chunk) {
+        parser.write(chunk);
+      });
+      request.once('end', function() {
+        isEnd = true;
+      });
+    }
   })
 };

  Modified: package.json (+1 -0)
===================================================================
--- package.json    2014-04-22 18:21:29 +0900 (5aa468f)
+++ package.json    2014-04-25 11:26:17 +0900 (8fb07a0)
@@ -25,6 +25,7 @@
     "fluent-logger": "*",
     "inflection": "*",
     "jade": "*",
+    "jsonparse": "*",
     "less-middleware": ">=0.2",
     "uber-cache": "*",
     "method-override": "*",
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index