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


TypeScript prisma-cli-engine.Client类代码示例

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


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

示例1: fetchAndPrintSchema

export async function fetchAndPrintSchema(
  client: Client,
  serviceName: string,
  stageName: string,
  token?: string,
): Promise<string> {
  const introspection = await client.introspect(serviceName, stageName, token)
  const schema = buildClientSchema(introspection)

  const sdl = printSchema(schema)
  const document = parse(sdl)
  const groupedDefinitions = groupBy(document.definitions, classifyDefinition)
  let sortedDefinitions: DefinitionNode[] = []

  typesOrder.map(type => {
    const definitions = groupedDefinitions[type]
    sortedDefinitions = sortedDefinitions.concat(definitions)
  })

  let newSdl = print({
    kind: Kind.DOCUMENT,
    definitions: sortedDefinitions,
  })

  const newDocument = parse(newSdl)

  // add comments to document
  let countOffset = 0
  let charOffset = 0
  typesOrder.forEach((type, index) => {
    if (!groupedDefinitions[type]) {
      return
    }
    const definitionCount = groupedDefinitions[type].length
    const definitions = newDocument.definitions.slice(
      countOffset,
      definitionCount,
    )
    const start = definitions[0].loc!.start

    const comment = `\
${index > 0 ? '\n' : ''}#
# ${descriptions[type]}
#\n\n`

    newSdl =
      newSdl.slice(0, start + charOffset) +
      comment +
      newSdl.slice(start + charOffset)

    charOffset += comment.length
    countOffset += definitionCount
  })

  const header = `# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
# DO NOT EDIT THIS FILE DIRECTLY\n\n`

  return header + newSdl
}
开发者ID:ahmb84,项目名称:prisma,代码行数:59,代码来源:printSchema.ts

示例2: 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

示例3: reset

 async reset(serviceName, stageName) {
   const before = Date.now()
   this.out.action.start(
     `Resetting ${chalk.bold(`${serviceName}@${stageName}`)}`,
   )
   await this.client.reset(
     serviceName,
     stageName,
     this.definition.getToken(serviceName, stageName),
   )
   this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
 }
开发者ID:ahmb84,项目名称:prisma,代码行数:12,代码来源:Seeder.ts

示例4: executeQuery

  async executeQuery(
    filePath: string,
    serviceName: string,
    stageName: string,
    token?: string,
    workspaceSlug?: string,
  ) {
    if (!fs.pathExistsSync(filePath)) {
      throw new Error(`Can't find seed import file ${filePath}`)
    }

    const query = fs.readFileSync(filePath, 'utf-8')
    try {
      parse(query)
    } catch (e) {
      throw new Error(`Error while parsing ${filePath}:\n${e.message}`)
    }

    await this.client.exec(serviceName, stageName, query, token, workspaceSlug)
  }
开发者ID:ahmb84,项目名称:prisma,代码行数:20,代码来源:Seeder.ts

示例5: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。