Permalink
Browse files

Refactor utils. Update mocha version in package json.

  • Loading branch information...
1 parent 2762ff5 commit fbcb86e04fc2e36759844a25642a997991d62993 @thadclay thadclay committed Dec 12, 2012
View
@@ -1,6 +1,5 @@
SHELL := /bin/bash
-node-command := xargs -n 1 -I file expresso file
file=*.test.js
unit_files=`find test/unit -name '$(file)' -type f -print0 | xargs -0 echo`
integration_files=`find test/integration -name '$(file)' -type f -print0 | xargs -0 echo`
View
@@ -1 +1 @@
-module.exports = require('./lib/fast_legs');
+module.exports = require('./lib');
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,31 @@
+/**
+ * Module dependencies.
+ */
+
+var _ = require('underscore');
+var Utils = require('../../utils');
+
+/**
+ * mysql - Utils.
+ */
+
+var utils = new Utils();
+
+utils.quote = function(outValues, operator) {
+ if (operator === 'IN' || operator === 'NOT IN') {
+ var valuePos = _.range(1, outValues.length+1);
+ var values = _.reduce(valuePos, function(memo, pos, i) {
+ memo += '?';
+ if (i+1 !== valuePos.length) memo += ',';
+ return memo;
+ }, '');
+ return '(' + values + ')';
+ } else if (operator === 'ILIKE') {
+ return 'UPPER(?)';
+ } else {
+ return '?';
+ }
+};
+
+module.exports = utils;
+
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,29 @@
+/**
+ * Module dependencies.
+ */
+
+var _ = require('underscore');
+var Utils = require('../../utils');
+
+/**
+ * pg - Utils.
+ */
+
+var utils = new Utils();
+
+utils.quote = function(outValues, operator) {
+ if (operator === 'IN' || operator === 'NOT IN') {
+ var valuePos = _.range(1, outValues.length+1);
+ var values = _.reduce(valuePos, function(memo, pos, i) {
+ memo += '$' + pos.toString();
+ if (i+1 !== valuePos.length) memo += ',';
+ return memo;
+ }, '');
+ return '(' + values + ')';
+ } else {
+ return '$' + outValues.length;
+ }
+};
+
+module.exports = utils;
+
@@ -1,109 +0,0 @@
-/**
- * Module dependencies.
- */
-
-var _ = require('underscore');
-
-/**
- * Utils.
- */
-
-var doubleQuote = exports.doubleQuote = function(value, outValues) {
- if (nil(value)) {
- return "NULL";
- } else if (_(value).isNumber()) {
- return value;
- } else if (_(value).isArray()) {
- return "(" + toCsv(value, outValues) + ")";
- } else if (_(value).isDate()) {
- return '"' + toDateTime(value) + '"';
- } else {
- return '"' + value + '"';
- }
-};
-
-var fieldIsValid = exports.fieldIsValid = function(model, field) {
- var columns = _(model._fields).pluck('column_name');
- return _.include(columns, field.split('.')[0]);
-};
-
-var hasWhiteSpace = exports.hasWhiteSpace = function(value) {
- return /\s/g.test(value);
-};
-
-var keysFromObject = exports.keysFromObject = function(fields) {
- return _(fields).chain()
- .map(function(field) {
- return _(field).keys();
- })
- .flatten()
- .uniq()
- .value();
-};
-
-var nil = exports.nil = function(value) {
- if (_(value).isUndefined() || _(value).isNull() || _(value).isNaN()) {
- return true;
- } else if (_(value).isArray() && _(value).isEmpty()) {
- return true;
- } else if (value.toString() === '[object Object]' && _(value).isEmpty()) {
- return true;
- } else if (_(value).isString() && _(value).isEmpty()) {
- return true;
- } else {
- return false;
- }
-};
-
-var quote = exports.quote = function(outValues, operator) {
- if (operator === 'IN' || operator === 'NOT IN') {
- var valuePos = _.range(1, outValues.length+1);
- var values = _.reduce(valuePos, function(memo, pos, i) {
- memo += '?';
- if (i+1 !== valuePos.length) memo += ',';
- return memo;
- }, '');
- return '(' + values + ')';
- } else if (operator === 'ILIKE') {
- return 'UPPER(?)';
- } else {
- return '?';
- }
-};
-
-var toCsv = exports.toCsv = function(list, keys, outValues) {
- return _(list).chain()
- .values()
- .map(function(o) { outValues.push(o); return '$' + outValues.length; })
- .join(',')
- .value();
-};
-
-var toPlaceholder = exports.toPlaceholder = function(list, keys, outValues) {
- return _(list).chain()
- .values()
- .map(function(o) { outValues.push(o); return '?'; })
- .join(', ')
- .value();
-};
-
-var toDateTime = exports.toDateTime = function(value) {
- if (_(value).isDate()) {
- return value.getFullYear()
- + '/' + (value.getMonth()+1)
- + '/' + (value.getDate())
- + ' ' + (value.getHours())
- + ':' + (value.getMinutes())
- + ':' + (value.getSeconds());
- }
-};
-
-var validFields = exports.validFields = function(model, fields) {
- var returnFields = {};
- _(fields).each(function(value, key) {
- if (fieldIsValid(model, key)) {
- returnFields[key] = value;
- }
- });
- return returnFields;
-};
View
@@ -1,107 +0,0 @@
-/**
- * Module dependencies.
- */
-
-var _ = require('underscore');
-
-/**
- * Utils.
- */
-
-var doubleQuote = exports.doubleQuote = function(value, outValues) {
- if (nil(value)) {
- return "NULL";
- } else if (_(value).isNumber()) {
- return value;
- } else if (_(value).isArray()) {
- return "(" + toCsv(value, outValues) + ")";
- } else if (_(value).isDate()) {
- return '"' + toDateTime(value) + '"';
- } else {
- return '"' + value + '"';
- }
-};
-
-var fieldIsValid = exports.fieldIsValid = function(model, field) {
- var columns = _(model._fields).pluck('column_name');
- return _.include(columns, field.split('.')[0]);
-};
-
-var hasWhiteSpace = exports.hasWhiteSpace = function(value) {
- return /\s/g.test(value);
-};
-
-var keysFromObject = exports.keysFromObject = function(fields) {
- return _(fields).chain()
- .map(function(field) {
- return _(field).keys();
- })
- .flatten()
- .uniq()
- .value();
-};
-
-var nil = exports.nil = function(value) {
- if (_(value).isUndefined() || _(value).isNull() || _(value).isNaN()) {
- return true;
- } else if (_(value).isArray() && _(value).isEmpty()) {
- return true;
- } else if (value.toString() === '[object Object]' && _(value).isEmpty()) {
- return true;
- } else if (_(value).isString() && _(value).isEmpty()) {
- return true;
- } else {
- return false;
- }
-};
-
-var quote = exports.quote = function(outValues, operator) {
- if (operator === 'IN' || operator === 'NOT IN') {
- var valuePos = _.range(1, outValues.length+1);
- var values = _.reduce(valuePos, function(memo, pos, i) {
- memo += '$' + pos.toString();
- if (i+1 !== valuePos.length) memo += ',';
- return memo;
- }, '');
- return '(' + values + ')';
- } else {
- return '$' + outValues.length;
- }
-};
-
-var toCsv = exports.toCsv = function(list, keys, outValues) {
- return _(list).chain()
- .values()
- .map(function(o) { outValues.push(o); return '$' + outValues.length; })
- .join(',')
- .value();
-};
-
-var toPlaceholder = exports.toPlaceholder = function(list, keys, outValues) {
- return _(list).chain()
- .values()
- .map(function(o) { outValues.push(o); return '?'; })
- .join(', ')
- .value();
-};
-
-var toDateTime = exports.toDateTime = function(value) {
- if (_(value).isDate()) {
- return value.getFullYear()
- + '/' + (value.getMonth()+1)
- + '/' + (value.getDate())
- + ' ' + (value.getHours())
- + ':' + (value.getMinutes())
- + ':' + (value.getSeconds());
- }
-};
-
-var validFields = exports.validFields = function(model, fields) {
- var returnFields = {};
- _(fields).each(function(value, key) {
- if (fieldIsValid(model, key)) {
- returnFields[key] = value;
- }
- });
- return returnFields;
-};
@@ -3,13 +3,13 @@
*/
var FastLegS = module.exports = function(db) {
- this.version = '0.1.5';
+ this.version = '0.2.0';
this.db = db || 'pg';
};
FastLegS.prototype.connect = function(connParams) {
- var Client = require('./'+(this.db)+'/client')
- var Base = require('./'+(this.db)+'/base')
+ var Client = require('./adapters/'+(this.db)+'/client');
+ var Base = require('./adapters/'+(this.db)+'/base');
var client = new Client(connParams);
client.connect();
this.Base = new Base(client);
Oops, something went wrong.

0 comments on commit fbcb86e

Please sign in to comment.