TiDB Serverless is compatible with MySQL, so you can use MySQL connection guide to connect to it.
Drizzle <> TiDB Serverless
This guide assumes familiarity with:
- Database connection basics with Drizzle
- TiDB database - website
- TiDB HTTP Driver - website
- Drizzle MySQL drivers - docs
According to the official website, TiDB Serverless is a fully-managed, autonomous DBaaS with split-second cluster provisioning and consumption-based pricing.
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
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 });