不要怂,就是干,撸起袖子干!

Commit a91a0f3c by Mick Hansen

Merge pull request #5061 from jasonku/5051-fix_sqlite_default_value

5051 fix sqlite default value
2 parents 838d596c f86987aa
......@@ -174,11 +174,22 @@ Query.prototype.run = function(sql, parameters) {
// this is the sqlite way of getting the metadata of a table
result = {};
var defaultValue;
results.forEach(function(_result) {
if (_result.dflt_value === null) {
// Column schema omits any "DEFAULT ..."
defaultValue = undefined;
} else if (_result.dflt_value === 'NULL') {
// Column schema is a "DEFAULT NULL"
defaultValue = null;
} else {
defaultValue = _result.dflt_value;
}
result[_result.name] = {
type: _result.type,
allowNull: (_result.notnull === 0),
defaultValue: _result.dflt_value,
defaultValue: defaultValue,
primaryKey : (_result.pk === 1)
};
......@@ -186,10 +197,6 @@ Query.prototype.run = function(sql, parameters) {
result[_result.name].defaultValue = { '0': false, '1': true }[result[_result.name].defaultValue];
}
if (result[_result.name].defaultValue === undefined) {
result[_result.name].defaultValue = null;
}
if (typeof result[_result.name].defaultValue === 'string') {
result[_result.name].defaultValue = result[_result.name].defaultValue.replace(/'/g, '');
}
......
......@@ -50,6 +50,10 @@ if (dialect === 'sqlite') {
expectation: {id: 'INTEGER DEFAULT 0'}
},
{
arguments: [{id: {type: 'INTEGER', defaultValue: undefined}}],
expectation: {id: 'INTEGER'}
},
{
arguments: [{id: {type: 'INTEGER', unique: true}}],
expectation: {id: 'INTEGER UNIQUE'}
},
......
......@@ -150,6 +150,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
var self = this;
var Users = self.sequelize.define('_Users', {
username: DataTypes.STRING,
city: {
type: DataTypes.STRING,
defaultValue: null
},
isAdmin: DataTypes.BOOLEAN,
enumVals: DataTypes.ENUM('hello', 'world')
}, { freezeTableName: true });
......@@ -161,6 +165,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
var id = metadata.id;
var username = metadata.username;
var city = metadata.city;
var isAdmin = metadata.isAdmin;
var enumVals = metadata.enumVals;
......@@ -177,7 +182,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
expect(username.type).to.equal(assertVal);
expect(username.allowNull).to.be.true;
switch (dialect) {
case 'sqlite':
expect(username.defaultValue).to.be.undefined;
break;
default:
expect(username.defaultValue).to.be.null;
}
switch (dialect) {
case 'sqlite':
expect(city.defaultValue).to.be.null;
break;
}
assertVal = 'TINYINT(1)';
switch (dialect) {
......@@ -190,7 +208,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
expect(isAdmin.type).to.equal(assertVal);
expect(isAdmin.allowNull).to.be.true;
switch (dialect) {
case 'sqlite':
expect(isAdmin.defaultValue).to.be.undefined;
break;
default:
expect(isAdmin.defaultValue).to.be.null;
}
if (dialect === 'postgres' || dialect === 'postgres-native') {
expect(enumVals.special).to.be.instanceof(Array);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!