Navigation Menu

Skip to content

Commit

Permalink
load: support values
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 25, 2014
1 parent 49579c2 commit 002a083
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/adapter/api/groonga.js
Expand Up @@ -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) {
Expand Down
34 changes: 34 additions & 0 deletions test/adapter/api/groonga/load.test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 002a083

Please sign in to comment.