• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Sequelize.literal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中Sequelize.literal函数的典型用法代码示例。如果您正苦于以下问题:TypeScript literal函数的具体用法?TypeScript literal怎么用?TypeScript literal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: aggregateBlockReward

  /**
   * Gets block rewards for a delegate for time period
   */
  // tslint:disable-next-line max-line-length
  public async aggregateBlockReward(filter: { generatorPublicKey: publicKey, start?: number, end?: number }): Promise<{ fees: number, rewards: number, count: number }> {
    const params: any                                                         = {};
    params.generatorPublicKey                                                 = filter.generatorPublicKey;
    params.delegates                                                          = this.constants.activeDelegates;
    const timestampClausole: { timestamp?: any } = {timestamp: {}};

    if (typeof(filter.start) !== 'undefined') {
      timestampClausole.timestamp[Op.gte] = filter.start - this.constants.epochTime.getTime() / 1000;
    }

    if (typeof(filter.end) !== 'undefined') {
      timestampClausole.timestamp[Op.lte] = filter.end - this.constants.epochTime.getTime() / 1000;
    }

    if (typeof(timestampClausole.timestamp[Op.gte]) === 'undefined'
      && typeof(timestampClausole.timestamp[Op.lte]) === 'undefined') {
      delete timestampClausole.timestamp;
    }

    const bufPublicKey = Buffer.from(params.generatorPublicKey, 'hex');
    const acc          = await AccountsModel
      .findOne({where: {isDelegate: 1, publicKey: bufPublicKey}});
    if (acc === null) {
      throw new Error('Account not found or is not a delegate');
    }

    const res: { count: string, rewards: string } = await this.BlocksModel.findOne({
      attributes: [
        sequelize.literal('COUNT(1)'),
        sequelize.literal('SUM("reward") as rewards'),
      ],
      raw       : true,
      where     : {
        ...timestampClausole,
        generatorPublicKey: bufPublicKey,
      },
    }) as any;

    const data = {
      count  : parseInt(res.count, 10),
      fees   : (await this.RoundsFeesModel.aggregate('fees', 'sum', {
        where: {
          ...timestampClausole,
          publicKey: bufPublicKey,
        },
      })) as number,
      rewards: res.rewards === null ? 0 : parseInt(res.rewards, 10),
    };
    if (isNaN(data.fees)) {
      // see https://github.com/sequelize/sequelize/issues/6299
      data.fees = 0;
    }
    return data;
  }
开发者ID:RiseVision,项目名称:rise-node,代码行数:58,代码来源:utils.ts


示例2: updateMissedBlocks

 /**
  * Updates accounts and add a missing block to whoever skipped one
  * @returns {Promise<void>}
  */
 public updateMissedBlocks(): DBOp<any> {
   if (this.scope.roundOutsiders.length === 0) {
     return null;
   }
   return {
     model  : this.scope.models.AccountsModel,
     options: {
       where: {
         address: { [Op.in]: this.scope.roundOutsiders },
       },
     },
     type   : 'update',
     values : {
       // tslint:disable-next-line max-line-length
       cmb          : this.scope.dposV2 ? sequelize.literal(`cmb ${this.scope.backwards ? '-' : '+'} 1`) : 0,
       missedblocks : sequelize.literal(`missedblocks ${this.scope.backwards ? '-' : '+'} 1`),
     },
   };
 }
开发者ID:RiseVision,项目名称:rise-node,代码行数:23,代码来源:round.ts


示例3: logAccess

 function logAccess(user: string) {
     // User already known, log this access
     models.log_access.update({
         last_seen : new Date(),
         access_counter : sequelize.literal("access_counter + 1")
     }, {
         where : {
             user : user,
         }
     }).then(function(r: any) {
     }, function(error: any) {
         console.log(error);
     });
 };
开发者ID:giovannipessiva,项目名称:l4w,代码行数:14,代码来源:database.ts


示例4: listThreadParentComments

  static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') {
    const query = {
      order: [ [ 'createdAt', order ] ],
      where: {
        id: {
          [ Sequelize.Op.in ]: Sequelize.literal('(' +
            'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +
            'SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ' + comment.id + ' UNION ' +
            'SELECT p.id, p."inReplyToCommentId" from "videoComment" p ' +
            'INNER JOIN children c ON c."inReplyToCommentId" = p.id) ' +
            'SELECT id FROM children' +
          ')'),
          [ Sequelize.Op.ne ]: comment.id
        }
      },
      transaction: t
    }

    return VideoCommentModel
      .scope([ ScopeNames.WITH_ACCOUNT ])
      .findAll(query)
  }
开发者ID:jiang263,项目名称:PeerTube,代码行数:22,代码来源:video-comment.ts


示例5: function

const buildArrayArgAttribute = function (table: string): any {
  return [sequelize.literal(`(SELECT ARRAY_AGG("dependentId") FROM mem_accounts2${table} WHERE "accountId" = "AccountsModel"."address")`), table];
};
开发者ID:RiseVision,项目名称:rise-node,代码行数:3,代码来源:AccountsModel.ts


