hekireki 0.10.1 → 0.20.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 (53) hide show
  1. package/README.md +179 -1131
  2. package/dist/bin/activerecord.js +1 -1
  3. package/dist/bin/ajv.js +1 -1
  4. package/dist/bin/arktype.js +1 -1
  5. package/dist/bin/atlas.js +1 -1
  6. package/dist/bin/django.js +6 -0
  7. package/dist/bin/drizzle.js +1 -1
  8. package/dist/bin/ecto.js +1 -1
  9. package/dist/bin/effect.js +1 -1
  10. package/dist/bin/eloquent.js +1 -1
  11. package/dist/bin/er.js +6 -0
  12. package/dist/bin/gorm.js +1 -1
  13. package/dist/bin/hekireki.js +176 -0
  14. package/dist/bin/kysely.js +1 -1
  15. package/dist/bin/pydantic.js +1 -1
  16. package/dist/bin/sea-orm.js +1 -1
  17. package/dist/bin/sqlalchemy.js +1 -1
  18. package/dist/bin/typebox.js +1 -1
  19. package/dist/bin/valibot.js +1 -1
  20. package/dist/bin/zod.js +1 -1
  21. package/dist/{bin-CR9GrJIk.js → bin-CPb5ZV8W.js} +2067 -1678
  22. package/dist/file-yN0By3gn.js +48 -0
  23. package/dist/schema-DwMNeEei.js +823 -0
  24. package/dist/start-Blp4k61D.js +5764 -0
  25. package/dist/studio/assets/cells-lAj-v64A.js +2 -0
  26. package/dist/studio/assets/codicon-Brq4_Ui5.ttf +0 -0
  27. package/dist/studio/assets/docs-CpeTt3O2.js +34 -0
  28. package/dist/studio/assets/editor.worker-D9zwrD0f.js +30 -0
  29. package/dist/studio/assets/enums._name-My5PypWw.js +1 -0
  30. package/dist/studio/assets/hooks-CiUANSpJ.js +1 -0
  31. package/dist/studio/assets/index-C4wWEcwe.js +188 -0
  32. package/dist/studio/assets/index-ZSt1ppSG.css +2 -0
  33. package/dist/studio/assets/labels-DBXIkmbm.js +1 -0
  34. package/dist/studio/assets/lazyRouteComponent-DmCXXiGp.js +1 -0
  35. package/dist/studio/assets/models._name-oUX64rwK.js +1 -0
  36. package/dist/studio/assets/not-found-DxAsuyR5.js +1 -0
  37. package/dist/studio/assets/prisma-Bk53qnxm.js +891 -0
  38. package/dist/studio/assets/prisma-C2rAM-pV.css +1 -0
  39. package/dist/studio/assets/routes-ZmrohHNP.js +1 -0
  40. package/dist/studio/assets/schema-gate-DJ_-6NYR.js +1 -0
  41. package/dist/studio/assets/schema-view-BaoCWAL8.js +8 -0
  42. package/dist/studio/assets/sql-DpzkSc6F.js +1 -0
  43. package/dist/studio/assets/useMatch-D73HO_WB.js +1 -0
  44. package/dist/studio/index.html +16 -0
  45. package/package.json +55 -25
  46. package/dist/bin/dbml.js +0 -6
  47. package/dist/bin/docs.js +0 -6
  48. package/dist/bin/mermaid-er.js +0 -6
  49. package/dist/cli/index.d.ts +0 -138
  50. package/dist/cli/index.js +0 -134
  51. /package/dist/bin/{dbml.d.ts → django.d.ts} +0 -0
  52. /package/dist/bin/{docs.d.ts → er.d.ts} +0 -0
  53. /package/dist/bin/{mermaid-er.d.ts → hekireki.d.ts} +0 -0
package/README.md CHANGED
@@ -2,39 +2,17 @@
2
2
 
3
3
  # Hekireki
4
4
 
