Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,73 @@ | ||
| // Generated by CoffeeScript 1.3.3 | ||
| (function() { | ||
| var formatResult, msgpack, nroonga, optionsToCommandString, overrideOutputType; | ||
| var nroonga = module.exports = require('../build/Release/nroonga_bindings.node'); | ||
| var msgpack = require('msgpack2'); | ||
|
|
||
| nroonga = module.exports = require('../build/Release/nroonga_bindings.node'); | ||
| function optionsToCommandString(command, options) { | ||
| var args, key; | ||
| args = [command]; | ||
|
|
||
| msgpack = require('msgpack2'); | ||
|
|
||
| optionsToCommandString = function(command, options) { | ||
| var args, key, value; | ||
| args = [command]; | ||
| if (options != null) { | ||
| for (key in options) { | ||
| value = options[key]; | ||
| if (value != null) { | ||
| args.push('--' + key); | ||
| args.push(JSON.stringify(value)); | ||
| } | ||
| if (options) { | ||
| for (key in options) { | ||
| if (options[key] != null) { | ||
| args.push('--' + key); | ||
| args.push(JSON.stringify(options[key])); | ||
| } | ||
| } | ||
| return args.join(' '); | ||
| }; | ||
| } | ||
| return args.join(' '); | ||
| } | ||
|
|
||
| overrideOutputType = function(optionsGiven, type) { | ||
| var key, options, value; | ||
| options = {}; | ||
| for (key in optionsGiven) { | ||
| value = optionsGiven[key]; | ||
| options[key] = value; | ||
| } | ||
| options.output_type = type; | ||
| return options; | ||
| }; | ||
| function overrideOutputType (optionsGiven, type) { | ||
| var key, options; | ||
| options = {}; | ||
| for (key in optionsGiven) { | ||
| options[key] = optionsGiven[key]; | ||
| } | ||
| options.output_type = type; | ||
| return options; | ||
| } | ||
|
|
||
| formatResult = function(result, command) { | ||
| if (command === 'dump') { | ||
| return result.toString('UTF-8'); | ||
| function formatResult(result, command) { | ||
| if (command === 'dump') { | ||
| return result.toString('UTF-8'); | ||
| } else { | ||
| if (result.length > 0) { | ||
| return msgpack.unpack(result); | ||
| } else { | ||
| if (result.length > 0) { | ||
| return msgpack.unpack(result); | ||
| } else { | ||
| return void 0; | ||
| } | ||
| return null; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| nroonga.Database.prototype.commandSync = function(command, options) { | ||
| var result; | ||
| if (options == null) { | ||
| options = {}; | ||
| } | ||
| options = overrideOutputType(options, 'msgpack'); | ||
| result = this.commandSyncString(optionsToCommandString(command, options)); | ||
| return formatResult(result, command); | ||
| }; | ||
| nroonga.Database.prototype.commandSync = function(command, options) { | ||
| var overridedOptions = overrideOutputType(options || {}, 'msgpack'); | ||
| var commandString = optionsToCommandString(command, overridedOptions); | ||
|
|
||
| nroonga.Database.prototype.command = function(command, options, callback) { | ||
| var wrappedCallback; | ||
| if (arguments.length === 2) { | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
| options = overrideOutputType(options, 'msgpack'); | ||
| wrappedCallback = callback != null ? function(error, data) { | ||
| if (error != null) { | ||
| var result = this.commandSyncString(commandString); | ||
| return formatResult(result, command); | ||
| }; | ||
|
|
||
| nroonga.Database.prototype.command = function(command, options, callback) { | ||
| var wrappedCallback = null; | ||
| var overridedOptions; | ||
| var commandString; | ||
|
|
||
| if (arguments.length === 2) { | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
|
|
||
| if (callback) { | ||
| wrappedCallback = function(error, data) { | ||
| if (error) { | ||
| return callback(error); | ||
| } else { | ||
| return callback(void 0, formatResult(data, command)); | ||
| return callback(null, formatResult(data, command)); | ||
| } | ||
| } : void 0; | ||
| return this.commandString(optionsToCommandString(command, options), wrappedCallback); | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| overridedOptions = overrideOutputType(options, 'msgpack'); | ||
| commandString = optionsToCommandString(command, overridedOptions); | ||
|
|
||
| }).call(this); | ||
| return this.commandString(commandString, wrappedCallback); | ||
| }; |