Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Not actually serializing, make method public for testability

  • Loading branch information...
commit 4a4492c0c6e615ecbdbf75bf8e19d87b02773a72 1 parent 189d64d
mde authored
View
22 lib/adapters/mongo/index.js
@@ -53,7 +53,7 @@ Adapter.prototype.constructor = Adapter;
utils.mixin(Adapter.prototype, new (function () {
- this._serializeSortOrder = function (sort) {
+ this.transformSortOrder = function (sort) {
var ret = {};
if (sort) {
for (var p in sort) {
@@ -63,27 +63,27 @@ utils.mixin(Adapter.prototype, new (function () {
return ret;
};
- this._serializeConditions = function (conditions) {
- return this._serializeOperation(conditions);
+ this.transformConditions = function (conditions) {
+ return this.transformOperation(conditions);
};
- this._serializeOperation = function (op) {
+ this.transformOperation = function (op) {
var self = this
, ops = []
, ret = {};
if (!op.isEmpty()) {
if (op.type == 'not') {
- ret = {'$nor': [self._serializeOperation(op.operand())]};
+ ret = {'$nor': [self.transformOperation(op.operand())]};
}
else {
// 'and' or 'or', ignore 'null' for now
ret['$' + op.type] = ops;
op.forEach(function (o) {
if (o instanceof operation.OperationBase) {
- ops.push(self._serializeOperation(o));
+ ops.push(self.transformOperation(o));
}
else {
- ops.push(self._serializeComparison(o));
+ ops.push(self.transformComparison(o));
}
});
}
@@ -91,7 +91,7 @@ utils.mixin(Adapter.prototype, new (function () {
return ret;
};
- this._serializeComparison = function (comp) {
+ this.transformComparison = function (comp) {
var ret = {}
, nocase = comp.opts.nocase
, complex
@@ -183,8 +183,8 @@ utils.mixin(Adapter.prototype, new (function () {
}
// Collection
else {
- conditions = this._serializeConditions(query.conditions);
- sort = this._serializeSortOrder(query.opts.sort);
+ conditions = this.transformConditions(query.conditions);
+ sort = this.transformSortOrder(query.opts.sort);
//var util = require('util');
//console.log(util.inspect(conditions, false, null));
@@ -262,7 +262,7 @@ utils.mixin(Adapter.prototype, new (function () {
}
// Collection
else {
- conditions = this._serializeConditions(query.conditions);
+ conditions = this.transformConditions(query.conditions);
}
collection.remove(conditions, function (err, data) {
var inst
View
34 lib/adapters/riak/index.js
@@ -131,16 +131,16 @@ utils.mixin(Adapter.prototype, new (function () {
, 'or': '||'
};
- this._serializeSortOrder = function (sort) {
+ this.transformSortOrder = function (sort) {
return sort ? JSON.stringify(sort).replace(/"/g, "'") : '';
};
- this._serializeConditions = function (conditions) {
- var cond = this._serializeOperation(conditions);
+ this.transformConditions = function (conditions) {
+ var cond = this.transformOperation(conditions);
return cond;
};
- this._serializeOperation = function (op) {
+ this.transformOperation = function (op) {
var self = this
, ops = [];
if (op.isEmpty()) {
@@ -149,14 +149,14 @@ utils.mixin(Adapter.prototype, new (function () {
else {
op.forEach(function (o) {
if (o instanceof operation.OperationBase) {
- ops.push(self._serializeOperation(o));
+ ops.push(self.transformOperation(o));
}
else {
- ops.push(self._serializeComparison(o));
+ ops.push(self.transformComparison(o));
}
});
if (op.type == 'not') {
- return '(!(' + self._serializeOperation(op.operand()) + '))';
+ return '(!(' + self.transformOperation(op.operand()) + '))';
}
else {
return '(' + ops.join(' ' + _operationSymbols[op.type.toLowerCase()] +
@@ -165,14 +165,14 @@ utils.mixin(Adapter.prototype, new (function () {
}
};
- this._serializeComparison = function (comp) {
+ this.transformComparison = function (comp) {
var ret = ''
- , name = this._serializeComparisonFieldName(comp)
+ , name = this.transformComparisonFieldName(comp)
, arr = [];
switch (true) {
case comp instanceof comparison.LikeComparison:
ret = name + '.indexOf(' +
- this._serializeComparisonValue(comp) + ') === 0';
+ this.transformComparisonValue(comp) + ') === 0';
break;
case comp instanceof comparison.InclusionComparison:
comp.value.forEach(function (item) {
@@ -182,14 +182,14 @@ utils.mixin(Adapter.prototype, new (function () {
ret = arr.join(' || ');
break;
default:
- ret = [name, this._serializeComparisonComparator(comp),
- this._serializeComparisonValue(comp)].join(' ');
+ ret = [name, this.transformComparisonComparator(comp),
+ this.transformComparisonValue(comp)].join(' ');
}
return ret;
};
- this._serializeComparisonFieldName = function (comp) {
+ this.transformComparisonFieldName = function (comp) {
// Use bracket-notation, in case field-name has special chars
// or is a reserved word
var name = 'data[\'' + comp.field + '\']';
@@ -199,12 +199,12 @@ utils.mixin(Adapter.prototype, new (function () {
return name;
};
- this._serializeComparisonComparator = function (comp) {
+ this.transformComparisonComparator = function (comp) {
var comparator = comp.jsComparatorString;
return comparator;
};
- this._serializeComparisonValue = function (comp) {
+ this.transformComparisonValue = function (comp) {
return _serializeForDataType(comp.datatype, comp.value);
};
@@ -270,8 +270,8 @@ utils.mixin(Adapter.prototype, new (function () {
}
// Teh mapreducy
else {
- conditions = this._serializeConditions(query.conditions);
- sort = this._serializeSortOrder(query.opts.sort);
+ conditions = this.transformConditions(query.conditions);
+ sort = this.transformSortOrder(query.opts.sort);
requestOpts = {
url: '/mapred'
, method: 'POST'
View
30 lib/adapters/sql/base.js
@@ -28,7 +28,7 @@ utils.mixin(Adapter.prototype, new (function () {
return columnName;
};
- this._serializeValue = function (prop, datatype) {
+ this.transformValue = function (prop, datatype) {
var ret;
// FIXME: Is special-casing this the right way to go?
if (prop === null || prop === undefined || prop == '') {
@@ -43,7 +43,7 @@ utils.mixin(Adapter.prototype, new (function () {
return ret;
};
- this._serializeSortOrder = function (sort) {
+ this.transformSortOrder = function (sort) {
var sql = ''
, fieldArr = [];
for (var p in sort) {
@@ -53,12 +53,12 @@ utils.mixin(Adapter.prototype, new (function () {
return sql;
}
- this._serializeConditions = function (conditions) {
- var sql = this._serializeOperation(conditions);
+ this.transformConditions = function (conditions) {
+ var sql = this.transformOperation(conditions);
return sql;
};
- this._serializeOperation = function (op) {
+ this.transformOperation = function (op) {
var self = this
, ops = [];
if (op.isEmpty()) {
@@ -66,15 +66,15 @@ utils.mixin(Adapter.prototype, new (function () {
}
else {
if (op.type == 'not') {
- return 'NOT (' + self._serializeOperation(op.operand()) + ')';
+ return 'NOT (' + self.transformOperation(op.operand()) + ')';
}
else {
op.forEach(function (o) {
if (o instanceof operation.OperationBase) {
- ops.push(self._serializeOperation(o));
+ ops.push(self.transformOperation(o));
}
else {
- ops.push(self._serializeComparison(o));
+ ops.push(self.transformComparison(o));
}
});
return '(' + ops.join(' ' + op.type.toUpperCase() + ' ') + ')';
@@ -82,13 +82,13 @@ utils.mixin(Adapter.prototype, new (function () {
}
};
- this._serializeComparison = function (comp) {
- return [this._serializeComparisonFieldName(comp),
- this._serializeComparisonComparator(comp),
- this._serializeComparisonValue(comp)].join(' ');
+ this.transformComparison = function (comp) {
+ return [this.transformComparisonFieldName(comp),
+ this.transformComparisonComparator(comp),
+ this.transformComparisonValue(comp)].join(' ');
};
- this._serializeComparisonFieldName = function (comp) {
+ this.transformComparisonFieldName = function (comp) {
var name = this._columnizePropertyName(comp.field);
if (comp.opts.nocase) {
name = 'LOWER(' + name + ')';
@@ -96,7 +96,7 @@ utils.mixin(Adapter.prototype, new (function () {
return name;
};
- this._serializeComparisonComparator = function (comp) {
+ this.transformComparisonComparator = function (comp) {
var val = comp.value
, comparator = comp.sqlComparatorString;
if (val === null) {
@@ -106,7 +106,7 @@ utils.mixin(Adapter.prototype, new (function () {
return comparator;
};
- this._serializeComparisonValue = function (comp) {
+ this.transformComparisonValue = function (comp) {
var val = comp.value
, ret = ''
, serialize = function (val) {
View
12 lib/adapters/sql/postgres.js
@@ -61,7 +61,7 @@ utils.mixin(Adapter.prototype, new (function () {
this.load = function (query, callback) {
var sql = ''
- , conditions = this._serializeConditions(query.conditions)
+ , conditions = this.transformConditions(query.conditions)
, opts = query.opts
, sort = opts.sort
, limit = opts.limit
@@ -73,7 +73,7 @@ utils.mixin(Adapter.prototype, new (function () {
sql += 'WHERE ' + conditions;
}
if (sort) {
- sql += this._serializeSortOrder(sort);
+ sql += this.transformSortOrder(sort);
}
if (skip) {
sql += ' OFFSET ' + skip;
@@ -129,14 +129,14 @@ utils.mixin(Adapter.prototype, new (function () {
}) +
' = ';
- update += this._serializeValue(prop, def.datatype);
+ update += this.transformValue(prop, def.datatype);
updates.push(update);
}
}
sql += 'UPDATE ' + this._tableizeModelName(modelName) + ' SET ';
sql += updates.join(', ') + ' ';
- sql += 'WHERE ' + this._serializeConditions(query.conditions);
+ sql += 'WHERE ' + this.transformConditions(query.conditions);
sql += ';'
this.exec(sql, function (err, res) {
@@ -155,7 +155,7 @@ utils.mixin(Adapter.prototype, new (function () {
this.remove = function (query, callback) {
var sql = '';
sql += 'DELETE FROM ' + this._tableizeModelName(query.model.modelName) + ' ';
- sql += 'WHERE ' + this._serializeConditions(query.conditions);
+ sql += 'WHERE ' + this.transformConditions(query.conditions);
sql += ';'
this.exec(sql, function (err, data) {
if (err) {
@@ -201,7 +201,7 @@ utils.mixin(Adapter.prototype, new (function () {
def = props[p];
prop = item[p];
// Use the same definition of NULL as for updates
- prop = self._serializeValue(prop, def.datatype);
+ prop = self.transformValue(prop, def.datatype);
if (prop != 'NULL') {
cols.push(self._columnizePropertyName(p, {
useQuotes: true
Please sign in to comment.
Something went wrong with that request. Please try again.