Become a Gold Sponsor

Drizzle <> TiDB Serverless

This guide assumes familiarity with:

According to the official website, TiDB Serverless is a fully-managed, autonomous DBaaS with split-second cluster provisioning and consumption-based pricing.

TiDB Serverless is compatible with MySQL, so you can use MySQL connection guide to connect to it.

TiDB Serverless provides an HTTP driver for edge environments. It is natively supported by Drizzle ORM via drizzle-orm/tidb-serverless package.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm @tidbcloud/serverless
npm i -D drizzle-kit

Step 2 - Initialize the driver and make a query

index.ts
import { drizzle } from 'drizzle-orm/connect';

const db = await drizzle('tidb-serverless', { connection: { url: process.env.TIDB_URL }});

const response = await db.select().from(...)

If you need a synchronous connection, you can use our additional connection API, where you specify a driver connection and pass it to the Drizzle instance.

import { connect } from '@tidbcloud/serverless';
import { drizzle } from 'drizzle-orm/tidb-serverless';

const client = connect({ url: '...' });
const db = drizzle(client);

What’s next?