Integrate Prisma with Tiger Data
Connect Prisma to Tiger Cloud or self-hosted TimescaleDB to introspect your schema and query your data with type-safe Prisma Client code.
Prisma is an open-source object-relational mapper (ORM) for Node.js and TypeScript that gives you a type-safe database client, schema migrations, and auto-generated queries.
This page shows you how to connect Prisma to Tiger Data, so that you can introspect an existing schema and query your data with a type-safe Prisma Client.
In this integration guide, you:
- Install Prisma and initialize a project.
- Set your connection details as the Prisma datasource.
- Introspect your schema and generate Prisma Client.
Prerequisites for this integration guide
To follow these steps, you'll need:
- A Tiger Cloud service, or a running instance of self-hosted TimescaleDB.
- Your connection details.
Connect Prisma to your service or database
Section titled “Connect Prisma to your service or database”Prisma reads your schema from an existing database rather than the other way around, so you introspect your service or database to generate the models Prisma Client uses.
- Install Prisma
In your project, install the Prisma CLI as a dev dependency, and the Prisma Client package:
Terminal window npm install -D prismanpm install @prisma/client - Initialize a Prisma project
Run the init command, targeting PostgreSQL:
Terminal window npx prisma init --datasource-provider postgresqlThis creates a
prisma/schema.prismafile with apostgresqldatasource, and a.envfile with a placeholderDATABASE_URL. - Set your connection details
In
.env, replace the placeholder with your connection details:Terminal window DATABASE_URL="postgresql://<user>:<password>@<host>:<port>/<dbname>?sslmode=require"Tiger Cloud requires an encrypted connection, so keep
sslmode=requirein the URL. If your service or database isn't reachable from where you run Prisma, make sure your network or firewall allows the connection first. - Introspect your schema
Pull the existing schema from your service or database into
prisma/schema.prisma:Terminal window npx prisma db pullPrisma connects using
DATABASE_URLand adds a model for each table it finds. Running this again overwrites models it generated previously, so keep any manual edits toschema.prismain version control before you re-run it. - Generate Prisma Client
Generate a type-safe client from the introspected schema:
Terminal window npx prisma generateRe-run this command any time
schema.prismachanges, so Prisma Client stays in sync with it.
Verify the integration
Section titled “Verify the integration”To confirm Prisma is working with your service or database:
- Query your data
In a script in your project, import Prisma Client and query one of the introspected models. Replace
<Model>with the name Prisma generated for one of your tables:import { PrismaClient } from "@prisma/client";const prisma = new PrismaClient();const rows = await prisma.<Model>.findMany({ take: 10 });console.log(rows); - Run the script
Run the script with Node (for example,
npx tsx script.tsif you're using tsx, or compile withtscfirst).You see rows from your service or database printed to the console, confirming Prisma Client can read your data.
You have successfully integrated Prisma with Tiger Data.
Troubleshooting
Section titled “Troubleshooting”Environment variable not found: DATABASE_URL: the Prisma CLI loads.envfrom your project root automatically; if you moved the file or you're running Prisma Client from a different working directory, load it yourself with a package likedotenvbefore Prisma Client is instantiated.P1001: Can't reach database server: confirm the host and port inDATABASE_URL, and that your network allows outbound connections from where Prisma runs. For Tiger Cloud, make suresslmode=requireis set.prisma db pulladds no models: confirm the role in your connection string hasSELECTaccess to the schema and tables you expect to see, and that those tables already exist. Prisma introspects existing structure, it doesn't create tables.
For other connectivity and authentication issues, see Troubleshoot Tiger Cloud integrations.