示例6: listAllAndSharedByActorForOutbox

  static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
    function getRawQuery (select: string) {
      const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +
        'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
        'INNER JOIN "account" AS "Account" ON "Account"."id" = "VideoChannel"."accountId" ' +
        'WHERE "Account"."actorId" = ' + actorId
      const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' +
        'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
        'WHERE "VideoShare"."actorId" = ' + actorId

      return `(${queryVideo}) UNION (${queryVideoShare})`
    }

    const rawQuery = getRawQuery('"Video"."id"')
    const rawCountQuery = getRawQuery('COUNT("Video"."id") as "total"')

    const query = {
      distinct: true,
      offset: start,
      limit: count,
      order: getSort('createdAt', [ 'Tags', 'name', 'ASC' ]),
      where: {
        id: {
          [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
        },
        [Sequelize.Op.or]: [
          { privacy: VideoPrivacy.PUBLIC },
          { privacy: VideoPrivacy.UNLISTED }
        ]
      },
      include: [
        {
          attributes: [ 'id', 'url' ],
          model: VideoShareModel.unscoped(),
          required: false,
          // We only want videos shared by this actor
          where: {
            [Sequelize.Op.and]: [
              {
                id: {
                  [Sequelize.Op.not]: null
                }
              },
              {
                actorId
              }
            ]
          },
          include: [
            {
              attributes: [ 'id', 'url' ],
              model: ActorModel.unscoped()
            }
          ]
        },
        {
          model: VideoChannelModel.unscoped(),
          required: true,
          include: [
            {
              attributes: [ 'name' ],
              model: AccountModel.unscoped(),
              required: true,
              include: [
                {
                  attributes: [ 'id', 'url', 'followersUrl' ],
                  model: ActorModel.unscoped(),
                  required: true
                }
              ]
            },
            {
              attributes: [ 'id', 'url', 'followersUrl' ],
              model: ActorModel.unscoped(),
              required: true
            }
          ]
        },
        VideoFileModel,
        TagModel
      ]
    }

    return Bluebird.all([
      // FIXME: typing issue
      VideoModel.findAll(query as any),
      VideoModel.sequelize.query(rawCountQuery, { type: Sequelize.QueryTypes.SELECT })
    ]).then(([ rows, totals ]) => {
      // totals: totalVideos + totalVideoShares
      let totalVideos = 0
      let totalVideoShares = 0
      if (totals[0]) totalVideos = parseInt(totals[0].total, 10)
      if (totals[1]) totalVideoShares = parseInt(totals[1].total, 10)

      const total = totalVideos + totalVideoShares
      return {
        data: rows,
        total: total
      }
    })
//.........这里部分代码省略.........
开发者ID:jiang263,项目名称:PeerTube,代码行数:101,代码来源:video.ts


示例7: parseInt

  [ScopeNames.AVAILABLE_FOR_LIST]: (options: {
    actorId: number,
    hideNSFW: boolean,
    filter?: VideoFilter,
    withFiles?: boolean,
    accountId?: number,
    videoChannelId?: number
  }) => {
    const accountInclude = {
      attributes: [ 'id', 'name' ],
      model: AccountModel.unscoped(),
      required: true,
      where: {},
      include: [
        {
          attributes: [ 'id', 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
          model: ActorModel.unscoped(),
          required: true,
          where: VideoModel.buildActorWhereWithFilter(options.filter),
          include: [
            {
              attributes: [ 'host' ],
              model: ServerModel.unscoped(),
              required: false
            },
            {
              model: AvatarModel.unscoped(),
              required: false
            }
          ]
        }
      ]
    }

    const videoChannelInclude = {
      attributes: [ 'name', 'description', 'id' ],
      model: VideoChannelModel.unscoped(),
      required: true,
      where: {},
      include: [
        {
          attributes: [ 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
          model: ActorModel.unscoped(),
          required: true,
          include: [
            {
              attributes: [ 'host' ],
              model: ServerModel.unscoped(),
              required: false
            },
            {
              model: AvatarModel.unscoped(),
              required: false
            }
          ]
        },
        accountInclude
      ]
    }

    // Force actorId to be a number to avoid SQL injections
    const actorIdNumber = parseInt(options.actorId.toString(), 10)
    const query: IFindOptions<VideoModel> = {
      where: {
        id: {
          [Sequelize.Op.notIn]: Sequelize.literal(
            '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
          ),
          [ Sequelize.Op.in ]: Sequelize.literal(
            '(' +
            'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
            'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
            'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
            ' UNION ' +
            'SELECT "video"."id" AS "id" FROM "video" ' +
            'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
            'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
            'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
            'LEFT JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' +
            'WHERE "actor"."serverId" IS NULL OR "actorFollow"."actorId" = ' + actorIdNumber +
            ')'
          )
        },
        // Always list public videos
        privacy: VideoPrivacy.PUBLIC,
        // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
        [ Sequelize.Op.or ]: [
          {
            state: VideoState.PUBLISHED
          },
          {
            [ Sequelize.Op.and ]: {
              state: VideoState.TO_TRANSCODE,
              waitTranscoding: false
            }
          }
        ]
      },
      include: [ videoChannelInclude ]
    }
//.........这里部分代码省略.........
开发者ID:jiang263,项目名称:PeerTube,代码行数:101,代码来源:video.ts


示例8:

    sequelize.fn('max', sequelize.col('age')),

    // Will order by max(age) DESC
    [sequelize.fn('max', sequelize.col('age')), 'DESC'],

    // Will order by  otherfunction(`col1`, 12, 'lalala') DESC
    [sequelize.fn('otherfunction', sequelize.col('col1'), 12, 'lalala'), 'DESC'],

    // Will order by name on an associated User
    [User, 'name', 'DESC'],

    // Will order by name on an associated User aliased as Friend
    [{model: User, as: 'Friend'}, 'name', 'DESC'],

    // Will order by name on a nested associated Company of an associated User
    [User, Company, 'name', 'DESC']
  ]
})

Something.findOne({
  order: 'convert(user_name using gbk)'
})

Something.findOne({
  order: 'username DESC'
})

Something.findOne({
  order: sequelize.literal('convert(user_name using gbk)')
})
开发者ID:Thylossus,项目名称:typed-sequelize,代码行数:30,代码来源:test.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Sequelize.sync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Sequelize.fn函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap