Almost complete feature but still under development. There may be changes as we address issues and feedback. Use with caution.
Prisma with Xata
Prisma ORM is a TypeScript ORM that is focused on type safety and developer experience.
Prisma currently only works with Xata databases that are set up with the ability to make direct Postgres connections. Follow the instructions below to learn how to configure Prisma to work with Xata in this method.
Enable Postgres connections in Xata
Xata now allows direct connections to Postgres. To enable it follow these steps:
Enable Postgres in your workspace settings
Create a brand new database with Postgres enabled
Use the @next
version of our APIs within your project
npm install -g @xata.io/cli@next
npm install @xata.io/client@next
Check the Postgres documentation for details and troubleshooting.
You can use the following package managers:
npm install prisma
pnpm add prisma
yarn add prisma
To use Xata with Prisma define a postgresql datasource in the schema.prisma
file. Here is an example:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
You can manually define the schema or use the introspection feature to generate the schema from the database.
To introspect the database, you can use the following command:
prisma db pull
To generate the client, you can use the following command:
prisma generate
After generating the client, you can use it in your code. Here is an example of using the client:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient({});
const result = await prisma.users.findMany({
where: {
name: 'Alice'
}
});
Migrations with Prisma require a shadow database.
For this purpose, create an additional database in Xata and configure its Postgres endpoint as shadowDatabaseUrl
in the datasource, as suggested by the relevant Prisma documentation.
- Xata File attachments columns are read-only and only shows file metadata. You will need to use the SDK to upload and download files.