kysely-gen 0.9.0 → 0.10.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.
Files changed (3) hide show
  1. package/README.md +48 -0
  2. package/dist/cli.js +456 -813
  3. package/package.json +12 -5
package/README.md CHANGED
@@ -51,6 +51,54 @@ npx kysely-gen --dialect mysql --url mysql://user:pass@localhost:3306/db
51
51
  | `--camel-case` | Convert names to camelCase |
52
52
  | `--include-pattern <glob>` | Only include matching tables |
53
53
  | `--exclude-pattern <glob>` | Exclude matching tables |
54
+ | `--zod` | Generate Zod schemas instead of TypeScript interfaces |
55
+
56
+ ## Zod Schema Generation
57
+
58
+ Generate Zod validation schemas with inferred types instead of TypeScript interfaces. Requires Zod v4+:
59
+
60
+ ```sh
61
+ npm install zod@4
62
+ npx kysely-gen --zod
63
+ ```
64
+
65
+ This generates `db-schemas.ts` with Zod schemas and inferred types:
66
+
67
+ ```typescript
68
+ import { z } from 'zod';
69
+
70
+ export const userSchema = z.object({
71
+ id: z.number(),
72
+ email: z.string(),
73
+ name: z.string().nullable(),
74
+ createdAt: z.date(),
75
+ });
76
+
77
+ export const newUserSchema = z.object({
78
+ id: z.number().optional(),
79
+ email: z.string(),
80
+ name: z.string().nullable().optional(),
81
+ createdAt: z.union([z.date(), z.string()]).optional(),
82
+ });
83
+
84
+ export const userUpdateSchema = z.object({
85
+ id: z.number().optional(),
86
+ email: z.string().optional(),
87
+ name: z.string().nullable().optional(),
88
+ createdAt: z.union([z.date(), z.string()]).optional(),
89
+ });
90
+
91
+ export type User = z.infer<typeof userSchema>;
92
+ export type NewUser = z.infer<typeof newUserSchema>;
93
+ export type UserUpdate = z.infer<typeof userUpdateSchema>;
94
+ ```
95
+
96
+ Three schemas are generated per table:
97
+ - **Select schema** (`userSchema`): What you get from queries
98
+ - **Insert schema** (`newUserSchema`): For inserts - auto-increment/default columns are optional
99
+ - **Update schema** (`userUpdateSchema`): For updates - all columns are optional
100
+
101
+ The `--zod` flag replaces TypeScript interface generation. Types are inferred from schemas via `z.infer<>`, ensuring they never drift.
54
102
 
55
103
  ## Example
56
104