mysql-activerecord
Advanced tools
Comparing version 0.2.9 to 0.3.1
26
index.js
@@ -62,2 +62,6 @@ /** | ||
connection.useDatabase(settings.database); | ||
if (settings.charset) { | ||
connection.query('SET NAMES ' + settings.charset); | ||
} | ||
@@ -96,6 +100,13 @@ var whereClause = {}, | ||
for (var key in dataSet) { | ||
queryString += escapeFieldName(key) + "=" + connection.escape(dataSet[key]); | ||
if (y < getObjectSize(dataSet)) { | ||
queryString += separator; | ||
y++; | ||
if (dataSet.hasOwnProperty(key)) { | ||
if (typeof dataSet[key] !== 'object') { | ||
queryString += escapeFieldName(key) + "=" + connection.escape(dataSet[key]); | ||
} | ||
else if (typeof dataSet[key] === 'object' && dataSet[key] instanceof Array && dataSet[key].length > 0) { | ||
queryString += escapeFieldName(key) + ' in ("' + dataSet[key].join('", "') + '")'; | ||
} | ||
if (y < getObjectSize(dataSet)) { | ||
queryString += separator; | ||
y++; | ||
} | ||
} | ||
@@ -152,8 +163,11 @@ } | ||
this.where = function(whereSet, whereValue) { | ||
if (typeof whereValue === 'undefined' && typeof whereSet === 'object') { | ||
if (typeof whereSet === 'object' && typeof whereValue === 'undefined') { | ||
whereClause = mergeObjects(whereClause, whereSet); | ||
} | ||
else if (typeof whereSet === 'string' || typeof whereSet === 'number') { | ||
else if ((typeof whereSet === 'string' || typeof whereSet === 'number') && typeof whereValue != 'undefined') { | ||
whereClause[whereSet] = whereValue; | ||
} | ||
else if ((typeof whereSet === 'string' || typeof whereSet === 'number') && typeof whereValue === 'object' && whereValue instanceof Array) { | ||
whereClause[whereSet] = whereValue; | ||
} | ||
return that; | ||
@@ -160,0 +174,0 @@ }; |
{ "name" : "mysql-activerecord" | ||
, "version": "0.2.9" | ||
, "version": "0.3.1" | ||
, "devDependencies": {"node-mysql": "0.9.1"} | ||
, "main" : "./" | ||
} |
11962
261