MCPcopy Index your code
hub / github.com/sequelize/sequelize-auto / createES5InitString

Method createES5InitString

src/auto-writer.ts:175–207  ·  view source on GitHub ↗
(tables: string[], assoc: string, vardef: string)

Source from the content-addressed store, hash-verified

173
174 // create the ES5 init-models file to load all the models into Sequelize
175 private createES5InitString(tables: string[], assoc: string, vardef: string) {
176 let str = `${vardef} DataTypes = require("sequelize").DataTypes;\n`;
177 const sp = this.space[1];
178 const modelNames: string[] = [];
179 // import statements
180 tables.forEach(t => {
181 const fileName = recase(this.options.caseFile, t, this.options.singularize);
182 const modelName = makeTableName(this.options.caseModel, t, this.options.singularize, this.options.lang);
183 modelNames.push(modelName);
184 str += `${vardef} _${modelName} = require("./${fileName}");\n`;
185 });
186
187 // create the initialization function
188 str += '\nfunction initModels(sequelize) {\n';
189 modelNames.forEach(m => {
190 str += `${sp}${vardef} ${m} = _${m}(sequelize, DataTypes);\n`;
191 });
192
193 // add the asociations
194 str += "\n" + assoc;
195
196 // return the models
197 str += `\n${sp}return {\n`;
198 modelNames.forEach(m => {
199 str += `${this.space[2]}${m},\n`;
200 });
201 str += `${sp}};\n`;
202 str += '}\n';
203 str += 'module.exports = initModels;\n';
204 str += 'module.exports.initModels = initModels;\n';
205 str += 'module.exports.default = initModels;\n';
206 return str;
207 }
208
209 // create the ESM init-models file to load all the models into Sequelize
210 private createESMInitString(tables: string[], assoc: string) {

Callers 1

createInitStringMethod · 0.95

Calls 2

recaseFunction · 0.90
makeTableNameFunction · 0.90

Tested by

no test coverage detected