本文整理匯總了TypeScript中Sequelize.Sequelize.import方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Sequelize.import方法的具體用法?TypeScript Sequelize.import怎麽用?TypeScript Sequelize.import使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sequelize.Sequelize
的用法示例。
在下文中一共展示了Sequelize.import方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
list.forEach((file) => {
// Import sequelize model.
let model:any = this.sequelize.import(file);
// Save to model storage of app.
this.app.models[model.name] = model;
});
示例2: loadModels
/**
* Load all models from plugins.
*
* @param sequelize {Sequelize}
*
* @returns {Promise}
*/
public async loadModels(sequelize: Sequelize) {
if (this.order.length === 0) {
this.determinateOrder();
}
for (let id of this.order) {
if (this.plugins[id].directory) {
var modelDirectory = path.normalize(this.plugins[id].directory + '/models/');
var exists = await fs.exists(modelDirectory);
if (! exists) {
modelDirectory = path.normalize(this.plugins[id].directory + '/Models/');
exists = await fs.exists(modelDirectory);
if (! exists) continue;
}
try {
let list = glob.sync(modelDirectory + '*.js');
if (list.length > 0) {
for (let file of list) {
// Import sequelize model.
let model: any = sequelize.import(file);
// Set in the plugin.
if (! this.plugins[id].models) {
this.plugins[id].models = {};
}
this.plugins[id].models[model.name] = model;
// Set in the global models.
if (! this.app.models.hasOwnProperty(id)) {
this.app.models[id] = {};
}
this.app.models[id][model.name] = model;
}
}
} catch (err) {
this.app.log.warn('Warning, can\'t load models for plugin ' + id, err.stack);
}
}
}
}
示例3:
}).forEach((file: string) => {
let model = this._sequelize.import(path.join(__dirname, file));
this._models[(model as any).name] = model;
});