This repository showcases an example of integrating TiDB Serverless with Cloudflare Workers, leveraging the edge function deployment support provided by Prisma.
Despite the documentation for TiDB Serverless stating that "Currently, @tidbcloud/prisma-adapter
is not compatible with edge environments", this demo proves otherwise by successfully operating in such conditions.
Please note that this setup does not use Prisma Accelerate connection pool.
For more details on Prisma Edge Functions Preview, check out: https://www.prisma.io/docs/orm/prisma-client/deployment/edge/overview
https://tidb-prisma-cloudflare.ogawa0071.workers.dev/
You will need the following:
- A Cloudflare account
- A TiDB Serverless account
- Clone the repository
git clone https://github.com/ogawa0071/tidb-prisma-cloudflare.git
cd tidb-prisma-cloudflare
npm install
- Copy
.env
and.dev.vars
files by running the following commands:
cp .env.example .env
cp .dev.vars.example .dev.vars
-
Update
.env
and.dev.vars
files with your TiDB Serverless connection string. -
Run the following commands to apply the existing database migrations located in the
/prisma
directory:
npx prisma migrate dev --name init
npx prisma generate
- Run the following command to seed the database with initial data:
npx prisma db seed
- Run the following command to start the server:
npm run dev
-
Open the browser at http://localhost:8787 to see result.
-
Run the following commands to deploy application and configure secret on the Cloudflare Workers platform:
npm deploy
npx wrangler secret put DATABASE_URL