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/tidb-serverless';

const db = drizzle({ connection: { url: process.env.TIDB_URL }});

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

If you need to provide your existing driver:

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

const client = connect({ url: process.env.TIDB_URL });
const db = drizzle({ client });

What’s next?