How to use the @prisma/sdk.IntrospectionEngine function in @prisma/sdk

To help you get started, we’ve selected a few @prisma/sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prisma / prisma2 / cli / introspection / src / commands / Introspect.ts View on Github external
config = await getConfig({
        datamodelPath: schemaPath,
      })

      const datasource = config.datasources[0]
      if (!datasource) {
        throw new Error(
          `Either provide ${chalk.greenBright('--url')} or add a ${chalk.greenBright.bold(
            'datasource',
          )} in the ${chalk.greenBright(path.relative(process.cwd(), schemaPath))} file.`,
        )
      }
      url = datasource.url.value
    }

    const engine = new IntrospectionEngine({
      cwd: schemaPath ? path.dirname(schemaPath) : undefined,
    })

    const basedOn =
      !args['--url'] && schemaPath
        ? ` based on datasource defined in ${chalk.underline(path.relative(process.cwd(), schemaPath))}`
        : ''
    log(`Introspecting${basedOn} …`)

    const before = Date.now()
    let introspectionSchema = await engine.introspect(url)
    engine.stop()

    if (introspectionSchema.trim() === '') {
      throw new Error(`Empty introspection result for ${chalk.underline(url)}`)
    }