Distributed data and
powerful tooling with
Prisma & CockroachDB

Manage your data at scale with CockroachDB and Prisma – a next-generation ORM for Node.js and TypeScript.

tech

What is Prisma?

Prisma makes working with data easy! It offers a type-safe Node.js & TypeScript ORM, global database caching, connection pooling, and real-time database events.

Query
// Creating a new record
await prisma.user.create({
firstName: “Alice”,
email: “alice@prisma.io”
})
Table
id firstName email
1 Bobby bobby@tables.io
2 Nilufar nilu@email.com
3 Jürgen jums@dums.edu
4 Alice alice@prisma.io

How Prisma and CockroachDB fit together

CockroachDB is a relational, PostgreSQL wire-protocol-compatible database built for cloud applications and services. It automates the task of scale, so developers no longer have to choose between the data integrity offered by a relational database or the availability of NoSQL. And, when using CockroachDB developers don’t have to worry about deployment or ongoing administration/management of the database.

Prisma is an open-source ORM that integrates seamlessly with CockroachDB and supports the full development cycle. Prisma helps you define your database schema declaratively using the Prisma schema and fetch data from CockroachDB with full type safety using Prisma Client.

Together the two technologies give developers access to the scalable infrastructure of a distributed database without requiring them to be experts in hosting and scaling databases.

Prisma Schema

The Prisma schema uses Prisma's modeling language to define your database schema. It makes data modeling easy and intuitive, especially when it comes to modeling relations.

Migrating your database schema is painless: you update the data model in your Prisma schema, run prisma db push to apply the schema changes, and CockroachDB will handle applying those changes to each database in your cluster.

1// Define the `User` table in the database
2model User {
3 id String @id @default(cuid())
4 email String @unique
5 password String
6 name String?
7 posts Post[]
8}
9
10// Define the `Post` table in the database
11model Post {
12 id String @id @default(cuid())
13 title String
14 content String?
15 authorId String
16 author User @relation(fields: [authorId], references: [id])
17}

"CockroachDB and Prisma is a match made in heaven. Not only does it simplify data but it also eliminates database operations so you can focus on what you want to…your code."

Aydrian HowardAydrian Howard -
Developer Advocate of Cockroach Labs

Why Prisma and CockroachDB?

Zero downtime migrations

CockroachDB clusters your databases into a single logical database, allowing it to apply schema migrations incrementally.

Introspection & optimization tools

Introspection allows you to pull down and easy-to-read representation of your database's schema. Here you have the ability to view and modify your indexes.

Deploy to multiple cloud providers

CockroachDB multi-cloud deployments allow you to avoid cloud-specific outages by deploying your database cluster to multiple providers at once.

Type-safe database client

Prisma Client ensures fully type-safe database queries with benefits like autocompletion - even in JavaScript.

Referential integrity with serverless

CockroachDB's distributed data model allows you to manage your relational data as if it were in a single logical database.

Intuitive data modeling

Prisma's modeling language is declarative and lets you intuitively describe your database schema.

blog post

Prisma support for CockroachDB is production ready

In this article, we announce the general availability of the Prisma CockroachDB connector and take a look at some of the reasons why you should use Prisma and CockroachDB together.

showcase

How Tryg has leveraged Prisma to democratize data

How Tryg transforms billions of records from different data sources, and expose a single data model via GraphQL and Prisma.

Featured Prisma & CockroachDB resources

CockroachDB data source connector documentation

This section of the docs covers the details of Prisma's CockroachDB data source connector.

Using Prisma with CockroachDB

In this section of the docs, you will learn about the concepts behind using Prisma and CockroachDB, the commonalities and differences between CockroachDB and other database providers, and the process for configuring your application to integrate with CockroachDB.