{"id":14979127,"url":"https://github.com/tidbcloud/kysely","last_synced_at":"2025-06-28T22:40:28.215Z","repository":{"id":194220083,"uuid":"690498878","full_name":"tidbcloud/kysely","owner":"tidbcloud","description":"Kysely dialect for TiDB Cloud, powered by TiDB Serverless driver","archived":false,"fork":false,"pushed_at":"2024-09-27T01:36:56.000Z","size":41,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-09-29T02:22:12.351Z","etag":null,"topics":["cloudflare-workers","edge-computing","kysely","netlify","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":"mit","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-09-12T10:08:14.000Z","updated_at":"2023-12-30T00:59:59.000Z","dependencies_parsed_at":"2023-09-12T11:15:41.010Z","dependency_job_id":"c4244eff-3dfc-4988-883e-ac2f7787ab58","html_url":"https://github.com/tidbcloud/kysely","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"d1f88fdad655afb21c9ca10d0c59dbba6d418de1"},"previous_names":["tidbcloud/kysely"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fkysely","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fkysely/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fkysely/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fkysely/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidbcloud","download_url":"https://codeload.github.com/tidbcloud/kysely/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859520,"owners_count":16556036,"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","kysely","netlify","serverless","tidb","tidbcloud","vercel"],"created_at":"2024-09-24T13:59:19.312Z","updated_at":"2024-10-11T18:42:27.540Z","avatar_url":"https://github.com/tidbcloud.png","language":"TypeScript","readme":"# kysely-tidbcloud\n\n[Kysely](https://github.com/koskimas/kysely) dialect for TiDB Cloud, using the [TiDB Cloud serverless driver](https://github.com/tidbcloud/serverless-js).\n\nIt is designed to be used on the edge, like Vercel Edge Functions, Cloudflare Workers, Netlify Edge Functions, etc.\n\n## Installation\n\nYou should also install kysely and @tidbcloud/serverless with @tidbcloud/kysely, as they are both required peer dependencies.\n\n```\nnpm install kysely @tidbcloud/kysely @tidbcloud/serverless\n```\n\n## Usage\n\n```\nimport { Kysely } from 'kysely'\nimport { TiDBServerlessDialect } from '@tidbcloud/kysely'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new TiDBServerlessDialect({\n    url: process.env.DATABASE_URL\n  }),\n})\n```\n\nDatabase is an interface including the database schema. See [Kysely documentation](https://kysely.dev/docs/getting-started#types) or the [full example below](#Example) for more details.\n\n## Example\n\n```ts\nimport { Kysely,GeneratedAlways,Selectable } from 'kysely'\nimport { TiDBServerlessDialect } from '@tidbcloud/kysely'\n\n// Types\ninterface Database {\n  person: PersonTable\n}\ninterface PersonTable {\n  id: GeneratedAlways\u003cnumber\u003e\n  name: string\n  gender: \"male\" | \"female\" | \"other\"\n}\n\n// Dialect\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new TiDBServerlessDialect({\n    url: process.env.DATABASE_URL\n  }),\n})\n\n// Simple Querying\ntype Person = Selectable\u003cPersonTable\u003e\nexport async function findPeople(criteria: Partial\u003cPerson\u003e) {\n  let query = db.selectFrom('person')\n\n  if (criteria.name){\n    query = query.where('name', '=', criteria.name)\n  }\n\n  return await query.selectAll().execute()\n}\n\n// Transaction\ntry{\n  await db.transaction().execute(async (trx) =\u003e {\n    await trx.insertInto('person')\n    .values({\n      name: 'test',\n      gender: 'male',\n    })\n    .executeTakeFirstOrThrow()\n\n    const person = await trx.selectFrom('person').where('name', '=', 'test').selectAll().execute()\n    console.log(person)\n    // verify the isolation of transaction\n    console.log(await findPeople({'name': 'test'}))\n    throw new Error(\"throw error to rollback\");\n  })\n}finally {\n  // verify the rollback of transaction\n  console.log(await findPeople({'name': 'test'}))\n}\n```\n\n## Configuration\n\nThe TiDB Cloud dialect accepts the same configurations as TiDB Cloud serverless driver. For example: You can customize the `fetch` in node.js:\n\n```ts\nimport { Kysely } from 'kysely'\nimport { TiDBServerlessDialect } from '@tidbcloud/kysely'\nimport { fetch } from 'undici'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new TiDBServerlessDialect({\n    url: process.env.DATABASE_URL,\n    fetch\n  }),\n})\n```\n\nSee [TiDB Cloud serverless driver configuration](https://github.com/tidbcloud/serverless-js#configuration) for the all configurations.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fkysely","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidbcloud%2Fkysely","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fkysely/lists"}