@@ -3,7 +3,7 @@ import _ from "lodash";
3
3
import path from "path" ;
4
4
import util from "util" ;
5
5
import { FKSpec , TableData } from "." ;
6
- import { AutoOptions , CaseFileOption , CaseOption , LangOption , pluralize , qNameSplit , recase , Relation } from "./types" ;
6
+ import { AutoOptions , CaseFileOption , CaseOption , LangOption , makeTableName , pluralize , qNameSplit , recase , Relation } from "./types" ;
7
7
const mkdirp = require ( 'mkdirp' ) ;
8
8
9
9
/** Writes text into files from TableData.text, and writes init-models */
@@ -72,8 +72,6 @@ export class AutoWriter {
72
72
return this . createTsInitString ( tableNames , assoc ) ;
73
73
case 'esm' :
74
74
return this . createESMInitString ( tableNames , assoc ) ;
75
- case 'esmd' :
76
- return this . createESMDInitString ( tableNames , assoc ) ;
77
75
case 'es6' :
78
76
return this . createES5InitString ( tableNames , assoc , "const" ) ;
79
77
default :
@@ -127,7 +125,7 @@ export class AutoWriter {
127
125
// import statements
128
126
tables . forEach ( t => {
129
127
const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
130
- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
128
+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
131
129
modelNames . push ( modelName ) ;
132
130
str += `import { ${ modelName } as _${ modelName } } from "./${ fileName } ";\n` ;
133
131
str += `import type { ${ modelName } Attributes, ${ modelName } CreationAttributes } from "./${ fileName } ";\n` ;
@@ -174,7 +172,7 @@ export class AutoWriter {
174
172
// import statements
175
173
tables . forEach ( t => {
176
174
const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
177
- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
175
+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
178
176
modelNames . push ( modelName ) ;
179
177
str += `${ vardef } _${ modelName } = require("./${ fileName } ");\n` ;
180
178
} ) ;
@@ -200,34 +198,7 @@ export class AutoWriter {
200
198
str += 'module.exports.default = initModels;\n' ;
201
199
return str ;
202
200
}
203
- // create the ES6 init-models file to load all the models (with define-syntax instead of classes) into Sequelize
204
- createESMDInitString ( tables : string [ ] , assoc : string ) {
205
- let str = 'import _sequelize from "sequelize";\n' ;
206
- str += 'const DataTypes = _sequelize.DataTypes;\n' ;
207
- const modelNames : string [ ] = [ ] ;
208
- // import statements
209
- tables . forEach ( t => {
210
- const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
211
- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
212
- modelNames . push ( modelName ) ;
213
- str += `import _${ modelName } from "./${ fileName } .js";\n` ;
214
- } ) ;
215
- // create the initialization function
216
- str += '\nexport default function initModels(sequelize) {\n' ;
217
- modelNames . forEach ( m => {
218
- str += ` const ${ m } = _${ m } (sequelize, DataTypes);\n` ;
219
- } ) ;
220
- // add the asociations
221
- str += "\n" + assoc ;
222
- // return the models
223
- str += "\n return {\n" ;
224
- modelNames . forEach ( m => {
225
- str += ` ${ m } ,\n` ;
226
- } ) ;
227
- str += ' };\n' ;
228
- str += '}\n' ;
229
- return str ;
230
- }
201
+
231
202
// create the ESM init-models file to load all the models into Sequelize
232
203
private createESMInitString ( tables : string [ ] , assoc : string ) {
233
204
let str = 'import _sequelize from "sequelize";\n' ;
@@ -236,18 +207,17 @@ export class AutoWriter {
236
207
// import statements
237
208
tables . forEach ( t => {
238
209
const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
239
- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
210
+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
240
211
modelNames . push ( modelName ) ;
241
212
str += `import _${ modelName } from "./${ fileName } .js";\n` ;
242
213
} ) ;
243
-
244
214
// create the initialization function
245
215
str += '\nexport default function initModels(sequelize) {\n' ;
246
216
modelNames . forEach ( m => {
247
217
str += ` const ${ m } = _${ m } .init(sequelize, DataTypes);\n` ;
248
218
} ) ;
249
219
250
- // add the asociations
220
+ // add the associations
251
221
str += "\n" + assoc ;
252
222
253
223
// return the models
0 commit comments