prisma-extension-kysely 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,9 @@
9
9
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
10
10
  [![GitHub license](https://img.shields.io/github/license/eoin-obrien/prisma-extension-kysely.svg)](https://github.com/eoin-obrien/prisma-extension-kysely/blob/main/LICENSE)
11
11
 
12
+ > [!IMPORTANT]
13
+ > **v4.0 now requires Prisma 7.** Prisma 7 makes driver adapters a required part of `PrismaClient` — see the [Prisma 7 upgrade guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/v7) to migrate your project. If you are on Prisma 5 or 6, continue using `prisma-extension-kysely` v3.
14
+
12
15
  Writing 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.
13
16
 
14
17
  And the best part? You can use all of your favorite [`kysely`](https://kysely.dev/) plugins with `prisma-extension-kysely` too!
@@ -30,10 +33,10 @@ You don't have to take our word for it, though:
30
33
 
31
34
  ## Compatibility
32
35
 
33
- | prisma-extension-kysely | Prisma | Kysely |
34
- |-------------------------|----------------|-----------------|
35
- | v3.x | ^5.0 \| ^6.0 | ^0.27 \| ^0.28 |
36
- | v4.x *(coming soon)* | ^7.0 | ^0.28 |
36
+ | prisma-extension-kysely | Prisma | Kysely |
37
+ | ----------------------- | ------------ | -------------- |
38
+ | v3.x | ^5.0 \| ^6.0 | ^0.27 \| ^0.28 |
39
+ | v4.x | ^7.0 | ^0.27 \| ^0.28 |
37
40
 
38
41
  ## Get started
39
42
 
@@ -43,6 +46,12 @@ Install the dependencies:
43
46
  npm install prisma-extension-kysely kysely
44
47
  ```
45
48
 
49
+ Install the driver adapter for your database. For example, for PostgreSQL:
50
+
51
+ ```shell
52
+ npm install @prisma/adapter-pg pg
53
+ ```
54
+
46
55
  Set up the excellent [`prisma-kysely`](https://www.npmjs.com/package/prisma-kysely) library to automatically generate types for your database:
47
56
 
48
57
  ```shell
@@ -66,10 +75,21 @@ npx prisma generate
66
75
  Extend your Prisma Client:
67
76
 
68
77
  ```typescript
78
+ import { PrismaPg } from "@prisma/adapter-pg";
79
+ import {
80
+ Kysely,
81
+ PostgresAdapter,
82
+ PostgresIntrospector,
83
+ PostgresQueryCompiler,
84
+ } from "kysely";
69
85
  import kyselyExtension from "prisma-extension-kysely";
70
- import type { DB } from "./prisma/generated/types";
86
+ import type { DB } from "./generated/kysely/types"; // Your path may vary depending on your setup in schema.prisma
87
+
88
+ const adapter = new PrismaPg({
89
+ connectionString: process.env.DATABASE_URL,
90
+ });
71
91
 
72
- const prisma = new PrismaClient().$extends(
92
+ const prisma = new PrismaClient({ adapter }).$extends(
73
93
  kyselyExtension({
74
94
  kysely: (driver) =>
75
95
  new Kysely<DB>({
@@ -138,7 +158,11 @@ await prisma.$kysely.transaction().execute(async (trx) => {});
138
158
  Do you love Kysely's plugins? So do we! You can use them with `prisma-extension-kysely` as well:
139
159
 
140
160
  ```typescript
141
- const prisma = new PrismaClient().$extends(
161
+ const adapter = new PrismaPg({
162
+ connectionString: process.env.DATABASE_URL,
163
+ });
164
+
165
+ const prisma = new PrismaClient({ adapter }).$extends(
142
166
  kyselyExtension({
143
167
  kysely: (driver) =>
144
168
  new Kysely<DB>({
@@ -178,22 +202,28 @@ const kyselyExtensionArgs: PrismaKyselyExtensionArgs<DB> = {
178
202
  kysely: (driver) =>
179
203
  new Kysely<DB>({
180
204
  dialect: {
181
- createAdapter: () => new SqliteAdapter(),
205
+ createAdapter: () => new PostgresAdapter(),
182
206
  createDriver: () => driver,
183
- createIntrospector: (db) => new SqliteIntrospector(db),
184
- createQueryCompiler: () => new SqliteQueryCompiler(),
207
+ createIntrospector: (db) => new PostgresIntrospector(db),
208
+ createQueryCompiler: () => new PostgresQueryCompiler(),
185
209
  },
186
210
  }),
187
211
  };
188
212
 
189
- // Initialize the replica client(s) and add the Kysely extension
190
- const replicaClient = new PrismaClient({
191
- datasourceUrl: "YOUR_REPLICA_URL", // Replace this with your replica's URL!
192
- log: [{ level: "query", emit: "event" }],
193
- }).$extends(kyselyExtension(kyselyExtensionArgs));
213
+ // Initialize the replica client(s) with its own adapter and add the Kysely extension
214
+ const replicaAdapter = new PrismaPg({
215
+ connectionString: process.env.REPLICA_DATABASE_URL,
216
+ });
217
+ const replicaClient = new PrismaClient({ adapter: replicaAdapter }).$extends(
218
+ kyselyExtension(kyselyExtensionArgs),
219
+ );
194
220
 
195
- // Initialize the primary client and add the Kysely extension and the read replicas extension
196
- const prisma = new PrismaClient()
221
+ // Initialize the primary client with its own adapter, then add the Kysely
222
+ // extension and the read replicas extension
223
+ const primaryAdapter = new PrismaPg({
224
+ connectionString: process.env.DATABASE_URL,
225
+ });
226
+ const prisma = new PrismaClient({ adapter: primaryAdapter })
197
227
  .$extends(kyselyExtension(kyselyExtensionArgs)) // Apply the Kysely extension before the read replicas extension!
198
228
  .$extends(
199
229
  readReplicas({
@@ -203,19 +233,12 @@ const prisma = new PrismaClient()
203
233
  ```
204
234
 
205
235
  See how we're setting up the replica client as a fully-fledged Prisma client and extending it separately? That's the secret sauce!
206
- It make sure that the replica client has a separate Kysely instance. If you try to use bare URLs, you'll run into trouble;
236
+ It makes sure that the replica client has a separate Kysely instance. If you try to use bare URLs, you'll run into trouble;
207
237
  it'll share the same Kysely instance as the primary client, and you'll get unpleasant surprises!
208
238
 
209
- ```typescript
210
- // Don't do this! It won't work as expected.
211
- readReplicas({
212
- url: "postgresql://user:password@localhost:5432/dbname",
213
- });
214
- ```
215
-
216
239
  Also, 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.
217
240
 
218
- Check out the [read replicas example](examples/read-replicas/) for a runnable example!
241
+ Check out the [read replicas example](examples/read-replica/) for a runnable example!
219
242
 
220
243
  ## Examples
221
244
 
@@ -224,14 +247,14 @@ Check out the [examples](examples) directory for a sample project!
224
247
  ```shell
225
248
  cd examples/basic
226
249
  npm install
227
- npx prisma db push
228
- npm run dev
250
+ npm start
229
251
  ```
230
252
 
231
253
  ## Learn more
232
254
 
233
255
  - [Kysely](https://kysely.dev/)
234
256
  - [`prisma-kysely`](https://www.npmjs.com/package/prisma-kysely)
257
+ - [Prisma 7 upgrade guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/v7)
235
258
 
236
259
  ## License
237
260
 
@@ -16,11 +16,11 @@ export declare class PrismaKyselyExtensionError extends Error {
16
16
  * Define a Prisma extension that adds Kysely query builder methods to the Prisma client
17
17
  * @param extensionArgs The extension configuration object
18
18
  */
19
- declare const _default: <Database>(extensionArgs: PrismaKyselyExtensionArgs<Database>) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library.js").InternalArgs<{}, {}, {}, {
19
+ declare const _default: <Database>(extensionArgs: PrismaKyselyExtensionArgs<Database>) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client.js").InternalArgs<{}, {}, {}, {
20
20
  /**
21
21
  * The Kysely instance used by the Prisma client
22
22
  */
23
23
  $kysely: Kysely<Database>;
24
- }> & import("@prisma/client/runtime/library.js").DefaultArgs>;
24
+ }> & import("@prisma/client/runtime/client.js").DefaultArgs>;
25
25
  export default _default;
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-extension-kysely",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "author": {
5
5
  "name": "Eoin O'Brien",
6
6
  "url": "https://eoin.ai",
@@ -31,13 +31,15 @@
31
31
  ],
32
32
  "type": "commonjs",
33
33
  "files": [
34
- "dist"
34
+ "dist",
35
+ "!**/*.tsbuildinfo"
35
36
  ],
36
37
  "scripts": {
37
- "pretest": "prisma db push",
38
- "test": "jest",
39
- "test:watch": "npm run test -- --watch",
40
- "test:coverage": "npm run test -- --coverage",
38
+ "pretest": "prisma db push && prisma generate",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "pretest:coverage": "prisma db push && prisma generate",
42
+ "test:coverage": "vitest run --coverage",
41
43
  "build:clean": "rm -rf ./dist",
42
44
  "build:compile": "tsc -b tsconfig.json tsconfig.cjs.json && tsconfig-to-dual-package",
43
45
  "build": "npm run build:clean && npm run build:compile",
@@ -53,7 +55,7 @@
53
55
  }
54
56
  },
55
57
  "peerDependencies": {
56
- "@prisma/client": "^5.0.0 || ^6.0.0",
58
+ "@prisma/client": "^7.0.0",
57
59
  "kysely": "^0.27.0 || ^0.28.0"
58
60
  },
59
61
  "devDependencies": {
@@ -61,22 +63,22 @@
61
63
  "@commitlint/cli": "^20.0.0",
62
64
  "@commitlint/config-conventional": "^20.0.0",
63
65
  "@commitlint/cz-commitlint": "^20.0.0",
64
- "@prisma/client": "^6.0.0",
65
- "@prisma/extension-read-replicas": "^0.4.0",
66
+ "@prisma/adapter-better-sqlite3": "^7.4.1",
67
+ "@prisma/client": "^7.0.0",
68
+ "@prisma/extension-read-replicas": "^0.5.0",
66
69
  "@semantic-release/changelog": "^6.0.0",
67
70
  "@semantic-release/git": "^10.0.0",
68
- "@types/jest": "^30.0.0",
71
+ "@vitest/coverage-v8": "^3.0.0",
69
72
  "commitizen": "^4.3.0",
73
+ "dotenv": "^17.3.1",
70
74
  "husky": "^9.0.0",
71
75
  "inquirer": "^9.0.0",
72
- "jest": "^30.0.0",
73
- "jest-mock-extended": "^4.0.0",
74
76
  "kysely": "^0.28.0",
75
- "prisma": "^6.0.0",
76
- "prisma-kysely": "^2.0.0",
77
+ "prisma": "^7.0.0",
78
+ "prisma-kysely": "^3.0.0",
77
79
  "semantic-release": "^25.0.3",
78
- "ts-jest": "^29.4.0",
79
80
  "tsconfig-to-dual-package": "^1.2.0",
80
- "typescript": "^5.0.0"
81
+ "typescript": "^5.0.0",
82
+ "vitest": "^3.0.0"
81
83
  }
82
84
  }
@@ -16,11 +16,11 @@ export declare class PrismaKyselyExtensionError extends Error {
16
16
  * Define a Prisma extension that adds Kysely query builder methods to the Prisma client
17
17
  * @param extensionArgs The extension configuration object
18
18
  */
19
- declare const _default: <Database>(extensionArgs: PrismaKyselyExtensionArgs<Database>) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/library.js").InternalArgs<{}, {}, {}, {
19
+ declare const _default: <Database>(extensionArgs: PrismaKyselyExtensionArgs<Database>) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client.js").InternalArgs<{}, {}, {}, {
20
20
  /**
21
21
  * The Kysely instance used by the Prisma client
22
22
  */
23
23
  $kysely: Kysely<Database>;
24
- }> & import("@prisma/client/runtime/library.js").DefaultArgs>;
24
+ }> & import("@prisma/client/runtime/client.js").DefaultArgs>;
25
25
  export default _default;
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-extension-kysely",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "author": {
5
5
  "name": "Eoin O'Brien",
6
6
  "url": "https://eoin.ai",
@@ -31,13 +31,15 @@
31
31
  ],
32
32
  "type": "module",
33
33
  "files": [
34
- "dist"
34
+ "dist",
35
+ "!**/*.tsbuildinfo"
35
36
  ],
36
37
  "scripts": {
37
- "pretest": "prisma db push",
38
- "test": "jest",
39
- "test:watch": "npm run test -- --watch",
40
- "test:coverage": "npm run test -- --coverage",
38
+ "pretest": "prisma db push && prisma generate",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "pretest:coverage": "prisma db push && prisma generate",
42
+ "test:coverage": "vitest run --coverage",
41
43
  "build:clean": "rm -rf ./dist",
42
44
  "build:compile": "tsc -b tsconfig.json tsconfig.cjs.json && tsconfig-to-dual-package",
43
45
  "build": "npm run build:clean && npm run build:compile",
@@ -53,7 +55,7 @@
53
55
  }
54
56
  },
55
57
  "peerDependencies": {
56
- "@prisma/client": "^5.0.0 || ^6.0.0",
58
+ "@prisma/client": "^7.0.0",
57
59
  "kysely": "^0.27.0 || ^0.28.0"
58
60
  },
59
61
  "devDependencies": {
@@ -61,22 +63,22 @@
61
63
  "@commitlint/cli": "^20.0.0",
62
64
  "@commitlint/config-conventional": "^20.0.0",
63
65
  "@commitlint/cz-commitlint": "^20.0.0",
64
- "@prisma/client": "^6.0.0",
65
- "@prisma/extension-read-replicas": "^0.4.0",
66
+ "@prisma/adapter-better-sqlite3": "^7.4.1",
67
+ "@prisma/client": "^7.0.0",
68
+ "@prisma/extension-read-replicas": "^0.5.0",
66
69
  "@semantic-release/changelog": "^6.0.0",
67
70
  "@semantic-release/git": "^10.0.0",
68
- "@types/jest": "^30.0.0",
71
+ "@vitest/coverage-v8": "^3.0.0",
69
72
  "commitizen": "^4.3.0",
73
+ "dotenv": "^17.3.1",
70
74
  "husky": "^9.0.0",
71
75
  "inquirer": "^9.0.0",
72
- "jest": "^30.0.0",
73
- "jest-mock-extended": "^4.0.0",
74
76
  "kysely": "^0.28.0",
75
- "prisma": "^6.0.0",
76
- "prisma-kysely": "^2.0.0",
77
+ "prisma": "^7.0.0",
78
+ "prisma-kysely": "^3.0.0",
77
79
  "semantic-release": "^25.0.3",
78
- "ts-jest": "^29.4.0",
79
80
  "tsconfig-to-dual-package": "^1.2.0",
80
- "typescript": "^5.0.0"
81
+ "typescript": "^5.0.0",
82
+ "vitest": "^3.0.0"
81
83
  }
82
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-extension-kysely",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "author": {
5
5
  "name": "Eoin O'Brien",
6
6
  "url": "https://eoin.ai",
@@ -48,13 +48,15 @@
48
48
  "./package.json": "./package.json"
49
49
  },
50
50
  "files": [
51
- "dist"
51
+ "dist",
52
+ "!**/*.tsbuildinfo"
52
53
  ],
53
54
  "scripts": {
54
- "pretest": "prisma db push",
55
- "test": "jest",
56
- "test:watch": "npm run test -- --watch",
57
- "test:coverage": "npm run test -- --coverage",
55
+ "pretest": "prisma db push && prisma generate",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest",
58
+ "pretest:coverage": "prisma db push && prisma generate",
59
+ "test:coverage": "vitest run --coverage",
58
60
  "build:clean": "rm -rf ./dist",
59
61
  "build:compile": "tsc -b tsconfig.json tsconfig.cjs.json && tsconfig-to-dual-package",
60
62
  "build": "npm run build:clean && npm run build:compile",
@@ -70,7 +72,7 @@
70
72
  }
71
73
  },
72
74
  "peerDependencies": {
73
- "@prisma/client": "^5.0.0 || ^6.0.0",
75
+ "@prisma/client": "^7.0.0",
74
76
  "kysely": "^0.27.0 || ^0.28.0"
75
77
  },
76
78
  "devDependencies": {
@@ -78,22 +80,22 @@
78
80
  "@commitlint/cli": "^20.0.0",
79
81
  "@commitlint/config-conventional": "^20.0.0",
80
82
  "@commitlint/cz-commitlint": "^20.0.0",
81
- "@prisma/client": "^6.0.0",
82
- "@prisma/extension-read-replicas": "^0.4.0",
83
+ "@prisma/adapter-better-sqlite3": "^7.4.1",
84
+ "@prisma/client": "^7.0.0",
85
+ "@prisma/extension-read-replicas": "^0.5.0",
83
86
  "@semantic-release/changelog": "^6.0.0",
84
87
  "@semantic-release/git": "^10.0.0",
85
- "@types/jest": "^30.0.0",
88
+ "@vitest/coverage-v8": "^3.0.0",
86
89
  "commitizen": "^4.3.0",
90
+ "dotenv": "^17.3.1",
87
91
  "husky": "^9.0.0",
88
92
  "inquirer": "^9.0.0",
89
- "jest": "^30.0.0",
90
- "jest-mock-extended": "^4.0.0",
91
93
  "kysely": "^0.28.0",
92
- "prisma": "^6.0.0",
93
- "prisma-kysely": "^2.0.0",
94
+ "prisma": "^7.0.0",
95
+ "prisma-kysely": "^3.0.0",
94
96
  "semantic-release": "^25.0.3",
95
- "ts-jest": "^29.4.0",
96
97
  "tsconfig-to-dual-package": "^1.2.0",
97
- "typescript": "^5.0.0"
98
+ "typescript": "^5.0.0",
99
+ "vitest": "^3.0.0"
98
100
  }
99
101
  }
@@ -1 +0,0 @@
1
- {"root":["../../src/connection.ts","../../src/driver.ts","../../src/index.ts"],"version":"5.9.3"}
@@ -1 +0,0 @@
1
- {"root":["../../src/connection.ts","../../src/driver.ts","../../src/index.ts"],"version":"5.9.3"}