Browse files

Merge pull request #66 from trojanowski/boolean-data-type

Add boolean data type
  • Loading branch information...
2 parents b9c69bc + e6010e2 commit 9f0f5bfd1ae8dab730d84fcf429001de7a4d00f9 @kunklejr kunklejr committed Jan 28, 2013
Showing with 36 additions and 10 deletions.
  1. +2 −1 lib/data_type.js
  2. +2 −0 lib/driver/base.js
  3. +2 −0 lib/driver/mysql.js
  4. +10 −3 test/driver/mysql_test.js
  5. +10 −3 test/driver/pg_test.js
  6. +10 −3 test/driver/sqlite3_test.js
View
3 lib/data_type.js
@@ -6,5 +6,6 @@ module.exports = {
DATE_TIME: 'datetime',
BLOB: 'blob',
TIMESTAMP: 'timestamp',
- BINARY: 'binary'
+ BINARY: 'binary',
+ BOOLEAN: 'boolean'
};
View
2 lib/driver/base.js
@@ -34,6 +34,8 @@ module.exports = Base = Class.extend({
return 'TIMESTAMP';
case type.BINARY:
return 'BINARY';
+ case type.BOOLEAN:
+ return 'BOOLEAN';
default:
var unknownType = str.toUpperCase();
log.warn('Using unknown data type', unknownType);
View
2 lib/driver/mysql.js
@@ -50,6 +50,8 @@ var MysqlDriver = Base.extend({
return 'TIMESTAMP';
case type.BINARY:
return 'BINARY';
+ case type.BOOLEAN:
+ return 'TINYINT(1)';
default:
throw new Error('Invalid data type ' + str);
}
View
13 test/driver/mysql_test.js
@@ -16,7 +16,8 @@ driver.connect({ driver: 'mysql', database: 'db_migrate_test', user:'root' }, fu
rel: dataType.REAL,
dt: dataType.DATE_TIME,
ts: dataType.TIMESTAMP,
- bin: dataType.BINARY
+ bin: dataType.BINARY,
+ bl: dataType.BOOLEAN
}, this.callback.bind(this, null));
},
@@ -50,9 +51,9 @@ driver.connect({ driver: 'mysql', database: 'db_migrate_test', user:'root' }, fu
}.bind(this));
},
- 'with 8 columns': function(err, columns) {
+ 'with 9 columns': function(err, columns) {
assert.isNotNull(columns);
- assert.equal(columns.length, 8);
+ assert.equal(columns.length, 9);
},
'that has integer id column that is primary key, non-nullable, and auto increments': function(err, columns) {
@@ -104,6 +105,12 @@ driver.connect({ driver: 'mysql', database: 'db_migrate_test', user:'root' }, fu
var column = findByName(columns, 'bin');
assert.equal(column.getDataType(), 'BINARY');
assert.equal(column.isNullable(), true);
+ },
+
+ 'that has boolean bl column': function(err, columns) {
+ var column = findByName(columns, 'bl');
+ assert.equal(column.getDataType(), 'TINYINT');
+ assert.equal(column.isNullable(), true);
}
}
}
View
13 test/driver/pg_test.js
@@ -14,7 +14,8 @@ driver.connect({ driver: 'pg', database: 'db_migrate_test' }, function(err, db)
txt: { type: dataType.TEXT, notNull: true, defaultValue: "foo" },
intg: dataType.INTEGER,
rel: dataType.REAL,
- dt: dataType.DATE_TIME
+ dt: dataType.DATE_TIME,
+ bl: dataType.BOOLEAN
}, this.callback.bind(this, null));
},
@@ -44,9 +45,9 @@ driver.connect({ driver: 'pg', database: 'db_migrate_test' }, function(err, db)
}.bind(this));
},
- 'with 6 columns': function(err, columns) {
+ 'with 7 columns': function(err, columns) {
assert.isNotNull(columns);
- assert.equal(columns.length, 6);
+ assert.equal(columns.length, 7);
},
'that has integer id column that is primary key, non-nullable, and auto increments': function(err, columns) {
@@ -86,6 +87,12 @@ driver.connect({ driver: 'pg', database: 'db_migrate_test' }, function(err, db)
var column = findByName(columns, 'dt');
assert.equal(column.getDataType(), 'TIMESTAMP WITHOUT TIME ZONE');
assert.equal(column.isNullable(), true);
+ },
+
+ 'that has boolean bl column': function(err, columns) {
+ var column = findByName(columns, 'bl');
+ assert.equal(column.getDataType(), 'BOOLEAN');
+ assert.equal(column.isNullable(), true);
}
},
View
13 test/driver/sqlite3_test.js
@@ -15,7 +15,8 @@ vows.describe('sqlite3').addBatch({
txt: { type: dataType.TEXT, notNull: true, defaultValue: "foo" },
intg: dataType.INTEGER,
rel: dataType.REAL,
- dt: dataType.DATE_TIME
+ dt: dataType.DATE_TIME,
+ bl: dataType.BOOLEAN
}, this.callback.bind(this, null, db));
}.bind(this));
},
@@ -53,9 +54,9 @@ vows.describe('sqlite3').addBatch({
}.bind(this));
},
- 'with 6 columns': function(err, columns) {
+ 'with 7 columns': function(err, columns) {
assert.isNotNull(columns);
- assert.equal(columns.length, 6);
+ assert.equal(columns.length, 7);
},
'that has integer id column that is primary key, non-nullable, and auto increments': function(err, columns) {
@@ -95,6 +96,12 @@ vows.describe('sqlite3').addBatch({
var column = findByName(columns, 'dt');
assert.equal(column.getDataType(), 'INTEGER');
assert.equal(column.isNullable(), true);
+ },
+
+ 'that has boolean bl column': function(err, columns) {
+ var column = findByName(columns, 'bl');
+ assert.equal(column.getDataType(), 'BOOLEAN');
+ assert.equal(column.isNullable(), true);
}
}
}

0 comments on commit 9f0f5bf

Please sign in to comment.