hekireki 0.9.3 → 0.10.1

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 (43) hide show
  1. package/README.md +463 -66
  2. package/dist/bin/activerecord.d.ts +1 -0
  3. package/dist/bin/activerecord.js +6 -0
  4. package/dist/bin/ajv.d.ts +1 -1
  5. package/dist/bin/ajv.js +1 -1
  6. package/dist/bin/arktype.d.ts +1 -1
  7. package/dist/bin/arktype.js +1 -1
  8. package/dist/bin/atlas.d.ts +1 -0
  9. package/dist/bin/atlas.js +6 -0
  10. package/dist/bin/dbml.d.ts +1 -1
  11. package/dist/bin/dbml.js +1 -1
  12. package/dist/bin/docs.d.ts +1 -1
  13. package/dist/bin/docs.js +1 -1
  14. package/dist/bin/drizzle.d.ts +1 -1
  15. package/dist/bin/drizzle.js +1 -1
  16. package/dist/bin/ecto.d.ts +1 -1
  17. package/dist/bin/ecto.js +1 -1
  18. package/dist/bin/effect.d.ts +1 -1
  19. package/dist/bin/effect.js +1 -1
  20. package/dist/bin/eloquent.d.ts +1 -0
  21. package/dist/bin/eloquent.js +6 -0
  22. package/dist/bin/gorm.d.ts +1 -1
  23. package/dist/bin/gorm.js +1 -1
  24. package/dist/bin/kysely.d.ts +1 -0
  25. package/dist/bin/kysely.js +6 -0
  26. package/dist/bin/mermaid-er.d.ts +1 -1
  27. package/dist/bin/mermaid-er.js +1 -1
  28. package/dist/bin/pydantic.d.ts +1 -0
  29. package/dist/bin/pydantic.js +6 -0
  30. package/dist/bin/sea-orm.d.ts +1 -1
  31. package/dist/bin/sea-orm.js +1 -1
  32. package/dist/bin/sqlalchemy.d.ts +1 -1
  33. package/dist/bin/sqlalchemy.js +1 -1
  34. package/dist/bin/typebox.d.ts +1 -1
  35. package/dist/bin/typebox.js +1 -1
  36. package/dist/bin/valibot.d.ts +1 -1
  37. package/dist/bin/valibot.js +1 -1
  38. package/dist/bin/zod.d.ts +1 -1
  39. package/dist/bin/zod.js +1 -1
  40. package/dist/{bin-BQVq3vuc.js → bin-CR9GrJIk.js} +2067 -344
  41. package/dist/cli/index.d.ts +41 -41
  42. package/dist/cli/index.js +1 -1
  43. package/package.json +40 -20
package/README.md CHANGED
@@ -2,7 +2,7 @@
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, and Elixir.
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.
6
6
 
7
7
  ## Features
8
8
 
