{"_id":"@daranzhao/prisma-extension-kysely","_rev":"2-0c93b3f30436197070df7bfccd278c1e","name":"@daranzhao/prisma-extension-kysely","dist-tags":{"latest":"1.1.1"},"versions":{"1.1.0":{"name":"@daranzhao/prisma-extension-kysely","version":"1.1.0","keywords":["prisma","@prisma/client","extension","kysely","sql","query builder","orm","database","postgresql","mysql","sqlite"],"license":"MIT","_id":"@daranzhao/prisma-extension-kysely@1.1.0","maintainers":[{"name":"daranzhao","email":"daran.zhao@gmail.com"}],"homepage":"https://github.com/daranzhao/prisma-extension-kysely/blob/main/README.md","bugs":{"url":"https://github.com/daranzhao/prisma-extension-kysely/issues"},"dist":{"shasum":"35ee336c6ce0a6228123221d46e299a34f8c8e19","tarball":"https://registry.npmjs.org/@daranzhao/prisma-extension-kysely/-/prisma-extension-kysely-1.1.0.tgz","fileCount":12,"integrity":"sha512-E+ujYM1SzGcMx94fV/cXDcLLzVaUybMO8czDV2bDHEHlbFyelhGymq7W3i6LLQOwNnMSGisZdf4Sc/wkhASPrA==","signatures":[{"sig":"MEQCIGlT24ebeUnOG8PLYH5S489Bl0nuXlmOp4FgRgL2TU+tAiAh/isIqfJdoOyPJKTpPjCpHx/qvaMcETxzciGQnjL8gg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25103},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","config":{"commitizen":{"path":"@commitlint/cz-commitlint"}},"module":"./dist/index.js","authors":[{"url":"https://eoin.ai","name":"Eoin O'Brien","email":"eoin@tracworx.ai"},{"url":"https://github.com/johannsonic","name":"Johann Boch"},{"url":"https://github.com/daranzhao","name":"Daran Zhao"}],"exports":{".":"./dist/index.js","./*":"./dist/*"},"gitHead":"3008b90dfa91767cf96e2d737746414961bd7616","scripts":{"lint":"eslint .","test":"jest","build":"npm run build:clean && npm run build:compile","commit":"git-cz","format":"prettier --write .","prepack":"npm run build","prepare":"npm run build","pretest":"prisma db push","lint:fix":"eslint --fix .","test:watch":"npm run test -- --watch","build:clean":"rm -rf ./dist","format:check":"prettier --check .","build:compile":"tsc","test:coverage":"npm run test -- --coverage"},"_npmUser":{"name":"daranzhao","email":"daran.zhao@gmail.com"},"repository":{"url":"git+https://github.com/daranzhao/prisma-extension-kysely.git","type":"git"},"_npmVersion":"10.9.2","description":"Prisma extension for Kysely","directories":{},"_nodeVersion":"22.13.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.0.0","husky":"^9.0.0","eslint":"^9.0.0","prisma":"latest","ts-jest":"^29.1.1","inquirer":"^8.2.6","prettier":"3.6.2","commitizen":"^4.3.0","typescript":"^5.0.0","@types/jest":"^30.0.0","prisma-kysely":"^1.7.1","@prisma/client":"latest","@commitlint/cli":"^18.4.3","jest-mock-extended":"^4.0.0","eslint-config-prettier":"^10.0.0","@commitlint/cz-commitlint":"^18.4.3","@typescript-eslint/parser":"^8.0.0","@commitlint/config-conventional":"^18.4.3","@prisma/extension-read-replicas":"^0.4.0","@typescript-eslint/eslint-plugin":"^8.0.0","eslint-plugin-require-extensions":"^0.1.3"},"peerDependencies":{"kysely":"^0.27.0","@prisma/client":"latest"},"_npmOperationalInternal":{"tmp":"tmp/prisma-extension-kysely_1.1.0_1760424913227_0.1370405574619571","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@daranzhao/prisma-extension-kysely","version":"1.1.1","authors":[{"name":"Eoin O'Brien","url":"https://eoin.ai","email":"eoin@tracworx.ai"},{"name":"Johann Boch","url":"https://github.com/johannsonic"},{"name":"Daran Zhao","url":"https://github.com/daranzhao"}],"description":"Prisma extension for Kysely","license":"MIT","homepage":"https://github.com/daranzhao/prisma-extension-kysely/blob/main/README.md","repository":{"type":"git","url":"git+https://github.com/daranzhao/prisma-extension-kysely.git"},"keywords":["prisma","@prisma/client","extension","kysely","sql","query builder","orm","database","postgresql","mysql","sqlite"],"type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":"./dist/index.js","./*":"./dist/*"},"scripts":{"pretest":"prisma db push","test":"jest","test:watch":"npm run test -- --watch","test:coverage":"npm run test -- --coverage","build:clean":"rm -rf ./dist","build:compile":"tsc","build":"npm run build:clean && npm run build:compile","prepack":"npm run build","prepare":"npm run build","commit":"git-cz","lint":"eslint .","lint:fix":"eslint --fix .","format":"prettier --write .","format:check":"prettier --check ."},"config":{"commitizen":{"path":"@commitlint/cz-commitlint"}},"peerDependencies":{"@prisma/client":"latest","kysely":"^0.27.0"},"devDependencies":{"@commitlint/cli":"^18.4.3","@commitlint/config-conventional":"^18.4.3","@commitlint/cz-commitlint":"^18.4.3","@prisma/client":"latest","@prisma/extension-read-replicas":"^0.4.0","@types/jest":"^30.0.0","@typescript-eslint/eslint-plugin":"^8.0.0","@typescript-eslint/parser":"^8.0.0","commitizen":"^4.3.0","eslint":"^9.0.0","eslint-config-prettier":"^10.0.0","eslint-plugin-require-extensions":"^0.1.3","husky":"^9.0.0","inquirer":"^8.2.6","jest":"^30.0.0","jest-mock-extended":"^4.0.0","prettier":"3.6.2","prisma":"latest","prisma-kysely":"^1.7.1","ts-jest":"^29.1.1","typescript":"^5.0.0"},"_id":"@daranzhao/prisma-extension-kysely@1.1.1","gitHead":"597f4c2deffc566e073952d486292d52399d1943","bugs":{"url":"https://github.com/daranzhao/prisma-extension-kysely/issues"},"_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-0q0WQEWqkjnpynbZizOgyk8SRj43or/Acp9y5fqk1vy4ykFlxU0f2k3SlcpBcAYjPfost2oe/zUKRzeTYroNBQ==","shasum":"0aca207b6b68b34d14ca760f0dded718ff79a532","tarball":"https://registry.npmjs.org/@daranzhao/prisma-extension-kysely/-/prisma-extension-kysely-1.1.1.tgz","fileCount":12,"unpackedSize":24105,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDhdP3ne/AVcOHv6ph/k8/PhrqY8MltLnvSWNFf/MtQwQIgSWw7ZTRImviaYmRjuOImIJ8CTIDpuEKrKC0OMN+wvaU="}]},"_npmUser":{"name":"daranzhao","email":"daran.zhao@gmail.com"},"directories":{},"maintainers":[{"name":"daranzhao","email":"daran.zhao@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prisma-extension-kysely_1.1.1_1760425531848_0.7727444086819188"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-14T06:55:13.128Z","modified":"2025-10-14T07:05:32.257Z","1.1.0":"2025-10-14T06:55:13.444Z","1.1.1":"2025-10-14T07:05:32.066Z"},"bugs":{"url":"https://github.com/daranzhao/prisma-extension-kysely/issues"},"license":"MIT","homepage":"https://github.com/daranzhao/prisma-extension-kysely/blob/main/README.md","keywords":["prisma","@prisma/client","extension","kysely","sql","query builder","orm","database","postgresql","mysql","sqlite"],"repository":{"type":"git","url":"git+https://github.com/daranzhao/prisma-extension-kysely.git"},"description":"Prisma extension for Kysely","maintainers":[{"name":"daranzhao","email":"daran.zhao@gmail.com"}],"readme":"# Prisma Kysely Extension\n\n[![GitHub license](https://img.shields.io/github/license/eoin-obrien/prisma-extension-kysely.svg)](https://www.npmjs.com/package/prisma-extension-kysely)\n\n## Note:\nThis is a forked version of the [prisma-extension-kysely](https://github.com/eoin-obrien/prisma-extension-kysely) package. It's been modified with this [suggestion](https://github.com/eoin-obrien/prisma-extension-kysely/pull/137) and slightly repackaged.\n\nTo use the modified extension, make sure you are chaining the kysely extension after the replica extension. For example:\n```\nclient\n  .$extends(\n    readReplicas({\n      replicas: replicaClients,\n    }),\n  )\n  .$extends(\n    kyselyExtension({\n      ...kyselyExtensionArguments,\n      config: { withReadReplica: true },\n    }),\n  )\n```\n\nOriginal README is reproduced below:\n\n---\n\nWriting and maintaining raw SQL queries for Prisma can be a tedious and error-prone task. The moment you need to write a query that is not supported out-of-the-box by Prisma, you lose all of that type-safety and autocompletion. This is where `prisma-extension-kysely` comes in! It allows you to easily write raw SQL queries in a type-safe manner with [`kysely`](https://kysely.dev/) and integrate them seamlessly with Prisma.\n\nAnd the best part? You can use all of your favorite [`kysely`](https://kysely.dev/) plugins with `prisma-extension-kysely` too!\n\nYou don't have to take our word for it, though:\n\n> I have to say, this is BY FAR the most amazing community package I've seen in the Prisma ecosystem!\n>\n> It makes it so much more convenient to drop down to raw SQL when needed without sacrificing DX — best of both worlds! 🚀\n\n— [Nikolas Burk, DevRel @ Prisma](https://twitter.com/nikolasburk/status/1747901827960471699)\n\n## Features\n\n- **Type-safe** — Write raw SQL queries in a type-safe manner with `kysely`\n- **Seamless integration** — Use `kysely` queries with Prisma as if they were native\n- **Autocompletion** — Get autocompletion for your queries in your IDE\n- **Type inference** — Get type inference for your queries in your IDE\n\n## Get started\n\nClick the **Use this template** button and provide details for your Client extension\n\nInstall the dependencies:\n\n```shell\nnpm install prisma-extension-kysely kysely\n```\n\nSet up the excellent [`prisma-kysely`](https://www.npmjs.com/package/prisma-kysely) library to automatically generate types for your database:\n\n```shell\nnpm install -D prisma-kysely\n```\n\nAdd `prisma-kysely` as a generator to your `schema.prisma`:\n\n```prisma\ngenerator kysely {\n  provider = \"prisma-kysely\"\n}\n```\n\nGenerate the types:\n\n```shell\nnpx prisma generate\n```\n\nExtend your Prisma Client:\n\n```typescript\nimport kyselyExtension from \"prisma-extension-kysely\";\nimport type { DB } from \"./prisma/generated/types\";\n\nconst prisma = new PrismaClient().$extends(\n  kyselyExtension({\n    kysely: (driver) =>\n      new Kysely<DB>({\n        dialect: {\n          // This is where the magic happens!\n          createDriver: () => driver,\n          // Don't forget to customize these to match your database!\n          createAdapter: () => new PostgresAdapter(),\n          createIntrospector: (db) => new PostgresIntrospector(db),\n          createQueryCompiler: () => new PostgresQueryCompiler(),\n        },\n        plugins: [\n          // Add your favorite plugins here!\n        ],\n      }),\n  }),\n);\n```\n\nIt's that simple! Now you can write raw SQL queries with `kysely` and use them with Prisma:\n\n```typescript\n// Replace this...\nconst result = prisma.$queryRaw`SELECT * FROM User WHERE id = ${id}`;\n\n// With this!\nconst query = prisma.$kysely\n  .selectFrom(\"User\")\n  .selectAll()\n  .where(\"id\", \"=\", id);\n\n// Thanks to kysely's magic, everything is type-safe!\nconst result = await query.execute();\n\n// You can also execute queries without fetching the results\nawait prisma.$kysely.deleteFrom(\"User\").where(\"id\", \"=\", id).execute();\n```\n\n## Transactions\n\nPrisma's interactive transactions are fully supported by `prisma-extension-kysely`! Just remeber to use `tx.$kysely` instead of `prisma.$kysely`, and you're good to go:\n\n```typescript\nawait prisma.$transaction(async (tx) => {\n  await tx.$kysely\n    .insertInto(\"User\")\n    .values({ id: 1, name: \"John Doe\" })\n    .execute();\n\n  await tx.$kysely\n    .insertInto(\"User\")\n    .values({ id: 2, name: \"Jane Doe\" })\n    .execute();\n});\n```\n\nDon't try to use Kysely's `transaction` method directly, though. It's not supported by `prisma-extension-kysely`, and it will throw an error if you try to use it.\n\n```typescript\n// Don't do this! Prefer prisma.$transaction instead.\nawait prisma.$kysely.transaction().execute(async (trx) => {});\n```\n\n## Plugins\n\nDo you love Kysely's plugins? So do we! You can use them with `prisma-extension-kysely` as well:\n\n```typescript\nconst prisma = new PrismaClient().$extends(\n  kyselyExtension({\n    kysely: (driver) =>\n      new Kysely<DB>({\n        dialect: {\n          createDriver: () => driver,\n          createAdapter: () => new PostgresAdapter(),\n          createIntrospector: (db) => new PostgresIntrospector(db),\n          createQueryCompiler: () => new PostgresQueryCompiler(),\n        },\n        // Use your favorite plugins!\n        plugins: [new CamelCasePlugin()],\n      }),\n  }),\n);\n```\n\nIf you're using the `CamelCasePlugin`, don't forget to add the `camelCase` option to your Prisma schema too:\n\n```prisma\ngenerator kysely {\n  provider = \"prisma-kysely\"\n  camelCase = true\n}\n```\n\nTake a look at [the camel case example](examples/camel-case/) to see it in action! Check out the [Kysely documentation](https://kysely.dev/) for more information about plugins.\n\n## Read Replicas\n\nUsing read replicas with `prisma-extension-kysely` is a breeze!\nJust use the excellent [`@prisma/extension-read-replicas`](https://www.npmjs.com/package/@prisma/extension-read-replicas) extension as normal.\nPay attention to how it's configured, though:\n\n```typescript\n// Use a common config for primary and replica clients (or different configs)\nconst kyselyExtensionArgs: PrismaKyselyExtensionArgs<DB> = {\n  kysely: (driver) =>\n    new Kysely<DB>({\n      dialect: {\n        createAdapter: () => new SqliteAdapter(),\n        createDriver: () => driver,\n        createIntrospector: (db) => new SqliteIntrospector(db),\n        createQueryCompiler: () => new SqliteQueryCompiler(),\n      },\n    }),\n};\n\n// Initialize the replica client(s) and add the Kysely extension\nconst replicaClient = new PrismaClient({\n  datasourceUrl: \"YOUR_REPLICA_URL\", // Replace this with your replica's URL!\n  log: [{ level: \"query\", emit: \"event\" }],\n}).$extends(kyselyExtension(kyselyExtensionArgs));\n\n// Initialize the primary client and add the Kysely extension and the read replicas extension\nconst prisma = new PrismaClient()\n  .$extends(kyselyExtension(kyselyExtensionArgs)) // Apply the Kysely extension before the read replicas extension!\n  .$extends(\n    readReplicas({\n      replicas: [replicaClient],\n    }),\n  ); // Apply the read replicas extension after the Kysely extension!\n```\n\nSee how we're setting up the replica client as a fully-fledged Prisma client and extending it separately? That's the secret sauce!\nIt make sure that the replica client has a separate Kysely instance. If you try to use bare URLs, you'll run into trouble;\nit'll share the same Kysely instance as the primary client, and you'll get unpleasant surprises!\n\n```typescript\n// Don't do this! It won't work as expected.\nreadReplicas({\n  url: \"postgresql://user:password@localhost:5432/dbname\",\n});\n```\n\nAlso, note that we're applying the Kysely extension before the read replicas extension. This is important! If you apply the read replicas extension first, you won't get `.$kysely` on the primary client.\n\nCheck out the [read replicas example](examples/read-replicas/) for a runnable example!\n\n## Examples\n\nCheck out the [examples](examples) directory for a sample project!\n\n```shell\ncd examples/basic\nnpm install\nnpx prisma db push\nnpm run dev\n```\n\n## Learn more\n\n- [Kysely](https://kysely.dev/)\n- [`prisma-kysely`](https://www.npmjs.com/package/prisma-kysely)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","readmeFilename":"README.md"}