null+****@clear*****
null+****@clear*****
2012年 6月 11日 (月) 18:20:25 JST
SHIMODA Hiroshi 2012-06-11 18:20:25 +0900 (Mon, 11 Jun 2012)
New Revision: 0f32446d844fec54ad07b01e135f31858f8cc306
Log:
Return dumped string as the result of "dump" command correctly
Modified files:
lib/nroonga.js
src/nroonga.coffee
test/database.test.coffee
Modified: lib/nroonga.js (+16 -5)
===================================================================
--- lib/nroonga.js 2012-06-09 20:27:21 +0900 (0bbadbd)
+++ lib/nroonga.js 2012-06-11 18:20:25 +0900 (84ee838)
@@ -1,5 +1,6 @@
+// Generated by CoffeeScript 1.3.3
(function() {
- var msgpack, nroonga, optionsToCommandString, overrideOutputType;
+ var formatResult, msgpack, nroonga, optionsToCommandString, overrideOutputType;
nroonga = module.exports = require('../build/Release/nroonga_bindings.node');
@@ -29,15 +30,25 @@
return options;
};
+ formatResult = function(result, command) {
+ if (command === 'dump') {
+ return result.toString('UTF-8');
+ } else {
+ return msgpack.unpack(result);
+ }
+ };
+
nroonga.Database.prototype.commandSync = function(command, options) {
var result;
- if (options == null) options = {};
+ if (options == null) {
+ options = {};
+ }
options = overrideOutputType(options, 'msgpack');
result = this.commandSyncString(optionsToCommandString(command, options));
if (result.length > 0) {
- return msgpack.unpack(result);
+ return formatResult(result, command);
} else {
- return;
+ return void 0;
}
};
@@ -52,7 +63,7 @@
if (error != null) {
return callback(error);
} else {
- return callback(void 0, msgpack.unpack(data));
+ return callback(void 0, formatResult(data, command));
}
} : void 0;
return this.commandString(optionsToCommandString(command, options), wrappedCallback);
Modified: src/nroonga.coffee (+8 -2)
===================================================================
--- src/nroonga.coffee 2012-06-09 20:27:21 +0900 (469f715)
+++ src/nroonga.coffee 2012-06-11 18:20:25 +0900 (27e806f)
@@ -16,11 +16,17 @@ overrideOutputType = (optionsGiven, type) ->
options.output_type = type
options
+formatResult = (result, command) ->
+ if command == 'dump'
+ result.toString('UTF-8')
+ else
+ msgpack.unpack(result)
+
nroonga.Database.prototype.commandSync = (command, options={}) ->
options = overrideOutputType(options, 'msgpack')
result = this.commandSyncString(optionsToCommandString(command, options))
if result.length > 0
- msgpack.unpack(result)
+ formatResult(result, command)
else
undefined
@@ -35,7 +41,7 @@ nroonga.Database.prototype.command = (command, options, callback) ->
if error?
callback error
else
- callback undefined, msgpack.unpack(data)
+ callback undefined, formatResult(data, command)
else
undefined
Modified: test/database.test.coffee (+22 -0)
===================================================================
--- test/database.test.coffee 2012-06-09 20:27:21 +0900 (eac819b)
+++ test/database.test.coffee 2012-06-11 18:20:25 +0900 (aae0773)
@@ -101,3 +101,25 @@ describe 'database with data stored', ->
query: 'search ranguba'
matched[0][0][0].should.equal(1)
done()
+
+ it 'should dump all records', (done) ->
+ withTestDatabase (db) ->
+ result = db.commandSync('dump', tables: 'Site')
+ expected_dump = 'table_create Site TABLE_HASH_KEY ShortText\n' +
+ 'column_create Site title COLUMN_SCALAR ShortText\n' +
+ 'table_create Terms TABLE_PAT_KEY|KEY_NORMALIZE ' +
+ 'ShortText --default_tokenizer TokenBigram\n' +
+ 'column_create Terms entry_title ' +
+ 'COLUMN_INDEX|WITH_POSITION Site title\n' +
+ 'load --table Site\n' +
+ '[\n' +
+ '["_key","title"],\n' +
+ '["http://groonga.org/","groonga - An open-source ' +
+ 'fulltext search engine and column store"],\n' +
+ '["http://groonga.rubyforge.org/","Fulltext search by ' +
+ 'Ruby with groonga - Ranguba"],\n' +
+ '["http://mroonga.github.com/","Groonga storage ' +
+ 'engine - Fast fulltext search on MySQL"]\n' +
+ ']'
+ result.should.equal(expected_dump)
+ done()