5
- **[Hekireki](https://www.npmjs.com/package/hekireki)** is a tool that generates validation schemas, ORM models, and ER diagrams from [Prisma](https://www.prisma.io/) schemas — supporting TypeScript, Python, Go, Rust, Elixir, Ruby, and PHP.
5
+ **[Hekireki](https://www.npmjs.com/package/hekireki)** generates validation schemas, ORM models and
6
+ ER diagrams from a [Prisma](https://www.prisma.io/) schema — for TypeScript, Python, Go, Rust,
7
+ Elixir, Ruby and PHP — and opens the schema, its documentation and its data in the browser with
8
+ [Hekireki Studio](#studio).
6
9
 
7
10
  ## Features
8
11
 
9
- ### TypeScript Validation Libraries
10
-
11
- - 💎 Automatically generates [Zod](https://zod.dev/) schemas from your Prisma schema
12
- - 🤖 Automatically generates [Valibot](https://valibot.dev/) schemas from your Prisma schema
13
- - 🏹 Automatically generates [ArkType](https://arktype.io/) schemas from your Prisma schema
14
- - ⚡ Automatically generates [Effect Schema](https://effect.website/docs/schema/introduction/) from your Prisma schema
15
- - 📦 Automatically generates [TypeBox](https://github.com/sinclairzx81/typebox) schemas from your Prisma schema
16
- - 📋 Automatically generates [AJV](https://ajv.js.org/)-compatible JSON Schema objects from your Prisma schema
17
-
18
- ### Python Validation
19
-
20
- - 🐍 Automatically generates [Pydantic](https://docs.pydantic.dev/) v2 models from your Prisma schema — with `@p.` field annotations, `Literal` enums, `@p.ConfigDict(...)` model config passthrough (`extra='forbid'` / `'ignore'` / `'allow'` and any other `ConfigDict` arguments), and `relation = true` for `<Model>Relations` subclasses
21
-
22
- ### ORM / Schema Generation (Multi-Language)
23
-
24
- - 🗄️ Automatically generates [Drizzle ORM](https://orm.drizzle.team/) table schemas and relations from your Prisma schema
25
- - 🐟 Automatically generates [Kysely](https://kysely.dev/) type definitions (`DB` interface) from your Prisma schema — with database-side-only `Generated` columns, enum value unions, `@map`/`@@map` support, and implicit m2m join tables
26
- - 🐍 Automatically generates [SQLAlchemy](https://www.sqlalchemy.org/) models (Python) — with `Mapped[T]` type hints, relationships, enums, composite keys, and index support
27
- - 🐹 Automatically generates [GORM](https://gorm.io/) models (Go) — with struct tags, JSON tags, relationships, enums, composite keys, and index support
28
- - 🦀 Automatically generates [Sea-ORM](https://www.sea-ql.org/SeaORM/) entities (Rust) — with `DeriveEntityModel`, relations, enums, serde support, and `rename_all`
29
- - 🧪 Generates [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html) schemas (Elixir) — with associations (`belongs_to`, `has_many`, `has_one`), composite primary keys, `@type t` typespecs, array fields, `@@map`/`@map` support, and `@moduledoc`
30
- - 💎 Generates [Active Record](https://guides.rubyonrails.org/active_record_basics.html) models (Ruby on Rails) — with associations (`belongs_to`, `has_one`, `has_many`, `has_and_belongs_to_many`), enums, composite primary keys, and `@@map`/`@map` support
31
- - 🐘 Generates [Eloquent](https://laravel.com/docs/eloquent) models (Laravel / PHP) — with relations (`belongsTo`, `hasOne`, `hasMany`, `belongsToMany`), `$fillable`, `$casts`, string-backed PHP enums, timestamp constants, and `@@map`/`@map` support
32
- - 🌍 Generates [Atlas](https://atlasgo.io/) HCL database schemas — with native `@db.*` type mapping (PostgreSQL / MySQL / SQLite), enum blocks, defaults (including `dbgenerated(...)` and scalar-list defaults), foreign keys with Prisma's referential-action defaults, unique / descending / fulltext indexes, implicit m2m join tables, and `@@schema` support — output is `atlas schema fmt` canonical
33
-
34
- ### Diagrams & Documentation
35
-
36
- - 📊 Creates [Mermaid](https://mermaid.js.org/) ER diagrams with PK/FK markers
37
- - 📝 Generates [DBML](https://dbml.dbdiagram.io/) (Database Markup Language) files and **PNG** ER diagrams via [dbml-renderer](https://github.com/softwaretechnik-berlin/dbml-renderer) — output format is determined by the file extension (`.dbml` or `.png`)
12
+ - **Validation schemas** — [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), [Effect Schema](https://effect.website/docs/schema/introduction/), [TypeBox](https://github.com/sinclairzx81/typebox), [AJV](https://ajv.js.org/) (JSON Schema) and [Pydantic](https://docs.pydantic.dev/) v2, written from the `///` [annotations](#annotations) on each field
13
+ - **ORM models and DDL** — [Drizzle](https://orm.drizzle.team/), [Kysely](https://kysely.dev/), [SQLAlchemy](https://www.sqlalchemy.org/), [Django](https://www.djangoproject.com/), [GORM](https://gorm.io/), [Sea-ORM](https://www.sea-ql.org/SeaORM/), [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html), [Active Record](https://guides.rubyonrails.org/active_record_basics.html), [Eloquent](https://laravel.com/docs/eloquent) and [Atlas](https://atlasgo.io/) HCL — with relations, enums, composite keys, indexes and `@@map` / `@map` throughout
14
+ - **ER diagrams** — [Mermaid](https://mermaid.js.org/), [DBML](https://dbml.dbdiagram.io/), PNG and SVG from one generator block, with crow's-foot cardinality and `PK` / `FK` / `UK` markers
15
+ - **[Hekireki Studio](#studio)** — the ER diagram, a reference docs page, every model's data, a Prisma editor and a SQL console, live from `schema.prisma`
38
16
 
39
17
  ## Installation
40
18
 
@@ -44,7 +22,9 @@ npm install -D hekireki
44
22
 
45
23
  ## Usage
46
24
 
47
- Prepare `schema.prisma`:
25
+ Each generator is a `generator` block in `schema.prisma`. `output` is **required**: point it at a
26
+ directory to get the default file name of that generator, or at a path with an extension to name
27
+ the file yourself.
48
28
 
49
29
  ```prisma
50
30
  datasource db {
@@ -59,183 +39,31 @@ generator Hekireki-Zod {
59
39
  relation = true
60
40
  }
61
41
 
62
- generator Hekireki-Valibot {
63
- provider = "hekireki-valibot"
64
- output = "./valibot"
65
- type = true
66
- comment = true
67
- relation = true
68
- }
69
-
70
- generator Hekireki-ArkType {
71
- provider = "hekireki-arktype"
72
- output = "./arktype"
73
- type = true
74
- comment = true
75
- relation = true
76
- }
77
-
78
- generator Hekireki-Effect {
79
- provider = "hekireki-effect"
80
- output = "./effect"
81
- type = true
82
- comment = true
83
- relation = true
84
- }
85
-
86
- generator Hekireki-TypeBox {
87
- provider = "hekireki-typebox"
88
- output = "./typebox"
89
- type = true
90
- comment = true
91
- relation = true
92
- }
93
-
94
- generator Hekireki-AJV {
95
- provider = "hekireki-ajv"
96
- output = "./ajv"
97
- type = true
98
- comment = true
99
- relation = true
100
- }
101
-
102
- generator Hekireki-Pydantic {
103
- provider = "hekireki-pydantic"
104
- output = "./pydantic"
105
- comment = true
106
- }
107
-
108
- generator Hekireki-Drizzle {
109
- provider = "hekireki-drizzle"
110
- output = "./drizzle"
111
- }
112
-
113
- generator Hekireki-Kysely {
114
- provider = "hekireki-kysely"
115
- output = "./kysely"
116
- }
117
-
118
- generator Hekireki-Atlas {
119
- provider = "hekireki-atlas"
120
- output = "./atlas"
121
- }
122
-
123
- generator Hekireki-SQLAlchemy {
124
- provider = "hekireki-sqlalchemy"
125
- output = "./sqlalchemy"
126
- }
127
-
128
- generator Hekireki-GORM {
129
- provider = "hekireki-gorm"
130
- output = "./gorm"
131
- package = "model"
132
- }
133
-
134
- generator Hekireki-SeaORM {
135
- provider = "hekireki-sea-orm"
136
- output = "./sea_orm"
137
- renameAll = "camelCase"
138
- }
139
-
140
- generator Hekireki-Ecto {
141
- provider = "hekireki-ecto"
142
- output = "./ecto"
143
- app = "DBSchema"
144
- }
145
-
146
- generator Hekireki-ActiveRecord {
147
- provider = "hekireki-activerecord"
148
- output = "./activerecord"
149
- }
150
-
151
- generator Hekireki-Eloquent {
152
- provider = "hekireki-eloquent"
153
- output = "./eloquent"
154
- namespace = "App.Models"
155
- }
156
-
157
- generator Hekireki-ER {
158
- provider = "hekireki-mermaid-er"
159
- output = "./mermaid-er"
160
- }
161
-
162
- generator Hekireki-DBML {
163
- provider = "hekireki-dbml"
164
- output = "docs/schema.dbml"
165
- }
166
-
167
- generator Hekireki-Docs {
168
- provider = "hekireki-docs"
169
- output = "./docs"
170
- }
171
-
172
42
  model User {
173
43
  /// Primary key
174
44
  /// @z.uuid()
175
- /// @v.pipe(v.string(), v.uuid())
176
- /// @a."string.uuid"
177
- /// @e.Schema.UUID
178
- /// @t.Type.String({ format: 'uuid' })
179
- /// @j.{ type: 'string' as const, format: 'uuid' as const }
180
- /// @p.UUID4
181
45
  id String @id @default(uuid())
182
46
  /// Display name
183
47
  /// @z.string().min(1).max(50)
184
- /// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
185
- /// @a."1 <= string <= 50"
186
- /// @e.Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50))
187
- /// @t.Type.String({ minLength: 1, maxLength: 50 })
188
- /// @j.{ type: 'string' as const, minLength: 1, maxLength: 50 }
189
- /// @p.Annotated[str, StringConstraints(min_length=1, max_length=50)]
190
48
  name String
191
- /// One-to-many relation to Post
192
49
  posts Post[]
193
50
  }
194
51
 
195
52
  model Post {
196
53
  /// Primary key
197
54
  /// @z.uuid()
198
- /// @v.pipe(v.string(), v.uuid())
199
- /// @a."string.uuid"
200
- /// @e.Schema.UUID
201
- /// @t.Type.String({ format: 'uuid' })
202
- /// @j.{ type: 'string' as const, format: 'uuid' as const }
203
- /// @p.UUID4
204
- id String @id @default(uuid())
55
+ id String @id @default(uuid())
205
56
  /// Article title
206
57
  /// @z.string().min(1).max(100)
207
- /// @v.pipe(v.string(), v.minLength(1), v.maxLength(100))
208
- /// @a."1 <= string <= 100"
209
- /// @e.Schema.String.pipe(Schema.minLength(1), Schema.maxLength(100))
210
- /// @t.Type.String({ minLength: 1, maxLength: 100 })
211
- /// @j.{ type: 'string' as const, minLength: 1, maxLength: 100 }
212
- /// @p.Annotated[str, StringConstraints(min_length=1, max_length=100)]
213
- title String
214
- /// Body content (no length limit)
215
- /// @z.string()
216
- /// @v.string()
217
- /// @a."string"
218
- /// @e.Schema.String
219
- /// @t.Type.String()
220
- /// @j.{ type: 'string' as const }
221
- content String
58
+ title String
222
59
  /// Foreign key referencing User.id
223
60
  /// @z.uuid()
224
- /// @v.pipe(v.string(), v.uuid())
225
- /// @a."string.uuid"
226
- /// @e.Schema.UUID
227
- /// @t.Type.String({ format: 'uuid' })
228
- /// @j.{ type: 'string' as const, format: 'uuid' as const }
229
- /// @p.UUID4
230
- userId String
231
- /// Prisma relation definition
232
- user User @relation(fields: [userId], references: [id])
61
+ userId String
62
+ user User @relation(fields: [userId], references: [id])
233
63
  }
234
64
  ```
235
65
 
236
- ## Generated Output
237
-
238
- ### Zod
66
+ `npx prisma generate` writes `./zod/index.ts`:
239
67
 
240
68
  ```ts
241
69
  import * as z from 'zod'
@@ -262,10 +90,6 @@ export const PostSchema = z.object({
262
90
  * Article title
263
91
  */
264
92
  title: z.string().min(1).max(100),
265
- /**
266
- * Body content (no length limit)
267
- */
268
- content: z.string(),
269
93
  /**
270
94
  * Foreign key referencing User.id
271
95
  */
@@ -289,815 +113,35 @@ export const PostRelationsSchema = z.object({
289
113
  export type PostRelations = z.infer<typeof PostRelationsSchema>
290
114
  ```
291
115
 
292
- ### Valibot
293
-
294
- ```ts
295
- import * as v from 'valibot'
296
-
297
- export const UserSchema = v.object({
298
- /**
299
- * Primary key
300
- */
301
- id: v.pipe(v.string(), v.uuid()),
302
- /**
303
- * Display name
304
- */
305
- name: v.pipe(v.string(), v.minLength(1), v.maxLength(50)),
306
- })
307
-
308
- export type User = v.InferOutput<typeof UserSchema>
309
-
310
- export const PostSchema = v.object({
311
- /**
312
- * Primary key
313
- */
314
- id: v.pipe(v.string(), v.uuid()),
315
- /**
316
- * Article title
317
- */
318
- title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
319
- /**
320
- * Body content (no length limit)
321
- */
322
- content: v.string(),
323
- /**
324
- * Foreign key referencing User.id
325
- */
326
- userId: v.pipe(v.string(), v.uuid()),
327
- })
328
-
329
- export type Post = v.InferOutput<typeof PostSchema>
330
-
331
- export const UserRelationsSchema = v.object({
332
- ...UserSchema.entries,
333
- posts: v.array(PostSchema),
334
- })
335
-
336
- export type UserRelations = v.InferOutput<typeof UserRelationsSchema>
337
-
338
- export const PostRelationsSchema = v.object({
339
- ...PostSchema.entries,
340
- user: UserSchema,
341
- })
342
-
343
- export type PostRelations = v.InferOutput<typeof PostRelationsSchema>
344
- ```
345
-
346
- ### ArkType
347
-
348
- ```ts
349
- import { type } from 'arktype'
350
-
351
- export const UserSchema = type({
352
- /**
353
- * Primary key
354
- */
355
- id: 'string.uuid',
356
- /**
357
- * Display name
358
- */
359
- name: '1 <= string <= 50',
360
- })
361
-
362
- export type User = typeof UserSchema.infer
363
-
364
- export const PostSchema = type({
365
- /**
366
- * Primary key
367
- */
368
- id: 'string.uuid',
369
- /**
370
- * Article title
371
- */
372
- title: '1 <= string <= 100',
373
- /**
374
- * Body content (no length limit)
375
- */
376
- content: 'string',
377
- /**
378
- * Foreign key referencing User.id
379
- */
380
- userId: 'string.uuid',
381
- })
382
-
383
- export type Post = typeof PostSchema.infer
384
-
385
- export const UserRelationsSchema = type({ ...UserSchema.t, posts: PostSchema.array() })
386
-
387
- export type UserRelations = typeof UserRelationsSchema.infer
388
-
389
- export const PostRelationsSchema = type({ ...PostSchema.t, user: UserSchema })
390
-
391
- export type PostRelations = typeof PostRelationsSchema.infer
392
- ```
393
-
394
- ### Effect Schema
395
-
396
- ```ts
397
- import { Schema } from 'effect'
398
-
399
- export const UserSchema = Schema.Struct({
400
- /**
401
- * Primary key
402
- */
403
- id: Schema.UUID,
404
- /**
405
- * Display name
406
- */
407
- name: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50)),
408
- })
409
-
410
- export type User = typeof UserSchema.Type
411
-
412
- export const PostSchema = Schema.Struct({
413
- /**
414
- * Primary key
415
- */
416
- id: Schema.UUID,
417
- /**
418
- * Article title
419
- */
420
- title: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(100)),
421
- /**
422
- * Body content (no length limit)
423
- */
424
- content: Schema.String,
425
- /**
426
- * Foreign key referencing User.id
427
- */
428
- userId: Schema.UUID,
429
- })
430
-
431
- export type Post = typeof PostSchema.Type
432
-
433
- export const UserRelationsSchema = Schema.Struct({
434
- ...UserSchema.fields,
435
- posts: Schema.Array(PostSchema),
436
- })
437
-
438
- export type UserRelations = typeof UserRelationsSchema.Type
439
-
440
- export const PostRelationsSchema = Schema.Struct({ ...PostSchema.fields, user: UserSchema })
441
-
442
- export type PostRelations = typeof PostRelationsSchema.Type
443
- ```
444
-
445
- ### TypeBox
446
-
447
- ```ts
448
- import { type Static, Type } from '@sinclair/typebox'
449
-
450
- export const UserSchema = Type.Object({
451
- /**
452
- * Primary key
453
- */
454
- id: Type.String({ format: 'uuid' }),
455
- /**
456
- * Display name
457
- */
458
- name: Type.String({ minLength: 1, maxLength: 50 }),
459
- })
460
-
461
- export type User = Static<typeof UserSchema>
462
-
463
- export const PostSchema = Type.Object({
464
- /**
465
- * Primary key
466
- */
467
- id: Type.String({ format: 'uuid' }),
468
- /**
469
- * Article title
470
- */
471
- title: Type.String({ minLength: 1, maxLength: 100 }),
472
- /**
473
- * Body content (no length limit)
474
- */
475
- content: Type.String(),
476
- /**
477
- * Foreign key referencing User.id
478
- */
479
- userId: Type.String({ format: 'uuid' }),
480
- })
481
-
482
- export type Post = Static<typeof PostSchema>
483
-
484
- export const UserRelationsSchema = Type.Object({
485
- ...UserSchema.properties,
486
- posts: Type.Array(PostSchema),
487
- })
488
-
489
- export type UserRelations = Static<typeof UserRelationsSchema>
490
-
491
- export const PostRelationsSchema = Type.Object({
492
- ...PostSchema.properties,
493
- user: UserSchema,
494
- })
495
-
496
- export type PostRelations = Static<typeof PostRelationsSchema>
497
- ```
498
-
499
- ### AJV
500
-
501
- ```ts
502
- import type { FromSchema } from 'json-schema-to-ts'
503
-
504
- export const UserSchema = {
505
- type: 'object' as const,
506
- properties: {
507
- /**
508
- * Primary key
509
- */
510
- id: { type: 'string' as const, format: 'uuid' as const },
511
- /**
512
- * Display name
513
- */
514
- name: { type: 'string' as const, minLength: 1, maxLength: 50 },
515
- },
516
- required: ['id', 'name'] as const,
517
- additionalProperties: false,
518
- } as const
519
-
520
- export type User = FromSchema<typeof UserSchema>
521
-
522
- export const PostSchema = {
523
- type: 'object' as const,
524
- properties: {
525
- /**
526
- * Primary key
527
- */
528
- id: { type: 'string' as const, format: 'uuid' as const },
529
- /**
530
- * Article title
531
- */
532
- title: { type: 'string' as const, minLength: 1, maxLength: 100 },
533
- /**
534
- * Body content (no length limit)
535
- */
536
- content: { type: 'string' as const },
537
- /**
538
- * Foreign key referencing User.id
539
- */
540
- userId: { type: 'string' as const, format: 'uuid' as const },
541
- },
542
- required: ['id', 'title', 'content', 'userId'] as const,
543
- additionalProperties: false,
544
- } as const
545
-
546
- export type Post = FromSchema<typeof PostSchema>
547
-
548
- export const UserRelationsSchema = {
549
- type: 'object' as const,
550
- properties: {
551
- ...UserSchema.properties,
552
- posts: { type: 'array' as const, items: PostSchema },
553
- },
554
- additionalProperties: false,
555
- } as const
556
-
557
- export type UserRelations = FromSchema<typeof UserRelationsSchema>
558
-
559
- export const PostRelationsSchema = {
560
- type: 'object' as const,
561
- properties: {
562
- ...PostSchema.properties,
563
- user: UserSchema,
564
- },
565
- additionalProperties: false,
566
- } as const
567
-
568
- export type PostRelations = FromSchema<typeof PostRelationsSchema>
569
- ```
570
-
571
- ### Drizzle
572
-
573
- ```ts
574
- import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
575
- import { relations } from 'drizzle-orm'
576
-
577
- export const user = sqliteTable('user', {
578
- id: text('id')
579
- .primaryKey()
580
- .$defaultFn(() => crypto.randomUUID()),
581
- name: text('name').notNull(),
582
- })
583
-
584
- export const post = sqliteTable('post', {
585
- id: text('id')
586
- .primaryKey()
587
- .$defaultFn(() => crypto.randomUUID()),
588
- title: text('title').notNull(),
589
- content: text('content').notNull(),
590
- userId: text('userId')
591
- .notNull()
592
- .references(() => user.id),
593
- })
594
-
595
- export const userRelations = relations(user, ({ many }) => ({ posts: many(post) }))
596
-
597
- export const postRelations = relations(post, ({ one }) => ({
598
- user: one(user, { fields: [post.userId], references: [user.id] }),
599
- }))
600
- ```
601
-
602
- ### Kysely
116
+ Every other generator reads the same schema. What each one writes is easiest to read as real
117
+ output: [`example/schema.prisma`](https://github.com/nakita628/hekireki/blob/main/example/schema.prisma)
118
+ exercises all of them at once — enums, `@@map`, composite keys, self-relations, implicit
119
+ many-to-many, native `@db.*` types — and the output of every generator for it is committed under
120
+ [`example/generated/`](https://github.com/nakita628/hekireki/tree/main/example/generated).
603
121
 
604
- Pure type definitions for the [Kysely](https://kysely.dev/) query builder. The `DB` interface is keyed by the actual database table names (`@@map` respected), columns use `@map`-ped names, and enums become value unions of their `@map`-ped database values. Reach for Kysely's own `Selectable` / `Insertable` / `Updateable` wrappers when you need to name a row type; query results are inferred and need no annotation.
122
+ ## Annotations
605
123
 
606
- Only **database-side** defaults become `Generated<T>`. `autoincrement()`, `now()` and `dbgenerated(...)` are evaluated by the database, so they are optional on insert; `uuid()`, `cuid()`, `ulid()` and `nanoid()` are evaluated by the Prisma Client and leave the column without a DDL default, so a raw Kysely insert must still supply them.
124
+ A `///` comment on a field is its documentation. A `///` line that begins with one of the prefixes
125
+ below is the validation the matching generator emits for that field, used verbatim:
607
126
 
608
- ```ts
609
- export interface User {
610
- id: string
611
- name: string
612
- }
613
-
614
- export interface Post {
615
- id: string
616
- title: string
617
- content: string
618
- userId: string
619
- }
620
-
621
- export interface DB {
622
- User: User
623
- Post: Post
624
- }
625
- ```
626
-
627
- Both ids above are `@default(uuid())`, which Prisma evaluates in the client — hence plain `string`, required on insert. A database-side default instead emits `Generated<T>` (and, for `DateTime`, the `Timestamp` alias), which Kysely makes optional on insert:
628
-
629
- ```prisma
630
- model Comment {
631
- id Int @id @default(autoincrement())
632
- createdAt DateTime @default(now())
633
- }
634
- ```
635
-
636
- ```ts
637
- import type { ColumnType } from 'kysely'
638
-
639
- export type Generated<T> =
640
- T extends ColumnType<infer S, infer I, infer U>
641
- ? ColumnType<S, I | undefined, U>
642
- : ColumnType<T, T | undefined, T>
643
-
644
- export type Timestamp = ColumnType<Date, Date | string, Date | string>
645
-
646
- export interface Comment {
647
- id: Generated<number>
648
- createdAt: Generated<Timestamp>
649
- }
650
- ```
651
-
652
- ```ts
653
- import { Kysely, type Insertable } from 'kysely'
654
- import type { DB, Post } from './kysely/types'
655
-
656
- declare const db: Kysely<DB>
657
- declare const userId: string
658
-
659
- // Query results are inferred — no annotation needed.
660
- const posts = await db.selectFrom('Post').selectAll().execute()
661
-
662
- const draft: Insertable<Post> = {
663
- id: crypto.randomUUID(),
664
- title: 'Hello',
665
- content: '...',
666
- userId,
667
- }
668
- await db.insertInto('Post').values(draft).execute()
669
- ```
670
-
671
- ### Atlas
672
-
673
- A declarative [Atlas](https://atlasgo.io/) HCL schema (`schema.hcl`). Table and column names use their `@@map`/`@map` database names, foreign keys and indexes follow Prisma's naming conventions (`<table>_<columns>_fkey` / `_key` / `_idx`), referential actions fall back to Prisma's defaults (`onUpdate: Cascade`, `onDelete: Restrict` for required and `SetNull` for optional relations), and client-side defaults such as `uuid()` and `cuid()` emit no database `DEFAULT` — the file describes exactly what `prisma migrate` would create. The output is already `atlas schema fmt` canonical.
674
-
675
- The schema label defaults to `public` (PostgreSQL / MySQL) or `main` (SQLite); on MySQL, set `schemaName` to your database name since MySQL schemas are databases.
676
-
677
- > [!WARNING]
678
- > Declarative `atlas schema apply` drops whatever is missing from the HCL, and three things can never appear in it: Prisma's own `_prisma_migrations` table (exclude it with `--exclude '_prisma_migrations'`), and columns or tables marked `@ignore`/`@@ignore` or typed `Unsupported(...)` — Prisma omits those from the DMMF that hekireki reads. When applying to an existing database, always dry-run first and keep Atlas's destructive-change linting enabled.
679
-
680
- Known limitations: the implicit m2m primary key is an unnamed constraint (Prisma names it `_X_AB_pkey`; the column set is identical, so this only surfaces as a constraint rename if you later hand the database back to `prisma migrate`), all enum blocks land in the default schema under `multiSchema` (Prisma exposes no schema for enums), Prisma's 63-byte truncation of very long constraint names is not reproduced, and removing or renaming enum values is a type rebuild in Atlas, as in any PostgreSQL workflow.
681
-
682
- ```hcl
683
- table "User" {
684
- schema = schema.main
685
- column "id" {
686
- null = false
687
- type = text
688
- }
689
- column "name" {
690
- null = false
691
- type = text
692
- }
693
- primary_key {
694
- columns = [column.id]
695
- }
696
- }
697
-
698
- table "Post" {
699
- schema = schema.main
700
- column "id" {
701
- null = false
702
- type = text
703
- }
704
- column "title" {
705
- null = false
706
- type = text
707
- }
708
- column "content" {
709
- null = false
710
- type = text
711
- }
712
- column "userId" {
713
- null = false
714
- type = text
715
- }
716
- primary_key {
717
- columns = [column.id]
718
- }
719
- foreign_key "Post_userId_fkey" {
720
- columns = [column.userId]
721
- ref_columns = [table.User.column.id]
722
- on_update = CASCADE
723
- on_delete = RESTRICT
724
- }
725
- }
726
-
727
- schema "main" {}
728
- ```
729
-
730
- ```bash
731
- # Apply the schema declaratively (dry-run first), or diff versioned migrations from it
732
- atlas schema apply --url "$DATABASE_URL" --to file://atlas/schema.hcl --exclude '_prisma_migrations' --dry-run
733
- atlas schema apply --url "$DATABASE_URL" --to file://atlas/schema.hcl --exclude '_prisma_migrations'
734
- atlas migrate diff --dev-url "docker://postgres/17/dev" --to file://atlas/schema.hcl
735
- ```
736
-
737
- ### Ecto
738
-
739
- Each model is output as a separate `.ex` file (1 model = 1 file), following Elixir conventions.
740
-
741
- ```elixir
742
- defmodule DBSchema.User do
743
- use Ecto.Schema
744
- @moduledoc false
745
-
746
- @primary_key {:id, :binary_id, autogenerate: true}
747
- @foreign_key_type :binary_id
748
-
749
- @type t :: %__MODULE__{
750
- id: Ecto.UUID.t(),
751
- name: String.t(),
752
- posts: [DBSchema.Post.t()]
753
- }
754
-
755
- schema "user" do
756
- field(:name, :string)
757
- has_many(:posts, DBSchema.Post, foreign_key: :user_id)
758
- end
759
- end
760
- ```
761
-
762
- ```elixir
763
- defmodule DBSchema.Post do
764
- use Ecto.Schema
765
- @moduledoc false
766
-
767
- @primary_key {:id, :binary_id, autogenerate: true}
768
- @foreign_key_type :binary_id
769
-
770
- @type t :: %__MODULE__{
771
- id: Ecto.UUID.t(),
772
- title: String.t(),
773
- content: String.t(),
774
- user: DBSchema.User.t() | nil
775
- }
776
-
777
- schema "post" do
778
- field(:title, :string)
779
- field(:content, :string)
780
- field(:user_id, :binary_id, source: :userId)
781
- belongs_to(:user, DBSchema.User, foreign_key: :user_id, define_field: false)
782
- end
783
- end
784
- ```
785
-
786
- ### Active Record
787
-
788
- Each model is output as a separate `.rb` file (1 model = 1 file), following Rails conventions. `class_name` and `foreign_key` are always spelled out so the generated associations never rely on Rails inflection. The generated code targets Rails 7.1+ (positional `enum` syntax, composite primary keys) and is continuously syntax-checked (`ruby -c`) and loaded against the real `activerecord` gem in CI.
789
-
790
- ```ruby
791
- class User < ApplicationRecord
792
- self.table_name = "user"
793
-
794
- attribute :id, default: -> { SecureRandom.uuid }
795
-
796
- has_many :posts, class_name: "Post", foreign_key: "userId"
797
- end
798
- ```
799
-
800
- ```ruby
801
- class Post < ApplicationRecord
802
- self.table_name = "post"
803
-
804
- attribute :id, default: -> { SecureRandom.uuid }
805
-
806
- belongs_to :user, class_name: "User", foreign_key: "userId"
807
- end
808
- ```
809
-
810
- ### Eloquent
811
-
812
- Each model is output as a separate `.php` file (1 model = 1 file, PSR-4 friendly). Prisma enums become string-backed PHP enums with matching `$casts` entries. The generated code targets PHP 8.1+ (backed enums) and is continuously syntax-checked (`php -l`) and loaded against the real `illuminate/database` package in CI. Composite primary keys are emitted as `protected $primaryKey = null;` because Eloquent has no native composite key support.
813
-
814
- ```php
815
- <?php
816
-
817
- namespace App\Models;
818
-
819
- use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids;
820
- use Illuminate\Database\Eloquent\Model;
821
- use Illuminate\Database\Eloquent\Relations\HasMany;
822
-
823
- class User extends Model
824
- {
825
- use HasVersion4Uuids;
826
-
827
- protected $table = 'user';
828
-
829
- protected $keyType = 'string';
830
-
831
- public $incrementing = false;
832
-
833
- public $timestamps = false;
834
-
835
- protected $fillable = [
836
- 'name',
837
- ];
838
-
839
- public function posts(): HasMany
840
- {
841
- return $this->hasMany(Post::class, 'userId');
842
- }
843
- }
844
- ```
845
-
846
- ```php
847
- <?php
848
-
849
- namespace App\Models;
850
-
851
- use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids;
852
- use Illuminate\Database\Eloquent\Model;
853
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
854
-
855
- class Post extends Model
856
- {
857
- use HasVersion4Uuids;
858
-
859
- protected $table = 'post';
860
-
861
- protected $keyType = 'string';
862
-
863
- public $incrementing = false;
864
-
865
- public $timestamps = false;
866
-
867
- protected $fillable = [
868
- 'title',
869
- 'content',
870
- 'userId',
871
- ];
872
-
873
- public function user(): BelongsTo
874
- {
875
- return $this->belongsTo(User::class, 'userId');
876
- }
877
- }
878
- ```
879
-
880
- ### SQLAlchemy
881
-
882
- ```python
883
- from sqlalchemy import ForeignKey
884
- from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
885
- import uuid as uuid_mod
886
-
887
-
888
- class Base(DeclarativeBase):
889
- pass
890
-
891
-
892
- class User(Base):
893
- __tablename__ = "user"
894
-
895
- id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
896
- name: Mapped[str]
897
-
898
- posts: Mapped[list["Post"]] = relationship(back_populates="user")
899
-
900
- class Post(Base):
901
- __tablename__ = "post"
902
-
903
- id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
904
- title: Mapped[str]
905
- content: Mapped[str]
906
- user_id: Mapped[str] = mapped_column(ForeignKey("user.id"))
907
-
908
- user: Mapped["User"] = relationship(back_populates="posts")
909
- ```
910
-
911
- ### Pydantic
912
-
913
- [Pydantic](https://docs.pydantic.dev/) v2 models (Python). `@p.` field annotations are used verbatim as the base type — list fields wrap it in `list[...]` and optional fields append `| None = None` — and imports for the known pydantic / typing names they reference (`EmailStr`, `Annotated`, `StringConstraints`, …) are added automatically; names outside that set are emitted as-is without an import. Fields without an annotation fall back to the built-in Prisma → Python type mapping, enums become `Literal[...]` of their Prisma-level value names, and relation fields are omitted.
914
-
915
- ```python
916
- from pydantic import BaseModel, StringConstraints, UUID4
917
- from typing import Annotated
918
-
919
-
920
- class User(BaseModel):
921
- id: UUID4
922
- """Primary key"""
923
- name: Annotated[str, StringConstraints(min_length=1, max_length=50)]
924
- """Display name"""
925
-
926
-
927
- class Post(BaseModel):
928
- id: UUID4
929
- """Primary key"""
930
- title: Annotated[str, StringConstraints(min_length=1, max_length=100)]
931
- """Article title"""
932
- content: str
933
- """Body content (no length limit)"""
934
- userId: UUID4
935
- """Foreign key referencing User.id"""
936
- ```
937
-
938
- To configure the model itself, annotate it with pydantic's own `ConfigDict` — the expression is passed through verbatim as `model_config`. `@p.ConfigDict(extra='forbid')` rejects unknown keys, `@p.ConfigDict(extra='allow')` keeps them, `@p.ConfigDict(extra='ignore')` states pydantic's default explicitly, and any other `ConfigDict` arguments (e.g. `frozen=True`) work the same way. No annotation leaves pydantic's default (`extra="ignore"`):
939
-
940
- ```prisma
941
- /// @p.ConfigDict(extra='forbid')
942
- model ApiKey {
943
- id String @id
944
- }
945
- ```
946
-
947
- ```python
948
- from pydantic import BaseModel, ConfigDict
127
+ | Prefix | Generator | Example |
128
+ | ------ | ----------------- | ----------------------------------------- |
129
+ | `@z.` | Zod | `/// @z.string().min(1).max(50)` |
130
+ | `@v.` | Valibot | `/// @v.pipe(v.string(), v.minLength(1))` |
131
+ | `@a.` | ArkType | `/// @a."1 <= string <= 50"` |
132
+ | `@e.` | Effect Schema | `/// @e.Schema.UUID` |
133
+ | `@t.` | TypeBox | `/// @t.Type.String({ format: 'uuid' })` |
134
+ | `@j.` | AJV / JSON Schema | `/// @j.{ type: 'string' as const }` |
135
+ | `@p.` | Pydantic | `/// @p.EmailStr` |
949
136
 
137
+ A field without an annotation falls back to the Prisma type. `@p.ConfigDict(...)` on a **model** is
138
+ passed through as Pydantic's `model_config`.
950
139
 
951
- class ApiKey(BaseModel):
952
- model_config = ConfigDict(extra='forbid')
953
-
954
- id: str
955
- ```
956
-
957
- With `relation = true`, each model that has relation fields also gets a `<Model>Relations` subclass — the Pydantic counterpart of the validator generators' relation schemas. Relation fields reference the base classes, so a payload fetched with its relations validates in one call:
958
-
959
- ```python
960
- class UserRelations(User):
961
- posts: list[Post]
962
- ```
963
-
964
- ### GORM
965
-
966
- ```go
967
- package model
968
-
969
- import (
970
- "github.com/google/uuid"
971
- "gorm.io/gorm"
972
- )
973
-
974
- type User struct {
975
- ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
976
- Name string `gorm:"column:name;not null" json:"name"`
977
- Posts []Post `gorm:"foreignKey:UserID"`
978
- }
979
-
980
- func (m *User) BeforeCreate(_ *gorm.DB) error {
981
- if m.ID == "" {
982
- m.ID = uuid.NewString()
983
- }
984
- return nil
985
- }
986
-
987
- type Post struct {
988
- ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
989
- Title string `gorm:"column:title;not null" json:"title"`
990
- Content string `gorm:"column:content;not null" json:"content"`
991
- UserID string `gorm:"column:user_id;not null" json:"user_id"`
992
- User User
993
- }
994
-
995
- func (m *Post) BeforeCreate(_ *gorm.DB) error {
996
- if m.ID == "" {
997
- m.ID = uuid.NewString()
998
- }
999
- return nil
1000
- }
1001
- ```
1002
-
1003
- ### Sea-ORM
1004
-
1005
- Each model is output as a separate `.rs` file with `mod.rs` and `prelude.rs`, following Sea-ORM conventions.
1006
-
1007
- **user.rs:**
1008
-
1009
- ```rust
1010
- use sea_orm::entity::prelude::*;
1011
- use sea_orm::Set;
1012
- use serde::{Deserialize, Serialize};
1013
-
1014
- #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
1015
- #[serde(rename_all = "camelCase")]
1016
- #[sea_orm(table_name = "user")]
1017
- pub struct Model {
1018
- #[sea_orm(primary_key, auto_increment = false)]
1019
- pub id: String,
1020
- pub name: String,
1021
- }
1022
-
1023
- #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
1024
- pub enum Relation {
1025
- #[sea_orm(has_many = "super::post::Entity")]
1026
- Posts,
1027
- }
1028
-
1029
- impl Related<super::post::Entity> for Entity {
1030
- fn to() -> RelationDef {
1031
- Relation::Posts.def()
1032
- }
1033
- }
1034
-
1035
- impl ActiveModelBehavior for ActiveModel {
1036
- fn new() -> Self {
1037
- Self {
1038
- id: Set(uuid::Uuid::new_v4().to_string()),
1039
- ..ActiveModelTrait::default()
1040
- }
1041
- }
1042
- }
1043
- ```
1044
-
1045
- ### Mermaid
1046
-
1047
- ```mermaid
1048
- erDiagram
1049
- User ||--}| Post : "(id) - (userId)"
1050
- User {
1051
- string id PK "Primary key"
1052
- string name "Display name"
1053
- }
1054
- Post {
1055
- string id PK "Primary key"
1056
- string title "Article title"
1057
- string content "Body content (no length limit)"
1058
- string userId FK "Foreign key referencing User.id"
1059
- }
1060
- ```
1061
-
1062
- ### DBML
1063
-
1064
- ```dbml
1065
- Table User {
1066
- id String [pk, note: 'Primary key']
1067
- name String [not null, note: 'Display name']
1068
- }
1069
-
1070
- Table Post {
1071
- id String [pk, note: 'Primary key']
1072
- title String [not null, note: 'Article title']
1073
- content String [not null, note: 'Body content (no length limit)']
1074
- userId String [not null, note: 'Foreign key referencing User.id']
1075
- }
1076
-
1077
- Ref Post_userId_fk: Post.userId > User.id
1078
- ```
1079
-
1080
- ### PNG
1081
-
1082
- The `hekireki-dbml` generator also outputs ER diagrams as PNG images when the `output` path ends with `.png`:
1083
-
1084
- ```prisma
1085
- generator Hekireki-PNG {
1086
- provider = "hekireki-dbml"
1087
- output = "docs/er-diagram.png"
1088
- }
1089
- ```
1090
-
1091
- ### Logical Relations (without a Foreign Key)
1092
-
1093
- To draw a relation that has **no physical foreign key**, add a `/// @relation <Parent>.<field> <Child>.<field> <cardinality>` doc-comment on the model:
140
+ `/// @relation <Parent>.<field> <Child>.<field> <cardinality>` on a **model** declares a relation
141
+ that has no physical foreign key — it is drawn in the Mermaid, DBML and image output (dashed in the
142
+ drawing) even though the column carries no `@relation(...)`:
1094
143
 
1095
144
  ```prisma
1096
- model User {
1097
- id String @id @default(uuid())
1098
- name String
1099
- }
1100
-
1101
145
  /// @relation User.id Post.userId one-to-many
1102
146
  model Post {
1103
147
  id String @id @default(uuid())
@@ -1105,191 +149,195 @@ model Post {
1105
149
  }
1106
150
  ```
1107
151
 
1108
- The relation is drawn in both the Mermaid and DBML output even though `Post.userId` has no `@relation(...)` foreign key. When a physical FK and an annotation describe the same pair, the annotation's cardinality wins in the Mermaid diagram.
1109
-
1110
- ### Docs
1111
-
1112
- The `hekireki-docs` generator creates an HTML documentation page from your Prisma schema. Serve it locally with `hekireki docs serve`:
1113
-
1114
- ```prisma
1115
- generator Hekireki-Docs {
1116
- provider = "hekireki-docs"
1117
- output = "./docs"
1118
- }
1119
- ```
152
+ ## Generators
153
+
154
+ | `provider` | Target | Default output | Options |
155
+ | ----------------------- | -------------------------- | ------------------------------------------- | ------------------------------------ |
156
+ | `hekireki-zod` | TypeScript | `index.ts` | `type`, `comment`, `relation`, `zod` |
157
+ | `hekireki-valibot` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
158
+ | `hekireki-arktype` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
159
+ | `hekireki-effect` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
160
+ | `hekireki-typebox` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
161
+ | `hekireki-ajv` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
162
+ | `hekireki-drizzle` | TypeScript | `schema.ts` | — |
163
+ | `hekireki-kysely` | TypeScript | `types.ts` | — |
164
+ | `hekireki-pydantic` | Python | `models.py` | `comment`, `relation` |
165
+ | `hekireki-sqlalchemy` | Python | `models.py` | — |
166
+ | `hekireki-django` | Python (Django ≥ 5.2) | `models.py` | — |
167
+ | `hekireki-gorm` | Go | `models.go` | `package` |
168
+ | `hekireki-sea-orm` | Rust | one `.rs` per model, `mod.rs`, `prelude.rs` | `renameAll` |
169
+ | `hekireki-ecto` | Elixir | one `.ex` per model | `app` |
170
+ | `hekireki-activerecord` | Ruby (Rails ≥ 7.1) | one `.rb` per model | — |
171
+ | `hekireki-eloquent` | PHP (Laravel, PHP ≥ 8.1) | one `.php` per model and enum | `namespace` |
172
+ | `hekireki-atlas` | Atlas HCL | `schema.hcl` | `schemaName`, `comment` |
173
+ | `hekireki-er` | Mermaid / DBML / PNG / SVG | — (see [ER diagrams](#er-diagrams)) | `outputs`, `mapToDbSchema`, `theme` |
1120
174
 
1121
175
  ## Configuration
1122
176
 
1123
- Configure each generator directly in your `schema.prisma` file.
1124
-
1125
- > `output` is **required** for every generator — there is no implicit default directory.
1126
- > Point it at a directory to get the file name shown below, or at a path with an
1127
- > extension to choose the file name yourself.
1128
-
1129
177
  ```prisma
1130
- // Zod Generator
1131
178
  generator Hekireki-Zod {
1132
179
  provider = "hekireki-zod"
1133
180
  output = "./zod" // Required. A directory here yields ./zod/index.ts
1134
- type = true // Generate TypeScript types (default: false)
1135
- comment = true // Include schema documentation (default: false)
1136
- zod = "v4" // Zod import: "v4", "mini", or "@hono/zod-openapi" (default: v4)
1137
- relation = true // Generate relation schemas (default: false)
181
+ type = true // TypeScript types (default: false)
182
+ comment = true // /// comments as doc comments (default: false)
183
+ relation = true // <Model>Relations schemas (default: false)
184
+ zod = "v4" // "v4" | "mini" | "@hono/zod-openapi" (default: v4)
1138
185
  }
1139
186
 
1140
- // Valibot Generator
187
+ // Valibot, ArkType, Effect Schema, TypeBox and AJV take the same type / comment / relation options.
1141
188
  generator Hekireki-Valibot {
1142
189
  provider = "hekireki-valibot"
1143
- output = "./valibot" // Required. A directory here yields ./valibot/index.ts
1144
- type = true // Generate TypeScript types (default: false)
1145
- comment = true // Include schema documentation (default: false)
1146
- relation = true // Generate relation schemas (default: false)
1147
- }
1148
-
1149
- // ArkType Generator
1150
- generator Hekireki-ArkType {
1151
- provider = "hekireki-arktype"
1152
- output = "./arktype" // Required. A directory here yields ./arktype/index.ts
1153
- type = true // Generate TypeScript types (default: false)
1154
- comment = true // Include schema documentation (default: false)
1155
- relation = true // Generate relation schemas (default: false)
1156
- }
1157
-
1158
- // Effect Schema Generator
1159
- generator Hekireki-Effect {
1160
- provider = "hekireki-effect"
1161
- output = "./effect" // Required. A directory here yields ./effect/index.ts
1162
- type = true // Generate TypeScript types (default: false)
1163
- comment = true // Include schema documentation (default: false)
1164
- relation = true // Generate relation schemas (default: false)
1165
- }
1166
-
1167
- // TypeBox Generator
1168
- generator Hekireki-TypeBox {
1169
- provider = "hekireki-typebox"
1170
- output = "./typebox" // Required. A directory here yields ./typebox/index.ts
1171
- type = true // Generate TypeScript types (default: false)
1172
- comment = true // Include schema documentation (default: false)
1173
- relation = true // Generate relation schemas (default: false)
190
+ output = "./valibot"
191
+ type = true
192
+ comment = true
193
+ relation = true
1174
194
  }
1175
195
 
1176
- // AJV (JSON Schema) Generator
1177
- generator Hekireki-AJV {
1178
- provider = "hekireki-ajv"
1179
- output = "./ajv" // Required. A directory here yields ./ajv/index.ts
1180
- type = true // Generate TypeScript types (default: false)
1181
- comment = true // Include schema documentation (default: false)
1182
- relation = true // Generate relation schemas (default: false)
196
+ generator Hekireki-Pydantic {
197
+ provider = "hekireki-pydantic"
198
+ output = "./pydantic" // A directory here yields ./pydantic/models.py
199
+ comment = true // /// comments as docstrings (default: false)
200
+ relation = true // <Model>Relations subclasses (default: false)
1183
201
  }
1184
202
 
1185
- // Drizzle ORM Schema Generator
203
+ // Drizzle, Kysely, SQLAlchemy, Django and Active Record take output alone.
1186
204
  generator Hekireki-Drizzle {
1187
205
  provider = "hekireki-drizzle"
1188
- output = "./drizzle" // Required. A directory here yields ./drizzle/schema.ts
206
+ output = "./drizzle" // A directory here yields ./drizzle/schema.ts
1189
207
  }
1190
208
 
1191
- // Kysely Type Definitions Generator
1192
- generator Hekireki-Kysely {
1193
- provider = "hekireki-kysely"
1194
- output = "./kysely" // Required. A directory here yields ./kysely/types.ts
1195
- }
1196
-
1197
- // Atlas HCL Schema Generator
1198
209
  generator Hekireki-Atlas {
1199
210
  provider = "hekireki-atlas"
1200
- output = "./atlas" // Required. A directory here yields ./atlas/schema.hcl
1201
- schemaName = "public" // Schema label (default: postgresql/mysql "public", sqlite "main")
1202
- comment = true // Emit /// docs as comment attributes (default: false)
1203
- }
1204
-
1205
- // SQLAlchemy Generator (Python)
1206
- generator Hekireki-SQLAlchemy {
1207
- provider = "hekireki-sqlalchemy"
1208
- output = "./sqlalchemy" // Required. A directory here yields ./sqlalchemy/models.py
1209
- }
1210
-
1211
- // Pydantic Generator (Python)
1212
- generator Hekireki-Pydantic {
1213
- provider = "hekireki-pydantic"
1214
- output = "./pydantic" // Required. A directory here yields ./pydantic/models.py
1215
- comment = true // Include docstrings from /// comments (default: false)
1216
- relation = true // Generate <Model>Relations subclasses (default: false)
211
+ output = "./atlas" // A directory here yields ./atlas/schema.hcl
212
+ schemaName = "public" // Schema label (default: postgresql/mysql "public", sqlite "main")
213
+ comment = true // /// comments as comment attributes (default: false)
1217
214
  }
1218
215
 
1219
- // GORM Generator (Go)
1220
216
  generator Hekireki-GORM {
1221
217
  provider = "hekireki-gorm"
1222
- output = "./gorm" // Required. A directory here yields ./gorm/models.go
1223
- package = "model" // Go package name (default: model)
218
+ output = "./gorm" // A directory here yields ./gorm/models.go
219
+ package = "model" // Go package name (default: model)
1224
220
  }
1225
221
 
1226
- // Sea-ORM Generator (Rust)
1227
222
  generator Hekireki-SeaORM {
1228
- provider = "hekireki-sea-orm"
1229
- output = "./sea_orm" // Required. Output directory for .rs files
1230
- renameAll = "camelCase" // #[serde(rename_all = "...")] attribute (optional)
223
+ provider = "hekireki-sea-orm"
224
+ output = "./sea_orm"
225
+ renameAll = "camelCase" // #[serde(rename_all = "...")] (optional)
1231
226
  }
1232
227
 
1233
- // Ecto Generator (Elixir)
1234
228
  generator Hekireki-Ecto {
1235
229
  provider = "hekireki-ecto"
1236
- output = "./ecto" // Required. A directory here yields ./ecto/
1237
- app = "MyApp" // App name (default: MyApp)
1238
- }
1239
-
1240
- // Active Record Generator (Ruby on Rails)
1241
- generator Hekireki-ActiveRecord {
1242
- provider = "hekireki-activerecord"
1243
- output = "./activerecord" // Required. Output directory for .rb files
230
+ output = "./ecto"
231
+ app = "MyApp" // Module prefix (default: MyApp)
1244
232
  }
1245
233
 
1246
- // Eloquent Generator (Laravel / PHP)
1247
234
  generator Hekireki-Eloquent {
1248
235
  provider = "hekireki-eloquent"
1249
- output = "./eloquent" // Required. Output directory for .php files
1250
- namespace = "App.Models" // PHP namespace, "." becomes "\" (default: App\Models)
236
+ output = "./eloquent"
237
+ namespace = "App.Models" // PHP namespace, "." becomes "\" (default: App\Models)
1251
238
  }
1252
239
 
1253
- // Mermaid ER Generator
1254
240
  generator Hekireki-ER {
1255
- provider = "hekireki-mermaid-er"
1256
- output = "./mermaid-er" // Required. A directory here yields ./mermaid-er/ER.md
241
+ provider = "hekireki-er"
242
+ output = "docs" // The directory the files in outputs go in
243
+ outputs = ["er.md", "schema.dbml", "er.svg"] // .md, .dbml, .png or .svg (optional)
244
+ mapToDbSchema = true // .dbml only. @@map/@map names (default: true)
245
+ theme = "light" // .png / .svg only. "light" (default) or "dark"
1257
246
  }
247
+ ```
1258
248
 
1259
- // DBML Generator (output extension determines format: .dbml or .png)
1260
- generator Hekireki-DBML {
1261
- provider = "hekireki-dbml"
1262
- output = "docs/schema.dbml" // Required. File path ending in .dbml or .png
1263
- mapToDbSchema = true // Map to DB schema names (default: true)
1264
- }
249
+ ## ER diagrams
1265
250
 
1266
- // PNG output (same provider, different extension)
1267
- generator Hekireki-PNG {
1268
- provider = "hekireki-dbml"
1269
- output = "docs/er-diagram.png" // Required. .png extension → PNG output
1270
- mapToDbSchema = true // Map to DB schema names (default: true)
1271
- }
251
+ `hekireki-er` writes the ER model of the schema in four formats, and the extension of each file
252
+ picks which — so the file you name is the file you get, and an extension it has no format for is an
253
+ error rather than a guess. `outputs` is the list of files and `output` the directory they go in; for
254
+ a single file, point `output` straight at it and leave `outputs` out.
1272
255
 
1273
- // Docs Generator
1274
- generator Hekireki-Docs {
1275
- provider = "hekireki-docs"
1276
- output = "./docs" // Required. A directory here yields ./docs
1277
- }
1278
- ```
256
+ Every option belongs to a format (`mapToDbSchema` to `.dbml`, `theme` to `.png` and `.svg`), and
257
+ setting one that no chosen format reads is an error — so an option never looks like it did something
258
+ it did not.
1279
259
 
1280
- ## Docs Server
260
+ `.md` writes a Mermaid diagram:
1281
261
 
1282
- Hekireki includes a built-in documentation server powered by [Hono](https://hono.dev/). After generating docs with `prisma generate`, you can preview them locally:
262
+ ```mermaid
263
+ erDiagram
264
+ User ||--o{ Post : "(id) - (userId)"
265
+ User {
266
+ string id PK "Primary key"
267
+ string name "Display name"
268
+ }
269
+ Post {
270
+ string id PK "Primary key"
271
+ string title "Article title"
272
+ string userId FK "Foreign key referencing User.id"
273
+ }
274
+ ```
1283
275
 
1284
- ```bash
1285
- # Start the docs server (default: http://localhost:5858)
1286
- hekireki docs serve
276
+ `.dbml` writes the same model for [dbdiagram.io](https://dbml.dbdiagram.io/); `.png` and `.svg`
277
+ draw the diagram Hekireki Studio shows, laid out automatically: a card per model and enum, its
278
+ fields with `🔑` / `🔗` / `UK` marks, the attributes and `///` prose under each, the `@@id` /
279
+ `@@unique` / `@@index` block attributes, and an edge per relation in crow's-foot notation captioned
280
+ with its cardinality and referential action. No external renderer is involved, and the PNG is
281
+ rasterised at 2x. Use `.svg` for files in the repository and `.png` where images are embedded.
282
+ Studio's Schema page exports both with the models where you dragged them.
1287
283
 
1288
- # Specify a custom port
1289
- hekireki docs serve -p 3000
1290
- ```
284
+ ## Studio
285
+
286
+ `hekireki studio` opens the schema in the browser, served locally by [Hono](https://hono.dev/).
287
+ Nothing is generated first — Studio reads `schema.prisma` itself and reloads on every edit to it:
1291
288
 
1292
- > **Note:** Run `prisma generate` first to generate the `docs/` directory with `index.html`.
289
+ ```bash
290
+ # Open ./prisma/schema.prisma, then ./schema.prisma (default: http://localhost:5555)
291
+ hekireki studio
292
+
293
+ # Read a multi-file schema: every .prisma file directly in the directory, together
294
+ hekireki studio --schema prisma/schema
295
+
296
+ # Browse a database of your choosing
297
+ hekireki studio --url file:./dev.db
298
+
299
+ # Listen on another port
300
+ hekireki studio -p 3000
301
+ ```
302
+
303
+ | Page | What it is |
304
+ | ---------------- | --------------------------------------------------------------------------------- |
305
+ | `/` — Schema | The ER diagram, laid out automatically, with **PNG** / **SVG** export |
306
+ | `/docs` — Docs | The reference page: every model and enum with its fields, attributes and comments |
307
+ | `/models/<name>` | A model's rows, editable, next to its fields |
308
+ | `/enums/<name>` | An enum with its members and the fields that hold it |
309
+ | `/prisma` | The schema in a Prisma editor, with the language server's diagnostics |
310
+ | `/sql` | A SQL console against the connected database |
311
+
312
+ `--schema` takes either a `schema.prisma` file or a directory — every `.prisma` file directly in the
313
+ directory (subdirectories are not descended into) is read as one schema, which is how Prisma's
314
+ [multi-file schema](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema)
315
+ (`prisma/schema/`) is opened. Without the flag, `./prisma/schema.prisma` then `./schema.prisma` are
316
+ looked for — the same two paths the Prisma CLI defaults to. Either way the whole directory is
317
+ watched, so a `.prisma` file added to it appears in Studio without a restart.
318
+
319
+ The database is the one `--url` names, or `DATABASE_URL` from the environment or `.env`, then
320
+ `datasource.url` in `prisma.config.ts`; `postgres://`, `mysql://` and `file:` are understood. A
321
+ relative `file:` path is resolved from the schema directory, as Prisma resolves it — with the
322
+ default `prisma/schema.prisma`, `file:./dev.db` is `prisma/dev.db`. Without a database, Studio
323
+ serves the schema alone — the diagram, the docs and the editor still work.
324
+
325
+ The HTTP API behind it is documented in [docs/studio-api.md](https://github.com/nakita628/hekireki/blob/main/packages/hekireki/docs/studio-api.md).
326
+
327
+ ## Notes
328
+
329
+ - **Atlas** — declarative `atlas schema apply` drops whatever is missing from the HCL, and Prisma's
330
+ `_prisma_migrations` table, `@ignore`d columns and `Unsupported(...)` types can never appear in it.
331
+ Dry-run first and exclude the migrations table: `--exclude '_prisma_migrations'`.
332
+ - **Kysely** — only **database-side** defaults become `Generated<T>`. `uuid()`, `cuid()`, `ulid()`
333
+ and `nanoid()` are evaluated by the Prisma Client, so a raw Kysely insert must still supply them.
334
+ - **Django** — enums become `TextChoices` + `TextField(choices=…)` (Django has no native PostgreSQL
335
+ enum type), a foreign key to a composite `@@id` / `@@unique` is emitted as the scalar columns
336
+ without a relation, `onUpdate` is dropped, and a plain `DateTime` maps to `DateTimeField` while
337
+ Prisma stores `timestamp` — annotate it `@db.Timestamptz` to keep `USE_TZ = True` reads aware.
338
+ - **Eloquent** — a composite primary key is emitted as `protected $primaryKey = null;`, because
339
+ Eloquent has no native support for one. Active Record writes the real
340
+ `self.primary_key = [...]` (Rails ≥ 7.1).
1293
341
 
1294
342
  ## License
1295
343