Skip to content

ogawa0071/tidb-prisma-cloudflare

Repository files navigation

TiDB Serverless + Prisma (Edge Functions Preview) + Cloudflare Workers

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

Demo

https://tidb-prisma-cloudflare.ogawa0071.workers.dev/

How to Use

You will need the following:

  • A Cloudflare account
  • A TiDB Serverless account
  1. Clone the repository
git clone https://github.com/ogawa0071/tidb-prisma-cloudflare.git
cd tidb-prisma-cloudflare
npm install
  1. Copy .env and .dev.vars files by running the following commands:
cp .env.example .env
cp .dev.vars.example .dev.vars
  1. Update .env and .dev.vars files with your TiDB Serverless connection string.

  2. Run the following commands to apply the existing database migrations located in the /prisma directory:

npx prisma migrate dev --name init
npx prisma generate
  1. Run the following command to seed the database with initial data:
npx prisma db seed
  1. Run the following command to start the server:
npm run dev
  1. Open the browser at http://localhost:8787 to see result.

  2. Run the following commands to deploy application and configure secret on the Cloudflare Workers platform:

npm deploy
npx wrangler secret put DATABASE_URL

About

Example of TiDB Serverless + Prisma + Cloudflare Workers, without Prisma Accelerate.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published