Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return dumped string as the result of "dump" command correctly

  • Loading branch information...
commit 0f32446d844fec54ad07b01e135f31858f8cc306 1 parent 812f99c
@piroor piroor authored
Showing with 46 additions and 7 deletions.
  1. +16 −5 lib/nroonga.js
  2. +8 −2 src/nroonga.coffee
  3. +22 −0 test/database.test.coffee
View
21 lib/nroonga.js
@@ -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);
View
10 src/nroonga.coffee
@@ -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
View
22 test/database.test.coffee
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.