Apply feedback

This commit is contained in:
Amir Jafarian 2016-01-09 03:23:49 -05:00
parent 1e5c7dbfc4
commit 97c972e3ea
3 changed files with 9 additions and 13 deletions

View File

@ -271,6 +271,7 @@ Connector.defineAliases = function(cls, methodOrPropertyName, aliases) {
*/
Connector.defineAliases(Connector.prototype, 'execute', ['command', 'query']);
Connector.defineAliases(Connector.prototype, '_buildUpdate', 'buildUpdate');

View File

@ -8,6 +8,8 @@ var Transaction = require('./transaction');
module.exports = SQLConnector;
function NOOP() {}
/**
* Base class for connectors that connect to relational databases using SQL
* @class
@ -555,10 +557,7 @@ SQLConnector.prototype.buildDelete = function(model, where, options) {
*/
SQLConnector.prototype.destroyAll = function(model, where, options, cb) {
var stmt = this.buildDelete(model, where, options);
this._executeAlteringQuery(model, stmt.sql, stmt.params, options, function(err, data) {
if (cb)
cb(err, data);
});
this._executeAlteringQuery(model, stmt.sql, stmt.params, options, cb || NOOP);
};
// Alias to `destroyAll`. Juggler checks `destroyAll` only.
@ -668,10 +667,7 @@ SQLConnector.prototype._constructUpdateQuery = function(model, where, fields) {
*/
SQLConnector.prototype.update = function(model, where, data, options, cb) {
var stmt = this._buildUpdate(model, where, data, options);
this._executeAlteringQuery(model, stmt.sql, stmt.params, options, function(err, data) {
if (cb)
cb(err, data);
});
this._executeAlteringQuery(model, stmt.sql, stmt.params, options, cb || NOOP);
};
/**
@ -945,9 +941,8 @@ SQLConnector.prototype.buildOrderBy = function(model, order) {
* @returns {{names: Array, values: Array, properties: Array}}
*/
SQLConnector.prototype.buildFields = function(model, data, excludeIds) {
// var props = this.getModelDefinition(model).properties;
var keys = Object.keys(data);
return this._createFields(model, data, keys, excludeIds);
return this._buildFieldsForKeys(model, data, keys, excludeIds);
};
/**
@ -960,7 +955,7 @@ SQLConnector.prototype.buildFields = function(model, data, excludeIds) {
SQLConnector.prototype._buildReplaceFields = function(model, data, excludeIds) {
var props = this.getModelDefinition(model).properties;
var keys = Object.keys(props);
return this._createFields(model, data, keys, excludeIds);
return this._buildFieldsForKeys(model, data, keys, excludeIds);
};
/*
@ -970,7 +965,7 @@ SQLConnector.prototype._buildReplaceFields = function(model, data, excludeIds) {
* @param {Boolean} excludeIds Exclude id properties or not, default to false
* @private
*/
SQLConnector.prototype._createFields = function(model, data, keys, excludeIds) {
SQLConnector.prototype._buildFieldsForKeys = function(model, data, keys, excludeIds) {
var props = this.getModelDefinition(model).properties;
var fields = {
names: [], // field names

View File

@ -281,7 +281,7 @@ describe('sql connector', function() {
});
it('builds UPDATE', function() {
var sql = connector._buildUpdate('customer', {name: 'John'}, {vip: false});
var sql = connector.buildUpdate('customer', {name: 'John'}, {vip: false});
expect(sql.toJSON()).to.eql({
sql: 'UPDATE `CUSTOMER` SET `VIP`=$1 WHERE `NAME`=$2',
params: [false, 'John']