Skip to content

Commit

Permalink
increased code coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerkoser committed Mar 11, 2015
1 parent 532d258 commit 526caaa
Show file tree
Hide file tree
Showing 89 changed files with 2,302 additions and 676 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
coverage
build
coverage.html
config.json
hdb.js
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git*
examples/
test/
coverage/
coverage/
bin/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.10"
- "0.12"
80 changes: 41 additions & 39 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,39 +206,41 @@ Client.prototype.destroy = function destroy(err) {
this._connection.destroy(err);
};

Client.prototype.prepare = function prepare(command, cb) {
var args = normalizeArguments.apply(null, arguments);
var statement = this._createStatement(this._connection, args[1]);
this._connection.prepare({
command: args[0]
}, function handleReply(err, reply) {
statement.handle(err, reply, args[2]);
});
return this;
Client.prototype.prepare = function prepare(command, options, cb) {
/* jshint unused:false */
return Client.prototype._prepare.apply(this, normalizeArguments(arguments, {}));
};

Client.prototype.exec = function exec(command, cb) {
var args = normalizeArguments.apply(null, arguments);
var result = this._createResult(this._connection, util.extend({
Client.prototype.exec = function exec(command, options, cb) {
/* jshint unused:false */
return Client.prototype._execute.apply(this, normalizeArguments(arguments, {
autoFetch: true
}, args[1]));
}));
};

Client.prototype.execute = function execute(command, options, cb) {
/* jshint unused:false */
return Client.prototype._execute.apply(this, normalizeArguments(arguments, {
autoFetch: false
}));
};

Client.prototype._execute = function _execute(command, options, cb) {
var result = this._createResult(this._connection, options);
this._connection.executeDirect({
command: args[0]
command: command
}, function handleReply(err, reply) {
result.handle(err, reply, args[2]);
result.handle(err, reply, cb);
});
return this;
};

Client.prototype.execute = function execute(command, cb) {
var args = normalizeArguments.apply(null, arguments);
var result = this._createResult(this._connection, util.extend({
autoFetch: false
}, args[1]));
this._connection.executeDirect({
command: args[0]
Client.prototype._prepare = function _prepare(command, options, cb) {
var statement = this._createStatement(this._connection, options);
this._connection.prepare({
command: command
}, function handleReply(err, reply) {
result.handle(err, reply, args[2]);
statement.handle(err, reply, cb);
});
return this;
};
Expand Down Expand Up @@ -266,33 +268,33 @@ Client.prototype._addListeners = function _addListeners(connection) {
connection.on('close', onclose);
};

Client.prototype._createConnection = function _createConnection(settings) {
return new Connection(settings);
};
Client.prototype._createConnection = Connection.create;

Client.prototype._createResult = function _createResult(connection, options) {
return new Result(connection, options);
};
Client.prototype._createResult = Result.create;

Client.prototype._createStatement = function _createStatement(connection, options) {
return new Statement(connection, options);
};
Client.prototype._createStatement = Statement.create;

function normalizeArguments(command, options, cb) {
function normalizeArguments(args, defaults) {
var command = args[0];
var options = args[1];
var cb = args[2];
defaults = defaults;
if (util.isFunction(options)) {
cb = options;
if (util.isObject(command)) {
options = util.extend({}, command);
if (options.sql) {
command = options.sql;
options.sql = undefined;
} else {
options = util.extend(defaults, command);
if (options.command) {
command = options.command;
options.command = undefined;
} else if (options.sql) {
command = options.sql;
options.sql = undefined;
}
} else {
options = {};
options = defaults;
}
} else {
options = util.extend(defaults, options);
}
return [command, options, cb];
}
Loading

0 comments on commit 526caaa

Please sign in to comment.