{"_id":"@atinux/kysely-d1","name":"@atinux/kysely-d1","dist-tags":{"latest":"0.3.1"},"versions":{"0.3.1":{"name":"@atinux/kysely-d1","description":"Kysely dialect for Cloudflare D1","main":"./dist/index.cjs","module":"./dist/index.js","version":"0.3.1","types":"./dist/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/aidenwallis/kysely-d1.git"},"author":{"name":"Aiden","email":"aiden@aidenwallis.co.uk"},"license":"MIT","type":"module","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"keywords":["kysely","cloudflare","d1","workers","serverless"],"scripts":{"build":"tsc && tsc -p tsconfig.cjs.json && mv dist/cjs/index.js dist/index.cjs && rmdir dist/cjs","check":"prettier --check src/ example/","format":"prettier --write src/ example/"},"peerDependencies":{"kysely":"*"},"devDependencies":{"@cloudflare/workers-types":"^4.20241011.0","@tsconfig/node14":"^1.0.3","kysely":"^0.27.4","prettier":"^3.3.3","typescript":"^5.6.3"},"_id":"@atinux/kysely-d1@0.3.1","gitHead":"9028fb9a97322f722821aee9e891bcb3314321fd","bugs":{"url":"https://github.com/aidenwallis/kysely-d1/issues"},"homepage":"https://github.com/aidenwallis/kysely-d1#readme","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-QyPnZLPSb2qksGsORhYtODi3qPASzUfON6tgaCGhpfb71h6TPSd0v5msjdptCcwRMnWi+bxqHkTufJiaiDjzfw==","shasum":"b7ee49c6bc07d4a299368829c6fcc9e0dc8af219","tarball":"https://registry.npmjs.org/@atinux/kysely-d1/-/kysely-d1-0.3.1.tgz","fileCount":6,"unpackedSize":19030,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEgM/WjDsFDlmnNXigzA+CPU86Wi8sRN8f1+Q4M+p+PbAiAt8ev1ZpHdkhE4BPWDAQIeFh7oQ6PxJ11k7elo1DwbVA=="}]},"_npmUser":{"name":"atinux","email":"atinux@gmail.com"},"directories":{},"maintainers":[{"name":"atinux","email":"atinux@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kysely-d1_0.3.1_1729162565889_0.6251241516843251"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-17T10:56:05.771Z","0.3.1":"2024-10-17T10:56:06.047Z","modified":"2024-10-17T10:56:06.311Z"},"maintainers":[{"name":"atinux","email":"atinux@gmail.com"}],"description":"Kysely dialect for Cloudflare D1","homepage":"https://github.com/aidenwallis/kysely-d1#readme","keywords":["kysely","cloudflare","d1","workers","serverless"],"repository":{"type":"git","url":"git+ssh://git@github.com/aidenwallis/kysely-d1.git"},"author":{"name":"Aiden","email":"aiden@aidenwallis.co.uk"},"bugs":{"url":"https://github.com/aidenwallis/kysely-d1/issues"},"license":"MIT","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<Response> {\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<Database>({ 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","readmeFilename":"README.md"}