Skip to content

Prisma

Integration · Prisma

If you already maintain a Prisma schema file, @askdb/prisma reads it directly and produces an AskDB schema artifact. No live database connection during introspection.

  • You have a schema.prisma and want to skip the live-database introspection step.
  • You’re working in CI, on a laptop without DB access, or in an air-gapped environment.
  • You pass ask() the matching dialect id at generation time (see Supported providers); no engine package is needed for that.

For the CLI and Studio, install @askdb/prisma in your project next to askdb. askdb and @askdb/studio list it as an optional peer: they load it only to read a Prisma schema, and don’t install it, because it brings in Prisma.

Terminal window
npm install askdb @askdb/prisma ai zod

ai and zod are there for Yarn Plug’n’Play: @askdb/prisma loads @askdb/core, which can only load them from your project. npx askdb@latest init --database prisma installs all of them for you. askdb also finds the copy in your project when it runs from elsewhere, as npx askdb does. To run the CLI without installing anything, name both packages in the one-off command: npx -p askdb -p @askdb/prisma askdb introspect --engine prisma.

Without it, askdb introspect --engine prisma exits 1 and names the package to install, and Studio shows the same message instead of resyncing.

To call the connector from your own code instead of the CLI:

Terminal window
npm install @askdb/prisma @askdb/introspect ai

Plus @askdb/core and a model provider to generate SQL — for example, OpenAI:

Terminal window
npm install @askdb/core ai @ai-sdk/openai

@askdb/prisma doesn’t bundle a SQL dialect. The built-in dialects live in @askdb/core: pass ask() the dialect id that matches your runtime database (see the table below). The artifact records your datasource.provider, so the CLI picks the dialect from it when askdb.config.ts sets no dialect.

Terminal window
# Introspect a Prisma schema file (or directory of .prisma files)
npx askdb introspect \
--engine prisma \
--prisma-schema ./prisma/schema.prisma \
--out my-app.schema \
--schema-id my-app
# Print the introspection result without writing
npx askdb introspect --engine prisma --prisma-schema ./prisma --print
# Diff against an existing schema artifact
npx askdb introspect --engine prisma --prisma-schema ./prisma --diff my-app.schema

To make --prisma-schema optional on repeat runs, set introspection.providerConfig.prisma.schemaPath in askdb.config.ts — or rely on auto-discovery: with provider: "prisma" and no path configured, AskDB looks in your project root for prisma/schema.prisma, then schema.prisma, then a prisma/ directory (a multi-file schema), and uses the first it finds.

import { introspect } from "@askdb/introspect";
import { createPrismaConnector } from "@askdb/prisma";
await introspect(
{ schemaPath: "./prisma", schemaId: "my-app" },
{ outDir: "my-app.schema", schemaId: "my-app" },
{ connector: createPrismaConnector() },
);

@askdb/prisma supports the five Prisma providers below; any other datasource.provider throws. At generation time, use the matching dialect id. To introspect the live database instead of the .prisma file, install the matching engine package:

Prisma providerdialect idEngine package (live introspection)
postgresql"postgres"@askdb/postgres
cockroachdb"cockroachdb"none: introspect the .prisma file
mysql"mysql"@askdb/mysql
sqlite"sqlite"@askdb/sqlite
sqlserver"sqlserver"@askdb/sqlserver

MongoDB is not supported — AskDB targets relational engines. The @askdb/prisma reference lists the mapping with the rest of the package’s API.

@askdb/prisma is a file-only connector. It does not connect to a database, it does not execute generated SQL, and it does not include a SQL dialect. For SQL generation, pass ask() the dialect id from the table above.