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


TypeScript Client.upload方法代码示例

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


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

示例1: upload

  async upload(
    serviceName: string,
    stage: string,
    token?: string,
    workspaceSlug?: string,
  ) {
    try {
      if (!this.isDir) {
        this.unzip()
      }
      let before = Date.now()
      this.out.action.start('Validating data')
      const files = await this.getFiles()
      this.validateFiles(files)
      this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
      before = Date.now()
      this.out.log('\nUploading nodes...')
      const state = this.getState()

      for (const fileName of files.nodes) {
        const n = this.getNumber(fileName)
        if (state.nodes >= n) {
          this.out.log(`Skipping file ${fileName} (already imported)`)
          continue
        }
        const file = fs.readFileSync(fileName, 'utf-8')
        const json = JSON.parse(file)
        const result = await this.client.upload(
          serviceName,
          stage,
          file,
          token,
          workspaceSlug,
        )
        this.checkForErrors(result)
        if (result.length > 0) {
          this.out.log(this.out.getStyledJSON(result))
          this.out.exit(1)
        }

        state.nodes = n
        this.saveState(state)
      }
      this.out.log(
        'Uploading nodes done ' + chalk.cyan(`${Date.now() - before}ms`),
      )
      before = Date.now()
      this.out.log('\nUploading lists')
      for (const fileName of files.lists) {
        const n = this.getNumber(fileName)
        if (state.lists >= n) {
          this.out.log(`Skipping file ${fileName} (already imported)`)
          continue
        }
        const file = fs.readFileSync(fileName, 'utf-8')
        const json = JSON.parse(file)
        const result = await this.client.upload(
          serviceName,
          stage,
          file,
          token,
          workspaceSlug,
        )
        this.checkForErrors(result)
        if (result.length > 0) {
          this.out.log(this.out.getStyledJSON(result))
          this.out.exit(1)
        }
        state.lists = n
        this.saveState(state)
      }
      this.out.log(
        'Uploading lists done ' + chalk.cyan(`${Date.now() - before}ms`),
      )
      before = Date.now()
      this.out.log('\nUploading relations')
      for (const fileName of files.relations) {
        const n = this.getNumber(fileName)
        if (state.relations >= n) {
          this.out.log(`Skipping file ${fileName} (already imported)`)
          continue
        }
        const file = fs.readFileSync(fileName, 'utf-8')
        const json = JSON.parse(file)
        const result = await this.client.upload(
          serviceName,
          stage,
          file,
          token,
          workspaceSlug,
        )
        this.checkForErrors(result)
        if (result.length > 0) {
          this.out.log(this.out.getStyledJSON(result))
          this.out.exit(1)
        }
        state.relations = n
        this.saveState(state)
      }
      this.saveState(defaultState)
//.........这里部分代码省略.........
开发者ID:ahmb84,项目名称:prisma,代码行数:101,代码来源:Importer.ts


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