diff --git a/src/auto-generator.ts b/src/auto-generator.ts index 9d3b4252..a5ce2968 100644 --- a/src/auto-generator.ts +++ b/src/auto-generator.ts @@ -324,6 +324,10 @@ export class AutoGenerator { defaultVal = null as any; // Override default NULL in MS SQL to javascript null } + if (defaultVal === "NULL") { + defaultVal = null as any; + } + if (defaultVal === null || defaultVal === undefined) { return true; } @@ -379,7 +383,7 @@ export class AutoGenerator { val_text = "Sequelize.Sequelize.literal('" + defaultVal + "')"; } else if (field_type.indexOf('date') === 0 || field_type.indexOf('timestamp') === 0) { - if (_.includes(['current_timestamp', 'current_date', 'current_time', 'localtime', 'localtimestamp'], defaultVal.toLowerCase())) { + if (_.includes(['current_timestamp', 'current_date', 'current_time', 'localtime', 'localtimestamp', 'null'], defaultVal.toLowerCase())) { val_text = "Sequelize.Sequelize.literal('" + defaultVal + "')"; } else { val_text = quoteWrapper + defaultVal + quoteWrapper; @@ -486,7 +490,7 @@ export class AutoGenerator { if (type === "boolean" || type === "bit(1)" || type === "bit" || type === "tinyint(1)") { val = 'DataTypes.BOOLEAN'; - // postgres range types + // postgres range types } else if (type === "numrange") { val = 'DataTypes.RANGE(DataTypes.DECIMAL)'; } else if (type === "int4range") { @@ -508,7 +512,7 @@ export class AutoGenerator { val += '.ZEROFILL'; } } else if (type === 'nvarchar(max)' || type === 'varchar(max)') { - val = 'DataTypes.TEXT'; + val = 'DataTypes.TEXT'; } else if (type.match(/n?varchar|string|varying/)) { val = 'DataTypes.STRING' + (!_.isNull(length) ? length : ''); } else if (type.match(/^n?char/)) { @@ -695,7 +699,7 @@ export class AutoGenerator { const notNull = isInterface ? '' : '!'; let str = ''; fields.forEach(field => { - if (!this.options.skipFields || !this.options.skipFields.includes(field)){ + if (!this.options.skipFields || !this.options.skipFields.includes(field)) { const name = this.quoteName(recase(this.options.caseProp, field)); const isOptional = this.getTypeScriptFieldOptional(table, field); str += `${sp}${name}${isOptional ? '?' : notNull}: ${this.getTypeScriptType(table, field)};\n`; diff --git a/src/auto-writer.ts b/src/auto-writer.ts index 07f279ad..44966cad 100644 --- a/src/auto-writer.ts +++ b/src/auto-writer.ts @@ -77,7 +77,7 @@ export class AutoWriter { case 'esm': return this.createESMInitString(tableNames, assoc); case 'es6': - return this.createES5InitString(tableNames, assoc, "const"); + return this.createES5InitString(tableNames, assoc, "const"); default: return this.createES5InitString(tableNames, assoc, "var"); } @@ -104,7 +104,7 @@ export class AutoWriter { rels.forEach(rel => { if (rel.isM2M) { const asprop = recase(this.options.caseProp, pluralize(rel.childProp)); - strBelongsToMany += `${sp}${rel.parentModel}.belongsToMany(${rel.childModel}, { as: '${asprop}', through: ${rel.joinModel}, foreignKey: "${rel.parentId}", otherKey: "${rel.childId}" });\n`; + strBelongsToMany += `${sp}${rel.parentModel}.belongsToMany(${rel.childModel}, { ${this.options.noAlias ? '' : `as: '${asprop}',`} through: ${rel.joinModel}, foreignKey: "${rel.parentId}", otherKey: "${rel.childId}" });\n`; } else { // const bAlias = (this.options.noAlias && rel.parentModel.toLowerCase() === rel.parentProp.toLowerCase()) ? '' : `as: "${rel.parentProp}", `; const asParentProp = recase(this.options.caseProp, rel.parentProp);