Permalink
Browse files

Merge pull request #26 from XadillaX/feature/remove_sugar

use lodash to instead of sugar
  • Loading branch information...
XadillaX committed Oct 21, 2015
2 parents b7c2304 + 07815ca commit 91b05b053215f7cd62975d3af315d0fd8b27e45d
@@ -4,6 +4,8 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

exports.Toshihiko = require("./lib/toshihiko");
exports.Type = require("./lib/fieldType");
exports.Memcached = require("toshihiko-memcached");
@@ -4,6 +4,8 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

/**
* escape sql
* @param str
@@ -14,7 +16,7 @@ exports.escape = function(str) {
return str;
}

return str./**escapeRegExp().*/chars().reduce(function(str, ch) {
return str.split("").reduce(function(str, ch) {
switch(ch) {
case "\n" : str += "\\n"; break;
case "'" : str += "\\'"; break;
@@ -38,12 +40,11 @@ exports.escape = function(str) {
* @returns {*}
*/
exports.escapeLike = function(str) {
return str./**escapeRegExp().*/chars().reduce(function(str, ch) {
return str.split("").chars().reduce(function(str, ch) {
if(ch === "_" || ch === "%") {
str += "\\";
}
str += ch;
return str;
}, "");
};

@@ -4,6 +4,8 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var fieldTypes = require("./fieldType");
var util = require("util");

@@ -4,30 +4,53 @@
* Copyright (c) 2015 Souche.com, all rights
* reserved.
*/
"use strict";

var moment = require("moment");

var Datetime = {};
Datetime.name = "Datetime";
Datetime.needQuotes = true;

/**
* restore
* @param {Date|Number|String} parsed the parsed datetime object
* @return {String} the original datetime type in mysql2
*/
Datetime.restore = function(parsed) {
return moment(parsed).format("YYYY-MM-DD HH:mm:ss");
};

/**
* parse
* @param {String} orig the original mysql2 datetime type
* @return {String} the parsed datetime string
*/
Datetime.parse = function(orig) {
return moment(orig).toDate();
};

/**
* equal
* @param {Date|Number|String} a object I
* @param {Date|Number|String} b object II
* @return {Boolean} whether they are equal
*/
Datetime.equal = function(a, b) {
return moment(a).format("x") === moment(b).format("x");
};

/**
* toJSON
* @param {Date|Number|String} datetime the datetime object
* @return {Object} the json object
*/
Datetime.toJSON = function(datetime) {
if(!(datetime instanceof Date)) {
datetime = moment(datetime).toDate();
}

return datetime.format("{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}.{fff}{isotz}");
return moment(datetime).format("YYYY-MM-DDTHH:mm:ss.SSSZ");
};

module.exports = Datetime;
@@ -4,20 +4,38 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var Float = {};
Float.name = "Float";
Float.needQuotes = false;

/**
* restore
* @param {String|Number} parsed the parsed float
* @return {Number} the float restored
*/
Float.restore = function(parsed) {
return parseFloat(parsed);
};

/**
* parse
* @param {Number} orig the original float
* @return {Number} the float
*/
Float.parse = function(orig) {
return parseFloat(orig);
};

Float.defaultValue = 0.0;

/**
* equal
* @param {Number|String} a float I
* @param {String|Number} b float II
* @return {Boolean} whether they are equal
*/
Float.equal = function(a, b) {
if(a === b) {
return true;
@@ -4,6 +4,8 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var _String = require("./string");
var Integer = require("./integer");
var Float = require("./float");
@@ -4,20 +4,38 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var Integer = {};
Integer.name = "Integer";
Integer.needQuotes = false;

/**
* restore
* @param {String|Number} parsed the parsed integer
* @return {Number} the integer restored
*/
Integer.restore = function(parsed) {
return parseInt(parsed);
};

/**
* parse
* @param {Number} orig the original integer
* @return {Number} the integer
*/
Integer.parse = function(orig) {
return parseInt(orig);
};

Integer.defaultValue = 0;

/**
* equal
* @param {Number|String} a integer I
* @param {String|Number} b integer II
* @return {Boolean} whether they are equal
*/
Integer.equal = function(a, b) {
if(a === b) {
return true;
@@ -4,16 +4,28 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var fJSON = require("fbbk-json");

var Json = {};
Json.name = "Json";
Json.needQuotes = true;

/**
* restore
* @param {Object} parsed the json object
* @return {String} the stringified json object
*/
Json.restore = function(parsed) {
return JSON.stringify(parsed);
};

/**
* parse
* @param {String} orig the stringified json object
* @return {Object} the json object
*/
Json.parse = function(orig) {
try {
return fJSON.parse(orig);
@@ -29,6 +41,12 @@ Json.parse = function(orig) {
}
};

/**
* equal
* @param {Object|String} a object I
* @param {Object|String} b object II
* @return {Boolean} whether they are equal
*/
Json.equal = function(a, b) {
if(a === b) {
return true;
@@ -4,10 +4,17 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
"use strict";

var Str = {};
Str.name = "String";
Str.needQuotes = true;

/**
* restore
* @param {String} parsed the parsed string
* @return {String} the string restored
*/
Str.restore = function(parsed) {
if(undefined === parsed || null === parsed) {
return "";
@@ -16,6 +23,11 @@ Str.restore = function(parsed) {
return parsed.toString();
};

/**
* parse
* @param {String} orig the original string
* @return {String} the string
*/
Str.parse = function(orig) {
if(undefined === orig || null === orig) {
return "";
@@ -24,6 +36,12 @@ Str.parse = function(orig) {
return orig.toString();
};

/**
* equal
* @param {String} a string I
* @param {String} b string II
* @return {Boolean} whether they are equal
*/
Str.equal = function(a, b) {
if(a === b) {
return true;
@@ -4,7 +4,8 @@
* Copyright (c) 2014 Huaban.com, all rights
* reserved.
*/
require("sugar");
"use strict";

var Field = require("./field");
var Query = require("./query");
var Yukari = require("./yukari");
@@ -44,6 +45,10 @@ var Model = function(name, toshihiko, fields, options) {
}

// some keymaps
// + n2c -> name to column
// + c2n -> column to name
// + name -> name
// + column -> column
self._fieldsKeyMap.n2c[f.name] = f.column;
self._fieldsKeyMap.c2n[f.column] = f.name;
self._fieldsKeyMap.name[f.name] = f;
@@ -53,7 +58,9 @@ var Model = function(name, toshihiko, fields, options) {
});

if(!this.primaryKeys || !this.primaryKeys.length) {
console.log(colors.rainbow("!!! WARNING: You'd better add primary key(s) in model " + name + "!!!"));
console.log(colors.rainbow(
"!!! WARNING: You'd better add primary key(s) in model " +
name + "!!!"));
}

this.options = options || {};
Oops, something went wrong.

0 comments on commit 91b05b0

Please sign in to comment.