{"id":15486024,"url":"https://github.com/tidbcloud/serverless-js","last_synced_at":"2025-04-07T15:06:42.700Z","repository":{"id":187401022,"uuid":"676780600","full_name":"tidbcloud/serverless-js","owner":"tidbcloud","description":"A fetch API-compatible driver to connect TiDB Serverless from serverless/edge functions","archived":false,"fork":false,"pushed_at":"2025-01-24T02:50:30.000Z","size":105,"stargazers_count":24,"open_issues_count":3,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-01T02:03:24.038Z","etag":null,"topics":["bun","cloudflare-workers","deno","edge-computing","javascript","mysql","netlify","serverless","tidb","typescript","vercel"],"latest_commit_sha":null,"homepage":"https://tidb.cloud/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","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":"LICENSE","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}},"created_at":"2023-08-10T02:11:34.000Z","updated_at":"2025-02-18T09:20:51.000Z","dependencies_parsed_at":"2023-08-10T07:56:44.245Z","dependency_job_id":"f27f1c3b-a33b-49f1-8f79-2056fec0c946","html_url":"https://github.com/tidbcloud/serverless-js","commit_stats":{"total_commits":53,"total_committers":7,"mean_commits":7.571428571428571,"dds":0.2264150943396226,"last_synced_commit":"529da9369b71da4394e7a6d0c29c01fe20ef9bf3"},"previous_names":["tidbcloud/serverless-js"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fserverless-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fserverless-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fserverless-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fserverless-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidbcloud","download_url":"https://codeload.github.com/tidbcloud/serverless-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"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":["bun","cloudflare-workers","deno","edge-computing","javascript","mysql","netlify","serverless","tidb","typescript","vercel"],"created_at":"2024-10-02T06:05:46.487Z","updated_at":"2025-04-07T15:06:42.670Z","avatar_url":"https://github.com/tidbcloud.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TiDB Cloud Serverless Driver for JavaScript\n\nThis driver is for serverless and edge compute platforms that require HTTP external connections, such as Vercel Edge Functions or Cloudflare Workers.\n\n## Usage\n\n**Install**\n\nYou can install the driver with npm:\n\n```bash\nnpm install @tidbcloud/serverless\n```\n\n**Query**\n\nTo query from TiDB Serverless, you need to create a connection first. Then you can use the connection to execute raw SQL queries. For example:\n\n```ts\nimport { connect } from '@tidbcloud/serverless'\n\nconst conn = connect({url: 'mysql://username:password@host/database'})\nconst results = await conn.execute('select * from test where id = ?',[1])\n```\n\n**Transaction (Experimental)**\n\nYou can also perform interactive transactions with the serverless driver. For example:\n\n```ts\nimport { connect } from '@tidbcloud/serverless'\n\nconst conn = connect({url: 'mysql://username:password@host/database'})\nconst tx = await conn.begin()\n\ntry {\n  await tx.execute('insert into test values (1)')\n  await tx.execute('select * from test')\n  await tx.commit()\n}catch (err) {\n  await tx.rollback()\n  throw err\n}\n```\n\n\u003e **Note:**\n\u003e \n\u003e The transaction is not concurrent-safe. You are not allowed to run SQLs parallel in the same transaction.\n\n**Edge example**\n\nThe serverless driver is suitable for the edge environments. See how to use it with Vercel Edge Functions:\n\n```\nimport { NextResponse } from 'next/server';\nimport type { NextRequest } from 'next/server';\nimport { connect } from '@tidbcloud/serverless'\nexport const runtime = 'edge'\n\nexport async function GET(request: NextRequest) {\n  const conn = connect({url: process.env.DATABASE_URL})\n  const result = await conn.execute('show tables')\n  return NextResponse.json({result});\n}\n```\n\nSee [TiDB Cloud Serverless Driver](https://docs.pingcap.com/tidbcloud/serverless-driver#edge-examples) documentation to learn more.\n\n## Configuration\n\nSee [Configure TiDB Cloud Serverless Driver](https://docs.pingcap.com/tidbcloud/serverless-driver-config).\n\n## License\n\nApache 2.0, see [LICENSE](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fserverless-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidbcloud%2Fserverless-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fserverless-js/lists"}