本文整理汇总了TypeScript中Sequelize.Model类的典型用法代码示例。如果您正苦于以下问题:TypeScript Model类的具体用法?TypeScript Model怎么用?TypeScript Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findOrCreateUserBySlackId
export function findOrCreateUserBySlackId(User: Model<any, any>, slackId: string, type: UserType): Promise<any> {
return User.findOrCreate({
where: {slackId},
defaults: {type}
})
.then(results => results[0]);
}
示例2: isDefined
public async isDefined (context: any): Promise<boolean> {
let settings = await this.settingModel.findAndCount({
where: {
context: { $eq: this.getContextString(context) }
}
});
return settings && settings.count > 0;
}
示例3: getAllSettings
/**
* Get all plugin settings.
* @param context Plugin class instance or app instance for global.
*/
public async getAllSettings (context: any): Promise<Setting[]> {
let settings: any[] = await this.settingModel.find({
where: { context: { $eq: this.getContextString(context) } }
});
return settings.map((setting) => {
return this.parseSetting(setting);
});
}
示例4: defineSettings
/**
* Define settings for context (plugin or core/app).
* @param context
* @param schema
*/
public async defineSettings (context: any, schema: SettingSchema) {
context = this.getContextString(context);
// Prepare all settings in database.
for (let setting of schema.settings) {
setting.value = null;
await this.settingModel.create(setting);
}
}
示例5: getSetting
/**
* Get setting.
* @param context
* @param key
*/
public async getSetting (context: any, key?: string): Promise<Setting> {
let setting = await this.settingModel.findOne({
where: { $and: [
{context: { $eq: this.getContextString(context) }},
{key: { $eq: key }}
]}
});
return this.parseSetting(setting);
}
示例6: boot
public async boot() {
let Map: Model<any,any> = this.app.models['Map'];
// Get all maps on server, sync with database.
let mapList: any[] = await this.app.serverFacade.client.gbx.query('GetMapList', [-1, 0]);
// Clear current list first.
this.list = {};
// TODO: Define interfaces for the maniaplanet return values.
for (let data of mapList) {
let exists = await Map.findOne({where: {uid: data.UId}});
if (! exists) {
let map = await Map.create({
uid: data.UId,
name: data.Name,
author: data.Author,
environment: data.Environnement
});
// Save created database model to local list.
this.list[data.UId] = map;
} else {
// Name update?
if (exists.name !== data.Name) {
exists.set('name', data.Name);
let map = await exists.save();
this.list[data.UId] = map;
} else {
this.list[data.UId] = exists;
}
}
}
// The sync with db is done, now check the current map and set it in the this.current
let currentMapInfo = await this.app.serverFacade.client.gbx.query('GetCurrentMapInfo', []);
if (currentMapInfo) {
this.current = this.list[currentMapInfo.UId];
}
}
示例7: callback
create(item: T, callback: (error: any, result: any) => void) {
this.schema_model.create(item)
.then((data) => {
return callback(null, data);
})
.catch((error) => {
return callback(error, null);
});
}