beta feature

Almost complete feature but still under development. There may be changes as we address issues and feedback. Use with caution.

Drizzle with Xata

Drizzle is a TypeScript ORM that is focused on type safety and closely follows the SQL syntax.

Install both Drizzle and @xata.io/drizzle with the Xata client. You can use the following package managers:

npm install drizzle-orm @xata.io/drizzle @xata.io/client

You can use Drizzle with a Xata, as demonstrated in the following examples:

import { pgTable, text } from 'drizzle-orm/pg-core';
import { drizzle } from '@xata.io/drizzle';
import { eq } from 'drizzle-orm';
import { getXataClient } from './xata'; // Generated client
 
const xata = getXataClient();
 
const drivers = pgTable('drivers', {
  id: text('id').primaryKey(),
  surname: text('surname'),
  forename: text('forename'),
  nationality: text('nationality')
});
 
const db = drizzle(xata);
 
const result = await db
  .select({ surname: drivers.surname, forename: drivers.forename })
  .from(drivers)
  .where(eq(drivers.nationality, 'Spanish'))
  .execute();

The code imports required modules from the drizzle-orm and @xata.io/drizzle libraries. It also brings in the eq function from drizzle-orm for value comparison and the getXataClient function from a local xata module. The getXataClient function is used to acquire an instance of the Xata client.

Currently, we recommend manually defining the schema like in the example above. We are working on utility functions to automatically generate the Drizzle model from the Xata database schema.

  • Drizzle migrations are not supported yet
  • Transactions are not supported yet