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
Copy file name to clipboardExpand all lines: README.md
+14-15Lines changed: 14 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,28 +39,28 @@ without losing the safety of the TypeScript type system?
39
39
fileName = "types.ts"
40
40
// Optionally generate runtime enums to a separate file
41
41
enumFileName = "enums.ts"
42
-
// Optionally include a custom import section (single or multi-line)
43
-
additionalImports = "import Decimal from 'decimal.js';"
42
+
// Optionally add content at the start of generated files (imports, pragmas, comments, etc.)
43
+
filePrefix = "import type { Decimal } from 'decimal.js';"
44
44
// For multi-line, use Prisma's triple-quoted string syntax (see below)
45
45
}
46
46
```
47
47
48
48
3. Run `prisma migrate dev` or `prisma generate` and use your freshly generated
49
49
types when instantiating Kysely!
50
50
51
-
### Advanced Import Configuration
51
+
### File Prefix Configuration
52
52
53
-
The `additionalImports` option supports full import sections, allowing you to import multiple libraries with different syntaxes:
53
+
The `filePrefix` option allows you to add custom content at the start of generated files. This is particularly useful for importing custom types and libraries:
54
54
55
55
```prisma
56
56
generator kysely {
57
57
provider = "prisma-kysely"
58
58
output = "../src/db"
59
59
fileName = "types.ts"
60
60
61
-
// Import multiple libraries with different syntaxes
62
-
additionalImports = """
63
-
import Decimal from 'decimal.js';
61
+
// Add custom imports for libraries you need in generated types
62
+
filePrefix = """
63
+
import type { Decimal } from 'decimal.js';
64
64
import { Big } from 'big.js';
65
65
import * as moment from 'moment';
66
66
import { v4 as uuid } from 'uuid';
@@ -72,14 +72,13 @@ import type { SomeType } from './custom-types';
72
72
This will generate a file that starts with:
73
73
74
74
```typescript
75
-
import { Big } from"big.js";
76
-
importDecimalfrom"decimal.js";
77
-
importtype { ColumnType } from"kysely";
78
-
import*asmomentfrom"moment";
79
-
import { v4asuuid } from"uuid";
80
-
81
-
importtype { SomeType } from"./custom-types";
75
+
importtype { Decimal } from'decimal.js';
76
+
import { Big } from'big.js';
77
+
import*asmomentfrom'moment';
78
+
import { v4asuuid } from'uuid';
79
+
importtype { SomeType } from'./custom-types';
82
80
81
+
importtype { ColumnType } from"kysely";
83
82
// ... rest of generated types
84
83
```
85
84
@@ -119,7 +118,7 @@ hope it's just as useful for you! 😎
119
118
|`enumFileName`| The filename for the generated enums. Omitting this will generate enums and files in the same file. ||
120
119
|`camelCase`| Enable support for Kysely's camelCase plugin |`false`|
121
120
|`exportWrappedTypes`| Kysely wrapped types such as `Selectable<Model>` are also exported as described in the [Kysely documentation](https://kysely.dev/docs/getting-started#types). The exported types follow the naming conventions of the document. |`false`|
122
-
|`additionalImports`| A full import section to prepend to the generated file. Supports any TS import syntax (default, named, namespace, renamed, and `import type`). Single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim; no sorting or deduplication is performed. ||
121
+
|`filePrefix`| Content to prepend to the start of generated file(s). Useful for custom imports, pragma directives (e.g., `// @ts-nocheck`), comments, or any other content. Supports single-line strings or multi-line via Prisma triple-quoted strings (`""" ... """`). The content is inserted verbatim at the top of the file(s).||
123
122
|`readOnlyIds`| Use Kysely's `GeneratedAlways` for `@id` fields with default values, preventing insert and update. |`false`|
124
123
|`[typename]TypeOverride`| Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the [config validator](https://github.com/valtyr/prisma-kysely/blob/main/src/utils/validateConfig.ts) for a complete list of options. ||
125
124
|`dbTypeName`| Allows you to override the exported type with all tables |`DB`|
// Import any additional libraries. Set to the full import section you want (e.g., "import Decimal from 'decimal.js';", "import { Big } from 'big.js';", multiple imports separated by newlines, etc.)
61
-
additionalImports: z.string().optional(),
60
+
// Content to prepend to the start of the generated file(s). Useful for custom imports, pragmas, or comments.
0 commit comments