{"id":25121357,"url":"https://github.com/aidenwallis/kysely-d1","last_synced_at":"2025-04-04T14:06:22.062Z","repository":{"id":61565369,"uuid":"552553465","full_name":"aidenwallis/kysely-d1","owner":"aidenwallis","description":"D1 dialect for Kysely","archived":false,"fork":false,"pushed_at":"2024-05-17T04:51:35.000Z","size":145,"stargazers_count":232,"open_issues_count":12,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T13:09:28.044Z","etag":null,"topics":["cloudflare","cloudflare-workers","d1","hacktoberfest","kysely","kysely-dialect","sqlite"],"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/aidenwallis.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":"2022-10-16T21:01:23.000Z","updated_at":"2025-03-26T13:53:10.000Z","dependencies_parsed_at":"2024-05-05T02:27:24.803Z","dependency_job_id":"43465ee4-02cc-4f60-a0e4-5b2d08550711","html_url":"https://github.com/aidenwallis/kysely-d1","commit_stats":{"total_commits":18,"total_committers":6,"mean_commits":3.0,"dds":0.5555555555555556,"last_synced_commit":"ba48112890fd91035fb51b93dc1301e9f8e4329d"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fkysely-d1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fkysely-d1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fkysely-d1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fkysely-d1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aidenwallis","download_url":"https://codeload.github.com/aidenwallis/kysely-d1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"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","cloudflare-workers","d1","hacktoberfest","kysely","kysely-dialect","sqlite"],"created_at":"2025-02-08T06:17:56.842Z","updated_at":"2025-04-04T14:06:22.042Z","avatar_url":"https://github.com/aidenwallis.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# kysely-d1\n\n[![ci](https://github.com/aidenwallis/kysely-d1/actions/workflows/ci.yaml/badge.svg)](https://github.com/aidenwallis/kysely-d1/actions/workflows/ci.yaml)\n[![npm](https://img.shields.io/npm/v/kysely-d1.svg)](https://www.npmjs.com/package/kysely-d1)\n\n[Kysely](https://github.com/koskimas/kysely) adapter for [Cloudflare D1](https://developers.cloudflare.com/d1/).\n\n```bash\nnpm i kysely-d1\n```\n\nThis project was largely adapted from [kysely-planetscale](https://github.com/depot/kysely-planetscale).\n\n## Usage\n\nPass your D1 binding into the dialect in order to configure the Kysely client. Follow [these docs](https://developers.cloudflare.com/d1/get-started/#4-bind-your-worker-to-your-d1-database) for instructions on how to do so.\n\n```typescript\nimport { Kysely } from 'kysely';\nimport { D1Dialect } from 'kysely-d1';\n\nexport interface Env {\n  DB: D1Database;\n}\n\ninterface KvTable {\n  key: string;\n  value: string;\n}\n\ninterface Database {\n  kv: KvTable;\n}\n\nexport default {\n  async fetch(request: Request, env: Env): Promise\u003cResponse\u003e {\n    const { searchParams } = new URL(request.url);\n    const key = searchParams.get('key');\n    if (!key) {\n      return new Response('No key defined.', { status: 400 });\n    }\n\n    // Create Kysely instance with kysely-d1\n    const db = new Kysely\u003cDatabase\u003e({ dialect: new D1Dialect({ database: env.DB }) });\n    \n    // Read row from D1 table\n    const result = await db.selectFrom('kv').selectAll().where('key', '=', key).executeTakeFirst();\n    if (!result) {\n      return new Response('No value found', { status: 404 });\n    }\n\n    return new Response(result.value);\n  },\n};\n```\n\nThere is a working [example](example) also included, which implements a K/V style store using D1.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faidenwallis%2Fkysely-d1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faidenwallis%2Fkysely-d1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faidenwallis%2Fkysely-d1/lists"}