Kouhei Sutou
null+****@clear*****
Fri Apr 25 13:51:17 JST 2014
Kouhei Sutou 2014-04-25 13:51:17 +0900 (Fri, 25 Apr 2014) New Revision: 002a083957f6e41f5c09c530492ee72dee72f8be https://github.com/droonga/express-droonga/commit/002a083957f6e41f5c09c530492ee72dee72f8be Message: load: support values Modified files: lib/adapter/api/groonga.js test/adapter/api/groonga/load.test.js Modified: lib/adapter/api/groonga.js (+9 -1) =================================================================== --- lib/adapter/api/groonga.js 2014-04-25 13:46:39 +0900 (cb99aea) +++ lib/adapter/api/groonga.js 2014-04-25 13:51:17 +0900 (fa255f3) @@ -45,11 +45,19 @@ module.exports = { } nRecords++; + var message = { table: request.query.table, // TODO: validate it - key: value._key, values: {} }; + Object.keys(value).forEach(function(key) { + if (key == '_key') { + message.key = value[key]; + } else { + message.values[key] = value[key]; + } + }); + connection.emit('add', message, function(error, message) { nResponses++; if (error) { Modified: test/adapter/api/groonga/load.test.js (+34 -0) =================================================================== --- test/adapter/api/groonga/load.test.js 2014-04-25 13:46:39 +0900 (7fe16cd) +++ test/adapter/api/groonga/load.test.js 2014-04-25 13:51:17 +0900 (fc66af5) @@ -121,6 +121,40 @@ suite('adapter/api/groonga: load', function() { }); }); }); + + suite('object style', function() { + test('one', function(done) { + var requestBody; + backend.reserveResponse(function(requestPacket) { + requestBody = requestPacket[2].body; + return utils.createReplyPacket(requestPacket, successMessage); + }); + var body = [ + { + _key: 'alice', + name: 'Alice', + age: 20 + } + ] + utils.post('/d/load?table=Users', JSON.stringify(body)) + .next(function(response) { + try { + assert.deepEqual(requestBody, + { + table: 'Users', + key: 'alice', + values: { + name: 'Alice', + age: 20 + } + }); + done(); + } catch (error) { + done(error); + } + }); + }); + }); }); suite('failure', function() { -------------- next part -------------- HTML����������������������������...Download