当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Model.findOne方法代码示例

本文整理汇总了TypeScript中Sequelize.Model.findOne方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Model.findOne方法的具体用法?TypeScript Model.findOne怎么用?TypeScript Model.findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sequelize.Model的用法示例。


在下文中一共展示了Model.findOne方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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);
 }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:14,代码来源:SettingManager.ts

示例2: findByUsername

 findByUsername (username: string, callback: (error: any, result: any) => void) {
     this.schema_model.findOne({
         where: {
             username: username
         }
     })
         .then((data) => {
             return callback(null, data);
         })
         .catch((error) => {
             return callback(error, null);
         });
 }  
开发者ID:pmatam,项目名称:nodejs,代码行数:13,代码来源:base_repository.ts

示例3: findById

 findById (idItem: number, callback: (error: any, result: any) => void) {
     this.schema_model.findOne({
         where: {
             id: idItem
         }
     })
         .then((data) => {
             return callback(null, data);
         })
         .catch((error) => {
             return callback(error, null);
         });
 }
开发者ID:pmatam,项目名称:nodejs,代码行数:13,代码来源:base_repository.ts

示例4: removeSetting

 /**
  * Remove setting.
  * @param context
  * @param setting key or setting instance.
  */
 public async removeSetting (context: any, setting: Setting | string): Promise<any> {
   let instance: Instance<any> = await this.settingModel.findOne({
     where: { $and: [
       {context: { $eq: this.getContextString(context) }},
       {key: { $eq: (typeof setting === 'string' ? setting : (setting as Setting).key) }}
     ]}
   });
   if (instance) {
     await instance.destroy();
     return true;
   }
   return false;
 }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:18,代码来源:SettingManager.ts

示例5: replaceSetting

  /**
   * Replace setting.
   * @param context
   * @param setting
   */
  public async replaceSetting (context: any, setting: Setting): Promise<any> {
    let instance = await this.settingModel.findOne({
      where: { $and: [
        {context: { $eq: this.getContextString(context) }},
        {key: { $eq: setting.key }}
      ]}
    });
    if (! instance) throw new Error('Setting key is not yet defined in the context store! (\''+setting.key+'\')');

    instance.set(setting);

    await instance.save();
  }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:18,代码来源:SettingManager.ts

示例6: setSetting

  /**
   * Set setting value.
   * @param context
   * @param key
   * @param value
   */
  public async setSetting (context: any, key: string, value: any): Promise<any> {
    let setting = await this.settingModel.findOne({
      where: { $and: [
        {context: { $eq: this.getContextString(context) }},
        {key: { $eq: key }}
      ]}
    });

    if (! setting) {
      throw new Error('Setting key is not yet defined in the context store!');
    }

    setting.set('value', value);
    await setting.save();
  }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:21,代码来源:SettingManager.ts

示例7: 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];
    }
  }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:41,代码来源:Maps.ts


注:本文中的Sequelize.Model.findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。