@@ -15,13 +15,21 @@
15
15
  - 📦 Automatically generates [TypeBox](https://github.com/sinclairzx81/typebox) schemas from your Prisma schema
16
16
  - 📋 Automatically generates [AJV](https://ajv.js.org/)-compatible JSON Schema objects from your Prisma schema
17
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
+
18
22
  ### ORM / Schema Generation (Multi-Language)
19
23
 
20
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
21
26
  - 🐍 Automatically generates [SQLAlchemy](https://www.sqlalchemy.org/) models (Python) — with `Mapped[T]` type hints, relationships, enums, composite keys, and index support
22
27
  - 🐹 Automatically generates [GORM](https://gorm.io/) models (Go) — with struct tags, JSON tags, relationships, enums, composite keys, and index support
23
28
  - 🦀 Automatically generates [Sea-ORM](https://www.sea-ql.org/SeaORM/) entities (Rust) — with `DeriveEntityModel`, relations, enums, serde support, and `rename_all`
24
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
25
33
 
26
34
  ### Diagrams & Documentation
27
35
 
@@ -43,12 +51,9 @@ datasource db {
43
51
  provider = "sqlite"
44
52
  }
45
53
 
46
- generator Hekireki-ER {
47
- provider = "hekireki-mermaid-er"
48
- }
49
-
50
54
  generator Hekireki-Zod {
51
55
  provider = "hekireki-zod"
56
+ output = "./zod"
52
57
  type = true
53
58
  comment = true
54
59
  relation = true
@@ -56,6 +61,7 @@ generator Hekireki-Zod {
56
61
 
57
62
  generator Hekireki-Valibot {
58
63
  provider = "hekireki-valibot"
64
+ output = "./valibot"
59
65
  type = true
60
66
  comment = true
61
67
  relation = true
@@ -63,6 +69,7 @@ generator Hekireki-Valibot {
63
69
 
64
70
  generator Hekireki-ArkType {
65
71
  provider = "hekireki-arktype"
72
+ output = "./arktype"
66
73
  type = true
67
74
  comment = true
68
75
  relation = true
@@ -70,6 +77,7 @@ generator Hekireki-ArkType {
70
77
 
71
78
  generator Hekireki-Effect {
72
79
  provider = "hekireki-effect"
80
+ output = "./effect"
73
81
  type = true
74
82
  comment = true
75
83
  relation = true
@@ -77,6 +85,7 @@ generator Hekireki-Effect {
77
85
 
78
86
  generator Hekireki-TypeBox {
79
87
  provider = "hekireki-typebox"
88
+ output = "./typebox"
80
89
  type = true
81
90
  comment = true
82
91
  relation = true
@@ -84,13 +93,31 @@ generator Hekireki-TypeBox {
84
93
 
85
94
  generator Hekireki-AJV {
86
95
  provider = "hekireki-ajv"
96
+ output = "./ajv"
87
97
  type = true
88
98
  comment = true
89
99
  relation = true
90
100
  }
91
101
 
102
+ generator Hekireki-Pydantic {
103
+ provider = "hekireki-pydantic"
104
+ output = "./pydantic"
105
+ comment = true
106
+ }
107
+
92
108
  generator Hekireki-Drizzle {
93
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"
94
121
  }
95
122
 
96
123
  generator Hekireki-SQLAlchemy {
@@ -116,6 +143,22 @@ generator Hekireki-Ecto {
116
143
  app = "DBSchema"
117
144
  }
118
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
+
119
162
  generator Hekireki-DBML {
120
163
  provider = "hekireki-dbml"
121
164
  output = "docs/schema.dbml"
@@ -134,6 +177,7 @@ model User {
134
177
  /// @e.Schema.UUID
135
178
  /// @t.Type.String({ format: 'uuid' })
136
179
  /// @j.{ type: 'string' as const, format: 'uuid' as const }
180
+ /// @p.UUID4
137
181
  id String @id @default(uuid())
138
182
  /// Display name
139
183
  /// @z.string().min(1).max(50)
@@ -142,6 +186,7 @@ model User {
142
186
  /// @e.Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50))
143
187
  /// @t.Type.String({ minLength: 1, maxLength: 50 })
144
188
  /// @j.{ type: 'string' as const, minLength: 1, maxLength: 50 }
189
+ /// @p.Annotated[str, StringConstraints(min_length=1, max_length=50)]
145
190
  name String
146
191
  /// One-to-many relation to Post
147
192
  posts Post[]
@@ -155,6 +200,7 @@ model Post {
155
200
  /// @e.Schema.UUID
156
201
  /// @t.Type.String({ format: 'uuid' })
157
202
  /// @j.{ type: 'string' as const, format: 'uuid' as const }
203
+ /// @p.UUID4
158
204
  id String @id @default(uuid())
159
205
  /// Article title
160
206
  /// @z.string().min(1).max(100)
@@ -163,6 +209,7 @@ model Post {
163
209
  /// @e.Schema.String.pipe(Schema.minLength(1), Schema.maxLength(100))
164
210
  /// @t.Type.String({ minLength: 1, maxLength: 100 })
165
211
  /// @j.{ type: 'string' as const, minLength: 1, maxLength: 100 }
212
+ /// @p.Annotated[str, StringConstraints(min_length=1, max_length=100)]
166
213
  title String
167
214
  /// Body content (no length limit)
168
215
  /// @z.string()
@@ -179,6 +226,7 @@ model Post {
179
226
  /// @e.Schema.UUID
180
227
  /// @t.Type.String({ format: 'uuid' })
181
228
  /// @j.{ type: 'string' as const, format: 'uuid' as const }
229
+ /// @p.UUID4
182
230
  userId String
183
231
  /// Prisma relation definition
184
232
  user User @relation(fields: [userId], references: [id])
@@ -333,6 +381,14 @@ export const PostSchema = type({
333
381
  })
334
382
 
335
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
336
392
  ```
337
393
 
338
394
  ### Effect Schema
@@ -351,7 +407,7 @@ export const UserSchema = Schema.Struct({
351
407
  name: Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50)),
352
408
  })
353
409
 
354
- export type UserEncoded = typeof UserSchema.Encoded
410
+ export type User = typeof UserSchema.Type
355
411
 
356
412
  export const PostSchema = Schema.Struct({
357
413
  /**
@@ -372,7 +428,18 @@ export const PostSchema = Schema.Struct({
372
428
  userId: Schema.UUID,
373
429
  })
374
430
 
375
- export type PostEncoded = typeof PostSchema.Encoded
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
376
443
  ```
377
444
 
378
445
  ### TypeBox
@@ -520,7 +587,9 @@ export const post = sqliteTable('post', {
520
587
  .$defaultFn(() => crypto.randomUUID()),
521
588
  title: text('title').notNull(),
522
589
  content: text('content').notNull(),
523
- userId: text('userId').notNull(),
590
+ userId: text('userId')
591
+ .notNull()
592
+ .references(() => user.id),
524
593
  })
525
594
 
526
595
  export const userRelations = relations(user, ({ many }) => ({ posts: many(post) }))
@@ -530,41 +599,139 @@ export const postRelations = relations(post, ({ one }) => ({
530
599
  }))
531
600
  ```
532
601
 
533
- #### ID default functions
602
+ ### Kysely
534
603
 
535
- For Drizzle, Prisma `@default(...)` ID generators are emitted as client-side `$defaultFn` calls. Some require an extra package — install it in your project:
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.
536
605
 
537
- | Prisma default | Generated call | Package to install |
538
- | ---------------------------------------- | --------------------- | ---------------------------------------------- |
539
- | `@default(uuid())` / `@default(uuid(4))` | `crypto.randomUUID()` | — (Node/Web built-in) |
540
- | `@default(cuid())` / `@default(cuid(1))` | `cuid()` | `npm i cuid` |
541
- | `@default(cuid(2))` | `createId()` | `npm i @paralleldrive/cuid2` |
542
- | `@default(nanoid())` | `nanoid()` | `npm i nanoid` (>= 5.0.9, or >= 3.3.8 for CJS) |
543
- | `@default(ulid())` | `ulid()` | `npm i ulidx` |
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.
544
607
 
545
- Notes:
608
+ ```ts
609
+ export interface User {
610
+ id: string
611
+ name: string
612
+ }
546
613
 
547
- - **`cuid()` uses cuid v1**, which its author has deprecated in favor of cuid v2 ([npm `cuid`](https://www.npmjs.com/package/cuid)). It is emitted only when you explicitly write `@default(cuid())`; for new schemas prefer `@default(cuid(2))`.
548
- - **`ulid()` maps to [`ulidx`](https://www.npmjs.com/package/ulidx)** (an actively maintained, crypto-backed drop-in for `ulid`).
549
- - `@default(uuid(7))` is currently emitted as `crypto.randomUUID()` (UUID v4); native v7 support is planned.
550
- - `@default(nanoid(n))` length argument is not yet applied — the default length is used.
551
- - Inserts that bypass the ORM (raw SQL, bulk load) won't run `$defaultFn`; add a database-level `DEFAULT` for those paths.
614
+ export interface Post {
615
+ id: string
616
+ title: string
617
+ content: string
618
+ userId: string
619
+ }
552
620
 
553
- ### Mermaid
621
+ export interface DB {
622
+ User: User
623
+ Post: Post
624
+ }
625
+ ```
554
626
 
555
- ```mermaid
556
- erDiagram
557
- User ||--}| Post : "(id) - (userId)"
558
- User {
559
- string id PK "Primary key"
560
- string name "Display name"
561
- }
562
- Post {
563
- string id PK "Primary key"
564
- string title "Article title"
565
- string content "Body content (no length limit)"
566
- string userId FK "Foreign key referencing User.id"
567
- }
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
568
735
  ```
569
736
 
570
737
  ### Ecto
@@ -616,11 +783,106 @@ defmodule DBSchema.Post do
616
783
  end
617
784
  ```
618
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
+
619
880
  ### SQLAlchemy
620
881
 
621
882
  ```python
622
883
  from sqlalchemy import ForeignKey
623
884
  from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
885
+ import uuid as uuid_mod
624
886
 
625
887
 
626
888
  class Base(DeclarativeBase):
@@ -630,16 +892,15 @@ class Base(DeclarativeBase):
630
892
  class User(Base):
631
893
  __tablename__ = "user"
632
894
 
633
- id: Mapped[str] = mapped_column(primary_key=True)
895
+ id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
634
896
  name: Mapped[str]
635
897
 
636
898
  posts: Mapped[list["Post"]] = relationship(back_populates="user")
637
899
 
638
-
639
900
  class Post(Base):
640
901
  __tablename__ = "post"
641
902
 
642
- id: Mapped[str] = mapped_column(primary_key=True)
903
+ id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
643
904
  title: Mapped[str]
644
905
  content: Mapped[str]
645
906
  user_id: Mapped[str] = mapped_column(ForeignKey("user.id"))
@@ -647,23 +908,95 @@ class Post(Base):
647
908
  user: Mapped["User"] = relationship(back_populates="posts")
648
909
  ```
649
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
949
+
950
+
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
+
650
964
  ### GORM
651
965
 
652
966
  ```go
653
967
  package model
654
968
 
969
+ import (
970
+ "github.com/google/uuid"
971
+ "gorm.io/gorm"
972
+ )
973
+
655
974
  type User struct {
656
- ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
975
+ ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
657
976
  Name string `gorm:"column:name;not null" json:"name"`
658
977
  Posts []Post `gorm:"foreignKey:UserID"`
659
978
  }
660
979
 
980
+ func (m *User) BeforeCreate(_ *gorm.DB) error {
981
+ if m.ID == "" {
982
+ m.ID = uuid.NewString()
983
+ }
984
+ return nil
985
+ }
986
+
661
987
  type Post struct {
662
- ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
663
- Title string `gorm:"column:title;not null" json:"title"`
988
+ ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
989
+ Title string `gorm:"column:title;not null" json:"title"`
664
990
  Content string `gorm:"column:content;not null" json:"content"`
665
- UserID string `gorm:"column:user_id;not null" json:"user_id"`
666
- User User
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
667
1000
  }
668
1001
  ```
669
1002
 
@@ -675,9 +1008,10 @@ Each model is output as a separate `.rs` file with `mod.rs` and `prelude.rs`, fo
675
1008
 
676
1009
  ```rust
677
1010
  use sea_orm::entity::prelude::*;
1011
+ use sea_orm::Set;
678
1012
  use serde::{Deserialize, Serialize};
679
1013
 
680
- #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
1014
+ #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
681
1015
  #[serde(rename_all = "camelCase")]
682
1016
  #[sea_orm(table_name = "user")]
683
1017
  pub struct Model {
@@ -698,7 +1032,31 @@ impl Related<super::post::Entity> for Entity {
698
1032
  }
699
1033
  }
700
1034
 
701
- impl ActiveModelBehavior for ActiveModel {}
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
+ }
702
1060
  ```
703
1061
 
704
1062
  ### DBML
@@ -762,13 +1120,17 @@ generator Hekireki-Docs {
762
1120
 
763
1121
  ## Configuration
764
1122
 
765
- Configure each generator directly in your `schema.prisma` file:
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.
766
1128
 
767
1129
  ```prisma
768
1130
  // Zod Generator
769
1131
  generator Hekireki-Zod {
770
1132
  provider = "hekireki-zod"
771
- output = "./zod" // Output path (default: ./zod/index.ts)
1133
+ output = "./zod" // Required. A directory here yields ./zod/index.ts
772
1134
  type = true // Generate TypeScript types (default: false)
773
1135
  comment = true // Include schema documentation (default: false)
774
1136
  zod = "v4" // Zod import: "v4", "mini", or "@hono/zod-openapi" (default: v4)
@@ -778,7 +1140,7 @@ generator Hekireki-Zod {
778
1140
  // Valibot Generator
779
1141
  generator Hekireki-Valibot {
780
1142
  provider = "hekireki-valibot"
781
- output = "./valibot" // Output path (default: ./valibot/index.ts)
1143
+ output = "./valibot" // Required. A directory here yields ./valibot/index.ts
782
1144
  type = true // Generate TypeScript types (default: false)
783
1145
  comment = true // Include schema documentation (default: false)
784
1146
  relation = true // Generate relation schemas (default: false)
@@ -787,7 +1149,7 @@ generator Hekireki-Valibot {
787
1149
  // ArkType Generator
788
1150
  generator Hekireki-ArkType {
789
1151
  provider = "hekireki-arktype"
790
- output = "./arktype" // Output path (default: ./arktype/index.ts)
1152
+ output = "./arktype" // Required. A directory here yields ./arktype/index.ts
791
1153
  type = true // Generate TypeScript types (default: false)
792
1154
  comment = true // Include schema documentation (default: false)
793
1155
  relation = true // Generate relation schemas (default: false)
@@ -796,7 +1158,7 @@ generator Hekireki-ArkType {
796
1158
  // Effect Schema Generator
797
1159
  generator Hekireki-Effect {
798
1160
  provider = "hekireki-effect"
799
- output = "./effect" // Output path (default: ./effect/index.ts)
1161
+ output = "./effect" // Required. A directory here yields ./effect/index.ts
800
1162
  type = true // Generate TypeScript types (default: false)
801
1163
  comment = true // Include schema documentation (default: false)
802
1164
  relation = true // Generate relation schemas (default: false)
@@ -805,7 +1167,7 @@ generator Hekireki-Effect {
805
1167
  // TypeBox Generator
806
1168
  generator Hekireki-TypeBox {
807
1169
  provider = "hekireki-typebox"
808
- output = "./typebox" // Output path (default: ./typebox/index.ts)
1170
+ output = "./typebox" // Required. A directory here yields ./typebox/index.ts
809
1171
  type = true // Generate TypeScript types (default: false)
810
1172
  comment = true // Include schema documentation (default: false)
811
1173
  relation = true // Generate relation schemas (default: false)
@@ -814,7 +1176,7 @@ generator Hekireki-TypeBox {
814
1176
  // AJV (JSON Schema) Generator
815
1177
  generator Hekireki-AJV {
816
1178
  provider = "hekireki-ajv"
817
- output = "./ajv" // Output path (default: ./ajv/index.ts)
1179
+ output = "./ajv" // Required. A directory here yields ./ajv/index.ts
818
1180
  type = true // Generate TypeScript types (default: false)
819
1181
  comment = true // Include schema documentation (default: false)
820
1182
  relation = true // Generate relation schemas (default: false)
@@ -823,60 +1185,95 @@ generator Hekireki-AJV {
823
1185
  // Drizzle ORM Schema Generator
824
1186
  generator Hekireki-Drizzle {
825
1187
  provider = "hekireki-drizzle"
826
- output = "./drizzle" // Output path (default: ./drizzle/schema.ts)
1188
+ output = "./drizzle" // Required. A directory here yields ./drizzle/schema.ts
827
1189
  }
828
1190
 
829
- // Mermaid ER Generator
830
- generator Hekireki-ER {
831
- provider = "hekireki-mermaid-er"
832
- output = "./mermaid-er" // Output path (default: ./mermaid-er/ER.md)
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
+ generator Hekireki-Atlas {
1199
+ 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)
833
1203
  }
834
1204
 
835
1205
  // SQLAlchemy Generator (Python)
836
1206
  generator Hekireki-SQLAlchemy {
837
1207
  provider = "hekireki-sqlalchemy"
838
- output = "./sqlalchemy" // Output path (default: ./sqlalchemy/models.py)
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)
839
1217
  }
840
1218
 
841
1219
  // GORM Generator (Go)
842
1220
  generator Hekireki-GORM {
843
1221
  provider = "hekireki-gorm"
844
- output = "./gorm" // Output path (default: ./gorm/models.go)
1222
+ output = "./gorm" // Required. A directory here yields ./gorm/models.go
845
1223
  package = "model" // Go package name (default: model)
846
1224
  }
847
1225
 
848
1226
  // Sea-ORM Generator (Rust)
849
1227
  generator Hekireki-SeaORM {
850
1228
  provider = "hekireki-sea-orm"
851
- output = "./sea_orm" // Output directory for .rs files
1229
+ output = "./sea_orm" // Required. Output directory for .rs files
852
1230
  renameAll = "camelCase" // #[serde(rename_all = "...")] attribute (optional)
853
1231
  }
854
1232
 
855
1233
  // Ecto Generator (Elixir)
856
1234
  generator Hekireki-Ecto {
857
1235
  provider = "hekireki-ecto"
858
- output = "./ecto" // Output directory (default: ./ecto/)
1236
+ output = "./ecto" // Required. A directory here yields ./ecto/
859
1237
  app = "MyApp" // App name (default: MyApp)
860
1238
  }
861
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
1244
+ }
1245
+
1246
+ // Eloquent Generator (Laravel / PHP)
1247
+ generator Hekireki-Eloquent {
1248
+ provider = "hekireki-eloquent"
1249
+ output = "./eloquent" // Required. Output directory for .php files
1250
+ namespace = "App.Models" // PHP namespace, "." becomes "\" (default: App\Models)
1251
+ }
1252
+
1253
+ // Mermaid ER Generator
1254
+ generator Hekireki-ER {
1255
+ provider = "hekireki-mermaid-er"
1256
+ output = "./mermaid-er" // Required. A directory here yields ./mermaid-er/ER.md
1257
+ }
1258
+
862
1259
  // DBML Generator (output extension determines format: .dbml or .png)
863
1260
  generator Hekireki-DBML {
864
1261
  provider = "hekireki-dbml"
865
- output = "docs/schema.dbml" // File path ending in .dbml or .png
1262
+ output = "docs/schema.dbml" // Required. File path ending in .dbml or .png
866
1263
  mapToDbSchema = true // Map to DB schema names (default: true)
867
1264
  }
868
1265
 
869
1266
  // PNG output (same provider, different extension)
870
1267
  generator Hekireki-PNG {
871
1268
  provider = "hekireki-dbml"
872
- output = "docs/er-diagram.png" // .png extension → PNG output
1269
+ output = "docs/er-diagram.png" // Required. .png extension → PNG output
873
1270
  mapToDbSchema = true // Map to DB schema names (default: true)
874
1271
  }
875
1272
 
876
1273
  // Docs Generator
877
1274
  generator Hekireki-Docs {
878
1275
  provider = "hekireki-docs"
879
- output = "./docs" // Output directory (default: ./docs)
1276
+ output = "./docs" // Required. A directory here yields ./docs
880
1277
  }
881
1278
  ```
882
1279