Skip to content

Commit

Permalink
Fixes duplicated debug in mysql for aggregate functions, creates .cal…
Browse files Browse the repository at this point in the history
…l() in aggregates for generic functions (#204)
  • Loading branch information
dresende committed Jul 5, 2013
1 parent 21de079 commit 3a2b196
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
20 changes: 15 additions & 5 deletions lib/AggregateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ function AggregateFunctions(opts) {

return this;
},
call: function (fun, args) {
if (args.length > 0) {
aggregates[aggregates.length - 1].push({ f: fun, a: args, alias: aggregateAlias(fun, args) });
// aggregates.push([]);
} else {
aggregates[aggregates.length - 1].push({ f: fun, alias: aggregateAlias(fun, args) });
}

if (fun == "distinct") {
used_distinct = true;
}

return this;
},
get: function (cb) {
if (typeof cb != "function") {
throw ErrorCodes.generateError(ErrorCodes.MISSING_CALLBACK, "You must pass a callback to Model.aggregate().get()");
Expand All @@ -86,7 +100,7 @@ function AggregateFunctions(opts) {

for (i = 0; i < aggregates.length; i++) {
for (j = 0; j < aggregates[i].length; j++) {
query[aggregates[i][j].f](aggregates[i][j].a, aggregates[i][j].alias);
query.fun(aggregates[i][j].f, aggregates[i][j].a, aggregates[i][j].alias);
}
}

Expand All @@ -107,10 +121,6 @@ function AggregateFunctions(opts) {

query = query.build();

if (opts.driver.opts && opts.driver.opts.debug) {
require("./Debug").sql(opts.driver_name, query);
}

opts.driver.execQuery(query, function (err, data) {
if (err) {
return cb(err);
Expand Down
6 changes: 3 additions & 3 deletions lib/Drivers/DML/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ Driver.prototype.getQuery = function () {
};

Driver.prototype.execQuery = function (query, cb) {
if (this.opts.debug) {
require("../../Debug").sql('mysql', query);
}
if (this.opts.pool) {
this.poolQuery(query, cb);
} else {
this.db.query(query, cb);
}
if (this.opts.debug) {
require("../../Debug").sql('mysql', query);
}
};

Driver.prototype.find = function (fields, table, conditions, opts, cb) {
Expand Down
8 changes: 7 additions & 1 deletion lib/Drivers/DML/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var switchableFunctions = {
});
},
execQuery: function (query, cb) {
if (this.opts.debug) {
require("../../Debug").sql('mysql', query);
}
this.db.connect(this.config, function (err, client, done) {
if (err) return cb(err);

Expand All @@ -75,7 +78,10 @@ var switchableFunctions = {
this.db.connect(cb);
},
execQuery: function (query, cb) {
this.db.query(query, function(err, result) {
if (this.opts.debug) {
require("../../Debug").sql('mysql', query);
}
this.db.query(query, function (err, result) {
if (err) {
cb(err);
} else {
Expand Down
5 changes: 4 additions & 1 deletion lib/Drivers/DML/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Driver.prototype.getQuery = function () {
};

Driver.prototype.execQuery = function (query, cb) {
if (this.opts.debug) {
require("../../Debug").sql('mysql', query);
}
this.db.all(query, cb);
};

Expand Down Expand Up @@ -262,7 +265,7 @@ Driver.prototype.propertyToValue = function (value, property) {
millis = '0' + millis;
}
strdate += ' ' + hours + ':' + minutes + ':' + seconds + '.' + millis + '000';
return strdate;
return strdate;
}

}
Expand Down

0 comments on commit 3a2b196

Please sign in to comment.