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


TypeScript Client.download方法代码示例

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


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

示例1: downloadFiles

  async downloadFiles(
    fileType: FileType,
    serviceName: string,
    stage: string,
    token?: string,
    workspaceSlug?: string,
  ) {
    const before = Date.now()
    this.out.action.start(`Downloading ${fileType}`)

    let cursor: ExportCursor = {
      table: 0,
      row: 0,
      field: 0,
      array: 0,
    }

    const cursorSum = c =>
      Object.keys(c).reduce((acc, curr) => acc + c[curr], 0)

    const leadingZero = (n: number, zeroes: number = 6) =>
      repeat('0', Math.max(zeroes - String(n).length, 0)) + n

    let count = 1
    const filesDir = path.join(this.exportDir, `${fileType}/`)
    while (cursorSum(cursor) >= 0) {
      const data = await this.client.download(
        serviceName,
        stage,
        JSON.stringify({
          fileType,
          cursor,
        }),
        token,
        workspaceSlug,
      )

      debug(data)

      if (data.errors) {
        throw new Error(data.errors)
      }

      const jsonString = JSON.stringify({
        valueType: fileType,
        values: data.out.jsonElements,
      })

      fs.writeFileSync(
        path.join(filesDir, `${leadingZero(count)}.json`),
        jsonString,
      )

      cursor = data.cursor
      count++
    }

    this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
  }
开发者ID:ahmb84,项目名称:prisma,代码行数:59,代码来源:Exporter.ts


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