Permalink
Browse files

Took some of the changes from https://github.com/cjohnson415 and adde…

…d columnConstraint null (used with timestamps)
  • Loading branch information...
1 parent 4860ff1 commit e4788d6bcdb9dac3f4a5b50166d85087ddb04a91 Jim Pravetz committed Dec 7, 2012
Showing with 48 additions and 27 deletions.
  1. +8 −6 lib/data_type.js
  2. +4 −0 lib/driver/base.js
  3. +34 −20 lib/driver/mysql.js
  4. +2 −1 package.json
View
@@ -1,8 +1,10 @@
module.exports = {
- STRING: 'string',
- TEXT: 'text',
- INTEGER: 'int',
- REAL: 'real',
- DATE_TIME: 'datetime',
- BLOB: 'blob'
+ STRING: 'string',
+ TEXT: 'text',
+ INTEGER: 'int',
+ REAL: 'real',
+ DATE_TIME: 'datetime',
+ BLOB: 'blob',
+ TIMESTAMP: 'timestamp',
+ BINARY: 'binary'
};
View
@@ -30,6 +30,10 @@ module.exports = Base = Class.extend({
return 'REAL';
case type.BLOB:
return 'BLOB';
+ case type.TIMESTAMP:
+ return 'TIMESTAMP';
+ case type.BINARY:
+ return 'BINARY';
default:
var unknownType = str.toUpperCase();
log.warn('Using unknown data type', unknownType);
View
@@ -23,6 +23,10 @@ var MysqlDriver = Base.extend({
return 'REAL';
case type.BLOB:
return 'BLOB';
+ case type.TIMESTAMP:
+ return 'TIMESTAMP';
+ case type.BINARY:
+ return 'BINARY';
default:
throw new Error('Invalid data type ' + str);
}
@@ -39,33 +43,43 @@ var MysqlDriver = Base.extend({
},
createColumnConstraint: function(spec, options) {
- var constraint = [];
- if (spec.primaryKey && options.emitPrimaryKey) {
- constraint.push('PRIMARY KEY');
- if (spec.autoIncrement) {
- constraint.push('auto_increment');
+ var constraint = [];
+ if (spec.unsigned) {
+ constraint.push('UNSIGNED');
}
- }
- if (spec.notNull) {
- constraint.push('NOT NULL');
- }
+ if (spec.primaryKey && options.emitPrimaryKey) {
+ constraint.push('PRIMARY KEY');
+ if (spec.autoIncrement) {
+ constraint.push('AUTO_INCREMENT');
+ }
+ }
- if (spec.unique) {
- constraint.push('UNIQUE');
- }
+ if (spec.notNull) {
+ constraint.push('NOT NULL');
+ }
- if (spec.defaultValue) {
- constraint.push('DEFAULT');
+ if (spec.unique) {
+ constraint.push('UNIQUE');
+ }
- if (typeof spec.defaultValue == 'string'){
- constraint.push("'" + spec.defaultValue + "'");
- } else {
- constraint.push(spec.defaultValue);
+ if (spec.null) {
+ constraint.push('NULL');
+ }
+
+ if (spec.defaultValue) {
+ constraint.push('DEFAULT');
+
+ if (typeof spec.defaultValue == 'string'){
+ //if (spec.defaultValue === 'NULL' || spec.defaultValue === 'CURRENT_TIMESTAMP') constraint.push(spec.defaultValue);
+ //else constraint.push("'" + spec.defaultValue + "'");
+ constraint.push("'" + spec.defaultValue + "'");
+ } else {
+ constraint.push(spec.defaultValue);
+ }
}
- }
- return constraint.join(' ');
+ return constraint.join(' ');
},
renameTable: function(tableName, newTableName, callback) {
View
@@ -37,7 +37,8 @@
"optimist": "~0.3.0",
"async": "~0.1.15",
"semver": "~1.0.14",
- "mkdirp": "~0.3.4"
+ "mkdirp": "~0.3.4",
+ "mysql": "https://github.com/jpravetz/node-mysql/tarball/master"
},
"devDependencies": {
"vows": "~0.6.2",

0 comments on commit e4788d6

Please sign in to comment.