當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。