Permalink
Browse files

Made a few fixes on mysql and sql helpers

  • Loading branch information...
1 parent 01ea63a commit c10de3efe8c2256ccad0a9f9fe7db80e07bcc6b2 @dresende committed Jul 23, 2012
Showing with 16 additions and 18 deletions.
  1. +4 −6 lib/databases/helpers.js
  2. +12 −12 lib/databases/mysql.js
View
@@ -115,7 +115,7 @@ module.exports = {
query = query.replace("%values", opts.info.query);
- //console.log(query);
+ //console.log(query, opts.info.values);
return opts.db.query(query, opts.info.values, this.handleSqlUpdateCall(opts.callback));
},
@@ -126,7 +126,7 @@ module.exports = {
query = query.replace("%fields", Object.keys(opts.data).map(opts.escape).join(", "));
query = query.replace("%values", opts.info.escapes.join(", "));
- //console.log(query);
+ //console.log(query, opts.info.values);
return opts.db.query(query, opts.info.values, this.handleSqlInsertCall(opts.callback));
},
@@ -135,8 +135,7 @@ module.exports = {
if (err) {
return cb(err);
}
-
- return callback(null);
+ return cb(null);
};
},
@@ -145,8 +144,7 @@ module.exports = {
if (err) {
return cb(err);
}
-
- return callback(null, info.insertId);
+ return cb(null, info.insertId);
};
},
View
@@ -164,7 +164,7 @@ DBClient.prototype.selectRecords = function (collection, config) {
query += helpers.buildSqlLimit(config.limit, config.skip);
}
- //console.log(_query, _values);
+ //console.log(query, values);
if (typeof config.callback == "function") {
this._client.query(query, values, function (err, info) {
@@ -179,7 +179,7 @@ DBClient.prototype.selectRecords = function (collection, config) {
return new helpers.DBQuery(this._client.query(query, values));
}
};
-DBClient.prototype.clearRecords = function (collection, config, callback) {
+DBClient.prototype.clearRecords = function (collection, config) {
var query = "DELETE FROM " + this._escapeId(this._collectionToTable(collection));
var tmp;
var values = [];
@@ -207,17 +207,17 @@ DBClient.prototype.clearRecords = function (collection, config, callback) {
config.callback(null, info);
});
};
-DBClient.prototype.saveRecord = function (idProp, collection, data, callback) {
- if (idProp && data[idProp] && parseInt(data[idProp], 10) > 0) {
- var id = data[idProp];
- delete data[idProp];
+DBClient.prototype.saveRecord = function (propertyId, collection, data, cb) {
+ if (propertyId && data[propertyId] && parseInt(data[propertyId], 10) > 0) {
+ var id = data[propertyId];
+ delete data[propertyId];
- this._updateRecord(collection, idProp, data, id, callback);
+ this._updateRecord(collection, propertyId, data, id, cb);
} else {
- this._insertRecord(collection, data, callback);
+ this._insertRecord(collection, data, cb);
}
};
-DBClient.prototype._insertRecord = function (collection, data, callback) {
+DBClient.prototype._insertRecord = function (collection, data, cb) {
return helpers.createSqlInsert({
table: this._collectionToTable(collection),
escape: this._escapeId,
@@ -228,10 +228,10 @@ DBClient.prototype._insertRecord = function (collection, data, callback) {
orm: this._orm,
data: data,
db: this._client,
- callback: helpers.handleSqlInsertCall(callback)
+ callback: cb
});
};
-DBClient.prototype._updateRecord = function (collection, idProp, data, id, callback) {
+DBClient.prototype._updateRecord = function (collection, idProp, data, id, cb) {
return helpers.createSqlUpdate({
table: this._collectionToTable(collection),
key: idProp,
@@ -242,7 +242,7 @@ DBClient.prototype._updateRecord = function (collection, idProp, data, id, callb
boolean_convert: this._booleanToSqlValue
}),
db: this._client,
- callback: helpers.handleSqlUpdateCall(callback)
+ callback: cb
});
};
DBClient.prototype._addQueryConditions = function (conditions) {

0 comments on commit c10de3e

Please sign in to comment.