This repo is an example of how to run TiDB Serverless with our prisma adapter on Vercel Edge functions
Before running through the following steps, make sure you have:
- Node.js installed on your machine
- a Vercel account
- a TiDB Serverless instance up and running and its connection string available
- cd to the correct directory:
cd prisma/prisma-vercel-example
Create a .env
file in the root of the project with the following content. You can get the connection string from the TiDB Serverless console.
DATABASE_URL="mysql://<user>:<password>@<host>:4000/<database>?sslaccept=strict"
npm install
npx prisma db push
Visit /api/edge to see the result
vercel dev
Add environment variable DATABASE_URL
npx vercel env add DATABASE_URL
Deploy to Vercel preview
vercel deploy
Deploy to Vercel prod
vercel --prod
- Install vercel cli:
npm install -g vercel
- Initialize project:
npx create-next-app@latest
- Set up prisma:
cd prisma-cloudflare-worker-example
andnpm install --save-dev prisma
- Init prisma:
npx prisma init --datasource-provider mysql
- Update .env file:
DATABASE_URL=mysql://<user>:<password>@<host>:4000/<database>?sslaccept=strict
- Update schema.prisma file: use driverAdapters as this example does
- Install dependencies:
npm install @tidbcloud/prisma-adapter @tidbcloud/serverless
- Configure postinstall hook: add a new key
"postinstall": "prisma generate"
to the scripts section in your package.json as this example - Sync db schema:
npx prisma db push
- Write Code: add
api/edge/route.js
file and write code as this example