Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types as per cjohnson415, add column constraint "null" #58

Merged
merged 3 commits into from Dec 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/data_type.js
@@ -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'
};
4 changes: 4 additions & 0 deletions lib/driver/base.js
Expand Up @@ -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);
Expand Down
54 changes: 34 additions & 20 deletions lib/driver/mysql.js
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down