You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -237,23 +237,12 @@ Below are the options for the `prisma-client` generator:
237
237
238
238
:::
239
239
240
-
### Output splitting and importing types
240
+
### Importing Types
241
241
242
-
The `prisma-client-js` generator used to generate all typings into a single `index.d.ts` file, which could lead to [slowing down editors](https://github.com/prisma/prisma/issues/4807) (e.g. breaking auto-complete) with large schemas.
242
+
The new `prisma-client` generator creates individual `.ts` files which allow for a more fine granular import of types. This can improve compile and typecheck performance and be useful for tree-shacking, too.
243
+
You can still use the top level barrel files that export all types through a single import.
243
244
244
-
The new `prisma-client` generator now splits the generated Prisma Client library into multiple files and thus avoids the problems of a single, large output file.
245
-
246
-
**Before** (`prisma-client-js`)
247
-
248
-
```
249
-
generated/
250
-
└── prisma
251
-
├── client.ts
252
-
├── index.ts # -> this is split into multiple files in 6.7.0
253
-
└── libquery_engine-darwin.dylib.node
254
-
```
255
-
256
-
**After** (`prisma-client`)
245
+
The overall structure of the generated output looks like this:
257
246
258
247
```
259
248
generated/
@@ -263,15 +252,119 @@ generated/
263
252
├── commonInputTypes.ts
264
253
├── enums.ts
265
254
├── internal
266
-
│ ├── class.ts
267
-
│ ├── prismaNamespace.ts
268
-
│ └── prismaNamespaceBrowser.ts
255
+
│ ├── ...
269
256
├── models
270
257
│ ├── Post.ts
271
258
│ └── User.ts
272
259
└── models.ts
273
260
```
274
261
262
+
#### `client.ts`
263
+
264
+
For use in your server code.
265
+
266
+
- Provides access to the `PrismaClient` instance and all model and utility types.
267
+
- Provides best compatibility with the `prisma-client-js` generated output.
268
+
- Contains transitive dependencies on server only packages so cannot be used in browser contexts.
269
+
270
+
Example:
271
+
```
272
+
import { Prisma, type Post, PrismaClient } from `./generated/prisma/client`
273
+
```
274
+
275
+
#### `browser.ts`
276
+
277
+
For using types in your frontend aka browser code.
278
+
279
+
- Contains no transitive dependencies on node.js or other server only packages.
280
+
- Contains no real `PrismaClient`.
281
+
- Contains all model and enum types and values.
282
+
- Provides access to various utilities like `Prisma.JsonNull` and `Prisma.Decimal`.
283
+
284
+
:::note
285
+
286
+
The old `prisma-client-js` generator created a node_modules package and used export maps to dynamically provide a browser compatible export of the generated prisma client.
287
+
As the new `prisma-client` generator creates direct TypeScript source code and no package.json anymore, this approach is not possible.
288
+
Hence you need to be explicit about your imports and whether things run on server or client!
289
+
290
+
You can still wrap the generated code in a package and use a similar approach on your own.
291
+
292
+
:::
293
+
294
+
Example:
295
+
```
296
+
import { Prisma, type Post } from `./generated/prisma/browser`
297
+
```
298
+
299
+
#### `enums.ts`
300
+
301
+
Isolated access to user defined enum types and values.
302
+
303
+
- Contains no transitive dependencies and is very slim.
304
+
- Can be used on backend and frontend.
305
+
- Prefer this for optimal tree shacking and typecheck performance when accessing enums.
306
+
307
+
Example:
308
+
```
309
+
import { MyEnum } from `./generated/prisma/enums`
310
+
```
311
+
312
+
#### `models.ts`
313
+
314
+
Isolated access to all model types.
315
+
316
+
- Can be used on backend and frontend.
317
+
- Contains all models including their derived utility types like `<ModelName>WhereInput` or `<ModelName>UpdateInput>.
318
+
319
+
:::note
320
+
321
+
Plain model types are exposed here as `<ModelName>Model` (e.g. `PostModel`). This is in contrast to the exposed name in `client.ts` and `browser.ts` which is simply `<ModelName>` (e.g. `Post`).
322
+
323
+
This is necessary due to internal constraints to avoid potential naming conflicts with internal types.
324
+
325
+
:::
326
+
327
+
Example:
328
+
```
329
+
import type { UserModel, PostModel, PostWhereInput, UserUpdateInput } from `./generated/prisma/models`
330
+
```
331
+
332
+
333
+
#### `models/<ModelName>.ts
334
+
335
+
Isolated access to the types for an individual model.
336
+
337
+
- Can be used on backend and frontend.
338
+
- Contains the models including its derived utility types like `<ModelName>WhereInput` or `<ModelName>UpdateInput>.
339
+
340
+
:::note
341
+
342
+
The plain model type is exposed here as `<ModelName>Model` (e.g. `PostModel`).
343
+
344
+
:::
345
+
346
+
Example:
347
+
```
348
+
import type { UserModel, UserWhereInput, UserUpdateInput } from `./generated/prisma/models/User`
349
+
```
350
+
351
+
352
+
#### `commonInputTypes.ts`
353
+
354
+
Provides shared utility types that you should rarely directly need.
355
+
356
+
Example:
357
+
```
358
+
import type { IntFilter } from `./generated/prisma/commonInputTypes`
359
+
```
360
+
361
+
#### `internal/*`
362
+
363
+
:warning: Do not directly import from these files! They are not part of the stable API of the generated code and can change at any time in breaking ways.
364
+
365
+
Usually anything you might need from there is exposed via `browser.ts` or `client.ts` under the `Prisma` namespace.
366
+
367
+
275
368
### Breaking changes from `prisma-client-js`
276
369
277
370
- Requires an `output` path on the `generator` block
0 commit comments