{"id":21846569,"url":"https://github.com/tidbcloud/prisma-adapter","last_synced_at":"2025-06-13T02:33:12.742Z","repository":{"id":200416992,"uuid":"704483628","full_name":"tidbcloud/prisma-adapter","owner":"tidbcloud","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-26T13:24:20.000Z","size":46,"stargazers_count":11,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-14T13:34:50.524Z","etag":null,"topics":["cloudflare-workers","edge-computing","netlify","prisma","serverless","tidb","tidbcloud","vercel"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tidbcloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-10-13T11:01:43.000Z","updated_at":"2025-02-25T23:50:40.000Z","dependencies_parsed_at":"2023-10-16T22:27:29.477Z","dependency_job_id":"83f56d5b-e00d-476a-8309-8ffb1bd66b61","html_url":"https://github.com/tidbcloud/prisma-adapter","commit_stats":null,"previous_names":["tidbcloud/prisma-adapter"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/tidbcloud/prisma-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fprisma-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fprisma-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fprisma-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fprisma-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidbcloud","download_url":"https://codeload.github.com/tidbcloud/prisma-adapter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fprisma-adapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259567101,"owners_count":22877642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","edge-computing","netlify","prisma","serverless","tidb","tidbcloud","vercel"],"created_at":"2024-11-27T23:14:28.270Z","updated_at":"2025-06-13T02:33:12.730Z","avatar_url":"https://github.com/tidbcloud.png","language":"TypeScript","readme":"# @tidbcloud/prisma-adapter\n\nPrisma driver adapter for [TiDB Cloud Serverless Driver](https://github.com/tidbcloud/serverless-js). For more details, see [TiDB Cloud Serverless Driver Prisma Tutorial\n](https://docs.pingcap.com/tidbcloud/serverless-driver-prisma-example).\n\n## Before you start\n\nBefore you start, make sure you have:\n\n- A TiDB Cloud account\n- Node \u003e= 18\n- [Prisma CLI](https://www.prisma.io/docs/concepts/components/prisma-cli) installed\n\n## Install\n\nYou will need to install the `@tidbcloud/prisma-adapter` driver adapter and the `@tidbcloud/serverless` serverless driver.\n\n```\nnpm install @tidbcloud/prisma-adapter @tidbcloud/serverless\n```\n\n## DATABASE URL\n\nSet the environment to your .env file in the local environment. You can get connection information on the TiDB Cloud console.\n\n```env\n// .env\nDATABASE_URL=\"mysql://username:password@host:4000/database?sslaccept=strict\"\n```\n\n\u003e NOTE\n\u003e \n\u003e The adapter only supports Prisma Client. Prisma migration and introspection still go through the traditional TCP way. If you only need Prisma Client, you can set the DATABASE_URL as the `mysql://username:password@host/database` format which port and ssl parameters are not needed).\n\n## Define Prisma schema\n\nFirst, you need to create a Prisma schema file called schema.prisma and define the model. Here we use the user as an example.\n\n```prisma\n// schema.prisma\ngenerator client {\n    provider        = \"prisma-client-js\"\n    previewFeatures = [\"driverAdapters\"]\n}\n\ndatasource db {\n    provider     = \"mysql\"\n    url          = env(\"DATABASE_URL\")\n}\n\n// define model according to your database table\nmodel user {\n    id    Int     @id @default(autoincrement())\n    email String? @unique(map: \"uniq_email\") @db.VarChar(255)\n    name  String? @db.VarChar(255)\n}\n```\n\n## Query\n\nHere is an example of query:\n\n```js\n// query.js\nimport { PrismaTiDBCloud } from '@tidbcloud/prisma-adapter';\nimport { PrismaClient } from '@prisma/client';\nimport dotenv from 'dotenv';\n\n// setup\ndotenv.config();\nconst connectionString = `${process.env.DATABASE_URL}`;\n\n// init prisma client\nconst adapter = new PrismaTiDBCloud({url: connectionString});\nconst prisma = new PrismaClient({ adapter });\n\n// insert\nconst user = await prisma.user.create({\n    data: {\n        email: 'test@prisma.io',\n        name: 'test',\n    },\n})\nconsole.log(user)\n\n// query after insert\nconsole.log(await prisma.user.findMany())\n```\n\n## Transaction\n\nHere is an example of transaction:\n\n```js\n// query.js\nimport { PrismaTiDBCloud } from '@tidbcloud/prisma-adapter';\nimport { PrismaClient } from '@prisma/client';\nimport dotenv from 'dotenv';\n\n// setup\ndotenv.config();\nconst connectionString = `${process.env.DATABASE_URL}`;\n\n// init prisma client\nconst adapter = new PrismaTiDBCloud({url: connectionString});\nconst prisma = new PrismaClient({ adapter });\n\nconst createUser1 = prisma.user.create({\n  data: {\n    email: 'yuhang.shi@pingcap.com',\n    name: 'Shi Yuhang',\n  },\n})\n\nconst createUser2 = prisma.user.create({\n  data: {\n    email: 'yuhang.shi@pingcap.com',\n    name: 'Shi Yuhang2',\n  },\n})\n\nconst createUser3 = prisma.user.create({\n  data: {\n    email: 'yuhang2.shi@pingcap.com',\n    name: 'Shi Yuhang2',\n  },\n})\ntry {\n  await prisma.$transaction([createUser1, createUser2]) // Operations fail together\n} catch (e) {\n  console.log(e)\n  await prisma.$transaction([createUser1, createUser3], isolationLevel: \"READ COMMITTED\") // Operations succeed together\n}\n```\n\n## Choose a version\n\n| Adapter | Prisma/Prisma Client | serverless driver |\n|---------|----------------------|-------------------|\n| v5.4.x  | v5.4.x               | [v0.0.6, v0.1.0)  |\n| v5.5.x  | v5.5.x               | [v0.0.7, v0.1.0)  |\n| v5.6.x  | v5.6.x               | [v0.0.7, v0.1.0)  |\n| v5.7.x  | v5.7.x               | [v0.0.7, v0.1.0)  |\n| v5.8.x  | v5.8.x               | [v0.0.9, v0.1.0)  |\n| v5.9.x  | v5.9.x               | [v0.0.9, v0.1.0)  |\n| v5.10.x | v5.10.x              | \\\u003e= v0.1.0        |\n| v5.11.x | v5.11.x              | \\\u003e= v0.1.0        |\n| v5.12.x | v5.12.x              | \\\u003e= v0.1.0        |\n| v5.13.x | v5.13.x              | \\\u003e= v0.1.0        |\n| v5.14.x | v5.14.x              | \\\u003e= v0.1.0        |\n| v5.15.x | v5.15.x              | \\\u003e= v0.1.0        |\n| v5.20.x | v5.20.x              | \\\u003e= v0.1.0        |\n| v6.6.x  | v6.6.x               | \\\u003e= v0.1.0        |\n\nHere is the step to step guide for how to choose the version:\n1. Choose the Prisma version: Choose the one as you need.\n2. Choose the adapter version: If you are using Prisma vx.y.z, you can choose the latest adapter version in vx.y. Open an issue once you find the adapter version is not compatible with Prisma version.\n3. Choose the serverless driver version: You can always use the latest version according to the table above.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fprisma-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidbcloud%2Fprisma-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fprisma-adapter/lists"}