hekireki 0.37.0 → 0.39.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 (94) hide show
  1. package/README.md +202 -127
  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 +1 -1
  7. package/dist/bin/drizzle.js +1 -1
  8. package/dist/bin/ecto.js +1 -1
  9. package/dist/bin/efcore.js +1 -1
  10. package/dist/bin/effect.js +1 -1
  11. package/dist/bin/eloquent.js +1 -1
  12. package/dist/bin/er.js +1 -1
  13. package/dist/bin/exposed.js +1 -1
  14. package/dist/bin/gorm.js +1 -1
  15. package/dist/bin/hekireki.js +5 -5
  16. package/dist/bin/kysely.js +1 -1
  17. package/dist/bin/pydantic.js +1 -1
  18. package/dist/bin/sea-orm.js +1 -1
  19. package/dist/bin/seed.js +1 -1
  20. package/dist/bin/sqlalchemy.js +1 -1
  21. package/dist/bin/typebox.js +1 -1
  22. package/dist/bin/valibot.js +1 -1
  23. package/dist/bin/zod.js +1 -1
  24. package/dist/{bin-CVN0pzc4.js → bin-BqUSO3tD.js} +544 -613
  25. package/dist/{discover-CcuFW0ZA.js → discover-taxa67WN.js} +1 -1
  26. package/dist/{emit-ALVe1wlq.js → emit-D6EafjQn.js} +1 -1
  27. package/dist/{migrate-DmUsB0Wq.js → migrate-BS2daXFS.js} +3 -3
  28. package/dist/{plan-FKGe6CzO.js → plan-BtHvkK4c.js} +487 -209
  29. package/dist/{prisma-model-NuNLrPtP.js → prisma-model-bvolNNow.js} +28 -4
  30. package/dist/{run-qU5ejzJJ.js → run-C7QR2qhb.js} +22 -19
  31. package/dist/{schema-D8vxD4Kv.js → schema-DaaMSqfw.js} +1 -1
  32. package/dist/{sql-BWRXT82c.js → sql-BGnCCgBa.js} +3 -5
  33. package/dist/{start-DCHq_ac3.js → start-AZKmzv5G.js} +4690 -4233
  34. package/dist/studio/assets/chip-qtq7V4Rg.js +1 -0
  35. package/dist/studio/assets/client-CrHiNQcn.js +2 -0
  36. package/dist/studio/assets/code-block-CMwrS7oX.js +24 -0
  37. package/dist/studio/assets/confirm-dialog-D-QpTAoA.js +1 -0
  38. package/dist/studio/assets/copy-CxzC330n.js +1 -0
  39. package/dist/studio/assets/{copy-button-0vjAmGWM.js → copy-button-BdkKLTkw.js} +1 -1
  40. package/dist/studio/assets/dist-BxXzo21y.js +13 -0
  41. package/dist/studio/assets/{docs-CaVCv7nB.js → docs-C7LO1TRA.js} +1 -1
  42. package/dist/studio/assets/editor.worker-BmdWdrHZ.js +33 -0
  43. package/dist/studio/assets/{enums._name-z71scSmR.js → enums._name-39GUOK93.js} +1 -1
  44. package/dist/studio/assets/field-icon-7dg1DynP.js +55 -0
  45. package/dist/studio/assets/hooks-zIaThymT.js +2 -0
  46. package/dist/studio/assets/index-CkssgCVw.js +11 -0
  47. package/dist/studio/assets/labels-Kd2QEwTC.js +2 -0
  48. package/dist/studio/assets/lazyRouteComponent-65jX9pcP.js +1 -0
  49. package/dist/studio/assets/lu-CMRQv6zo.js +7 -0
  50. package/dist/studio/assets/marked-text-CZD1SIT9.js +3 -0
  51. package/dist/studio/assets/models._name-CHe0Do2Y.js +1 -0
  52. package/dist/studio/assets/{monaco-B9PsjQQo.js → monaco-CTrNbz9K.js} +2 -2
  53. package/dist/studio/assets/monaco-XesTiddK.js +943 -0
  54. package/dist/studio/assets/{not-found-4wswYq0J.js → not-found-CMgHbtIb.js} +1 -1
  55. package/dist/studio/assets/prisma-BRcayuiL.js +2 -0
  56. package/dist/studio/assets/result-table-BINfktPB.js +1 -0
  57. package/dist/studio/assets/routes-BzUMSxYJ.js +1 -0
  58. package/dist/studio/assets/{schema-gate-BvdKOqn1.js → schema-gate-CJc_mlpl.js} +1 -1
  59. package/dist/studio/assets/schema-view-D6zy0-V7.js +9 -0
  60. package/dist/studio/assets/search-field-Cch08a8e.js +5 -0
  61. package/dist/studio/assets/sql-D1dfGXuK.js +6 -0
  62. package/dist/studio/assets/table-Dd2Yy1pw.js +1 -0
  63. package/dist/studio/assets/tabs-Bn62CRYV.js +1 -0
  64. package/dist/studio/assets/useFormValidation-Bj-3Yj3r.js +1 -0
  65. package/dist/studio/assets/useMatch-C20PphzP.js +1 -0
  66. package/dist/studio/assets/useMultipleSelectionState-DaV9XbLV.js +1 -0
  67. package/dist/studio/index.html +10 -9
  68. package/package.json +38 -37
  69. package/dist/studio/assets/chip-DzylbrFL.js +0 -1
  70. package/dist/studio/assets/client-Dntzxukj.js +0 -2
  71. package/dist/studio/assets/code-block-9KOaLIVF.js +0 -24
  72. package/dist/studio/assets/confirm-dialog-_tJslTz8.js +0 -1
  73. package/dist/studio/assets/copy-BU2HaQi8.js +0 -1
  74. package/dist/studio/assets/dist-DZceSPCo.js +0 -13
  75. package/dist/studio/assets/editor.worker-DWPaKKV_.js +0 -33
  76. package/dist/studio/assets/hooks-CIyp76Ha.js +0 -55
  77. package/dist/studio/assets/index-BplvUeah.js +0 -16
  78. package/dist/studio/assets/labels-CxkkiH5p.js +0 -1
  79. package/dist/studio/assets/lazyRouteComponent-HlW_UM7H.js +0 -1
  80. package/dist/studio/assets/lu-C9ww8Xn7.js +0 -7
  81. package/dist/studio/assets/marked-text-DkIbIGaf.js +0 -3
  82. package/dist/studio/assets/models._name-Bf8RXxTl.js +0 -1
  83. package/dist/studio/assets/monaco-dYT_niNG.js +0 -943
  84. package/dist/studio/assets/prisma-BpS-GoYm.js +0 -2
  85. package/dist/studio/assets/result-table-DvGl9IoJ.js +0 -1
  86. package/dist/studio/assets/routes-cRDXK5Bp.js +0 -1
  87. package/dist/studio/assets/schema-view-CqNyYGB0.js +0 -9
  88. package/dist/studio/assets/sql-iadv3BWl.js +0 -6
  89. package/dist/studio/assets/table-DUjzf1P8.js +0 -1
  90. package/dist/studio/assets/tabs-DJr-DjH8.js +0 -1
  91. package/dist/studio/assets/useFormValidation-BB_6NZbP.js +0 -1
  92. package/dist/studio/assets/useMatch-CLknNl5M.js +0 -1
  93. package/dist/studio/assets/useMultipleSelectionState-BqzE75CP.js +0 -1
  94. package/dist/studio/assets/useOverlayTriggerState-DVeiBmOc.js +0 -1
package/README.md CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  # Hekireki
4
4
 
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, and seeds a database.
5
+ **[Hekireki](https://www.npmjs.com/package/hekireki)** reads a [Prisma](https://www.prisma.io/)
6
+ schema and writes what the rest of the project needs from it: validation schemas, ORM models for
7
+ nine languages, an ER diagram, and seed data. It also comes with a Studio for the schema and its
8
+ database.
7
9
 
8
10
  ## Installation
9
11
 
@@ -11,12 +13,9 @@ ER diagrams from a [Prisma](https://www.prisma.io/) schema, and seeds a database
11
13
  npm install -D hekireki
12
14
  ```
13
15
 
14
- ## Generators
16
+ ## Quick start
15
17
 
16
- Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required. Every
17
- generator reads the tables and columns Prisma creates: a model or field without `@map` keeps the
18
- name it has in the schema (`"Todo"`, `"authorId"`), and each ORM is told so where its own
19
- convention would say otherwise.
18
+ Add a generator block to `schema.prisma` and run `npx prisma generate`. `output` is required.
20
19
 
21
20
  ```prisma
22
21
  generator Hekireki-Zod {
@@ -26,65 +25,13 @@ generator Hekireki-Zod {
26
25
  }
27
26
  ```
28
27
 
29
- | Provider | Generates | Options |
30
- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------- |
31
- | `hekireki-zod` | [Zod](https://zod.dev/) | `type`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
32
- | `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `relation` |
33
- | `hekireki-pydantic` | Pydantic | `relation` |
34
- | `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django` | Drizzle, Kysely, SQLAlchemy, Django | |
35
- | `hekireki-activerecord` | Active Record | `locales` |
36
- | `hekireki-gorm` | GORM | `package` |
37
- | `hekireki-sea-orm` | SeaORM | `renameAll` |
38
- | `hekireki-ecto` | Ecto | `app` |
39
- | `hekireki-eloquent` | Eloquent | `namespace` |
40
- | `hekireki-efcore` (PostgreSQL, MySQL, SQLite) | EF Core | `namespace`, `context` |
41
- | `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
42
- | `hekireki-atlas` | Atlas HCL | `schemaName` |
43
- | `hekireki-er` | ER diagram | `outputs` (`.md`, `.dbml`, `.png`, `.svg`), `theme` |
44
- | `hekireki-seed` | The schema module `hekireki.config.ts` is typed against | |
45
-
46
- On MySQL, `hekireki-drizzle` reads and writes a `@db.Timestamp` column as UTC, and MySQL converts a
47
- `TIMESTAMP` through the connection's `time_zone`: set it to `'+00:00'` on drizzle's connection, as
48
- Prisma's adapter does on its own, or the two see times that differ by the offset. On CockroachDB it
49
- writes the PostgreSQL schema, for node-postgres, and an `Int` key with `@default(sequence())` is an
50
- identity column, as Prisma makes it; keep the session's `TimeZone` at UTC there, as on PostgreSQL,
51
- for a `dbgenerated("CURRENT_TIMESTAMP")` default to be UTC.
52
-
53
- `hekireki-atlas` writes the tables as Prisma Migrate makes them, so that `atlas schema diff`
54
- against a database Prisma made has nothing to change. Its `schemaName` is `public` unless given
55
- (`main` on SQLite): on MySQL, where the schema is the database, give the database's name.
56
-
57
- `hekireki-efcore` stores a `DateTime` as Prisma Client does, whatever its `DateTimeKind`: the UTC
58
- instant (a `Local` value converted), read back as `Utc`, in Prisma's text form on SQLite, and
59
- `now()` filled in by EF Core rather than by the database's clock. It takes Npgsql's legacy
60
- timestamp behaviour to be off. On MySQL, compare a `@db.Time` column with a parameter rather than
61
- a constant: MySql.EntityFrameworkCore writes a constant `TimeSpan` as `TIME '03:04:05'`, without
62
- its fraction.
63
-
64
- `hekireki-django` keeps a `DateTime` as Prisma Client keeps it. A column without a zone is declared
65
- with the `UtcDateTimeField` written into `models.py`, which stores the UTC instant (on SQLite
66
- Prisma's text, `2030-01-02T03:04:05.678+00:00`) and reads it back as UTC, aware under
67
- `USE_TZ = True` and in `TIME_ZONE` under `False`; a `@db.Timestamptz` is Django's own field.
68
- `now()` is filled in by the model, in UTC (the UTC date or time on `@db.Date` and `@db.Time`), a
69
- literal default on a date or time column is its UTC date or time, an `@updatedAt` on one stamps the
70
- UTC date or time (`UtcDateField`, `UtcTimeField`) where Django's `auto_now` would take the local
71
- one, and a model with `@updatedAt` is managed by `AutoNowQuerySet`, so `QuerySet.update()` bumps it
72
- as `updateMany` does. Keep
73
- `USE_TZ = True`, Django's default: with `False`, Django sets a PostgreSQL session to `TIME_ZONE`,
74
- and a `dbgenerated()` default such as `CURRENT_TIMESTAMP` is evaluated in that zone.
75
-
76
- `hekireki-exposed` keeps a `DateTime` as Prisma Client keeps it, with no conversion through the
77
- JVM's zone: an `Instant` bound and read as the UTC instant, to the millisecond (a finer value is
78
- truncated, as a JavaScript Date holds it, in every native type), the UTC date of a `@db.Date`, the
79
- UTC time of a `@db.Time`, and a `@db.Timetz` at offset zero. `now()`, literal defaults and every
80
- `@updatedAt` are filled in by the client on a DAO or DSL insert, and the DAO bumps `@updatedAt` on
81
- update; a DSL `Table.update` has no such hook, so set it there yourself
82
- (`it[updatedAt] = Instant.now()`). pgjdbc sets the session to the JVM's zone, so open the
83
- connection in UTC, as Prisma's is, for a `dbgenerated("CURRENT_TIMESTAMP")` default or `now()` in
84
- SQL: `Database.connect(url, setupConnection = { it.createStatement().use { s -> s.execute("SET TIME ZONE 'UTC'") } })`.
28
+ Every generator reads the tables and columns Prisma creates: a model or field without `@map`
29
+ keeps the name it has in the schema (`"Todo"`, `"authorId"`), and each ORM is told so where its
30
+ own convention would say otherwise.
85
31
 
86
- A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.`, `@p.`, `@ar.` or `@ecto.` is
87
- used as-is by Zod, Valibot, ArkType, Effect Schema, TypeBox, AJV, Pydantic, Active Record or Ecto:
32
+ A `///` comment on a field can carry a line for one of the validation generators, which uses it
33
+ as it is. The prefix says which: `@z.` for Zod, `@v.` Valibot, `@a.` ArkType, `@e.` Effect
34
+ Schema, `@t.` TypeBox, `@j.` AJV, `@p.` Pydantic, `@ar.` Active Record and `@ecto.` Ecto.
88
35
 
89
36
  ```prisma
90
37
  model User {
@@ -94,7 +41,104 @@ model User {
94
41
  }
95
42
  ```
96
43
 
97
- ### Rails
44
+ ## Generators
45
+
46
+ The `provider` of the generator block picks the output. The options are optional unless a
47
+ section below says otherwise.
48
+
49
+ ### Validation schemas
50
+
51
+ - **`hekireki-zod`** writes [Zod](https://zod.dev/) schemas. `type` also exports the TypeScript
52
+ type of each schema, `relation` adds a schema for each relation, and `zod` picks the flavour:
53
+ `"v4"` (the default), `"mini"` or `"@hono/zod-openapi"`.
54
+ - **`hekireki-valibot`**, **`hekireki-arktype`**, **`hekireki-effect`**, **`hekireki-typebox`**
55
+ and **`hekireki-ajv`** write Valibot, ArkType, Effect Schema, TypeBox and AJV schemas, with the
56
+ same `type` and `relation` options.
57
+ - **`hekireki-pydantic`** writes Pydantic models, with `relation`.
58
+
59
+ ### ORM models
60
+
61
+ Every ORM generator stores a `DateTime` as Prisma Client stores it, so that the ORM and Prisma
62
+ read each other's rows alike. What that takes differs per ORM, and the sections further down say
63
+ what each one does and what is left to the caller.
64
+
65
+ - **`hekireki-drizzle`** writes Drizzle tables. See [Drizzle](#drizzle).
66
+ - **`hekireki-kysely`** writes the `DB` interface for Kysely. See [Kysely](#kysely).
67
+ - **`hekireki-sqlalchemy`** writes SQLAlchemy models.
68
+ - **`hekireki-django`** writes Django models. See [Django](#django).
69
+ - **`hekireki-activerecord`** writes Rails models. `locales` names the directory for translated
70
+ messages. See [Active Record](#active-record).
71
+ - **`hekireki-gorm`** writes GORM structs. `package` is the Go package name, `model` by default.
72
+ - **`hekireki-sea-orm`** writes SeaORM entities. `renameAll` is serde's `rename_all` for the
73
+ entities and enums (`"camelCase"`, for one). See [SeaORM](#seaorm).
74
+ - **`hekireki-ecto`** writes Ecto schemas. `app` is the application module the schemas live
75
+ under, `MyApp` by default. See [Ecto](#ecto).
76
+ - **`hekireki-eloquent`** writes Eloquent models. `namespace` is the PHP namespace, `App\Models`
77
+ by default.
78
+ - **`hekireki-efcore`** writes EF Core entities and a `DbContext`, on PostgreSQL, MySQL and SQLite.
79
+ `namespace` is the C# namespace, `Models` by default, and `context` the name of the context,
80
+ `AppDbContext` by default. See [EF Core](#ef-core).
81
+ - **`hekireki-exposed`** writes Exposed tables, on PostgreSQL. `package` is the Kotlin package,
82
+ `models` by default, and `dao` writes the DAO classes beside the tables unless set to `false`.
83
+ See [Exposed](#exposed).
84
+
85
+ ### Database and diagrams
86
+
87
+ - **`hekireki-atlas`** writes the schema as Atlas HCL. `schemaName` is the schema the tables go
88
+ in. See [Atlas](#atlas).
89
+ - **`hekireki-er`** draws the ER diagram. `outputs` lists the files to write, one rendering per
90
+ extension (`.md`, `.dbml`, `.png`, `.svg`), and `theme` is `light` or `dark`.
91
+ - **`hekireki-seed`** writes the schema module that `hekireki.config.ts` is typed against. See
92
+ [Seed](#seed).
93
+
94
+ ### Drizzle
95
+
96
+ On MySQL, `hekireki-drizzle` reads and writes a `@db.Timestamp` column as UTC, and MySQL converts
97
+ a `TIMESTAMP` through the connection's `time_zone`. Set it to `'+00:00'` on drizzle's connection,
98
+ as Prisma's adapter does on its own, or the two see times that differ by the offset.
99
+
100
+ On CockroachDB it writes the PostgreSQL schema, for node-postgres, and an `Int` key with
101
+ `@default(sequence())` is an identity column, as Prisma makes it. Keep the session's `TimeZone` at
102
+ UTC there, as on PostgreSQL, for a `dbgenerated("CURRENT_TIMESTAMP")` default to be UTC.
103
+
104
+ ### Kysely
105
+
106
+ `hekireki-kysely` writes one `DB` interface, each column typed as the driver of the datasource
107
+ reads and binds it: better-sqlite3 on SQLite, pg on PostgreSQL, mysql2 on MySQL. Kysely converts
108
+ nothing and runs no hook, so what the types cannot say is the caller's:
109
+
110
+ - On SQLite a `DateTime` is text, compared as text: write it as Prisma does,
111
+ `date.toISOString().replace('Z', '+00:00')`, or `=`, `@unique` and `@@id` do not meet Prisma's
112
+ rows. A `DateTime` with `now()` or a literal default is asked for on insert there, as Prisma
113
+ Client writes it itself: SQLite's own default is other text (`CURRENT_TIMESTAMP` sorts before
114
+ Prisma's rows, and Prisma reads the literal as an Invalid Date).
115
+ - pg and mysql2 read a column without a zone in the process's zone, Prisma in UTC: set pg's type
116
+ parsers 1114, 1082, 1115 and 1182 to UTC with `pg.defaults.parseInputDatesAsUTC = true`, and
117
+ give mysql2 `timezone: 'Z'`. MySQL refuses ISO text with a `Z`; write a `Date` or MySQL's
118
+ `2030-01-02 03:04:05.678901`.
119
+ - `@db.Time` and `@db.Timetz` are `string`, the time of day the drivers read.
120
+ - `@updatedAt` is asked for on insert, optional or not, and must be set on every update.
121
+
122
+ `examples/kysely` in the repository runs a schema against Kysely on SQLite.
123
+
124
+ ### Django
125
+
126
+ `hekireki-django` keeps a `DateTime` as Prisma Client keeps it:
127
+
128
+ - A column without a zone is declared with the `UtcDateTimeField` written into `models.py`. It
129
+ stores the UTC instant (on SQLite Prisma's text, `2030-01-02T03:04:05.678+00:00`) and reads it
130
+ back as UTC, aware under `USE_TZ = True` and in `TIME_ZONE` under `False`. A `@db.Timestamptz`
131
+ is Django's own field.
132
+ - `now()` is filled in by the model, in UTC (the UTC date or time on `@db.Date` and `@db.Time`),
133
+ and a literal default on a date or time column is its UTC date or time.
134
+ - An `@updatedAt` on a date or time column stamps the UTC date or time (`UtcDateField`,
135
+ `UtcTimeField`) where Django's `auto_now` would take the local one. A model with `@updatedAt`
136
+ is managed by `AutoNowQuerySet`, so `QuerySet.update()` bumps it as `updateMany` does.
137
+
138
+ Keep `USE_TZ = True`, Django's default: with `False`, Django sets a PostgreSQL session to
139
+ `TIME_ZONE`, and a `dbgenerated()` default such as `CURRENT_TIMESTAMP` is evaluated in that zone.
140
+
141
+ ### Active Record
98
142
 
99
143
  `hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
100
144
  per Prisma model, as a Rails developer would write them (and `prisma_date_time.rb` where a column
@@ -107,7 +151,9 @@ A `/// @ar.` line on a field is a validator (`presence`, `length(maximum: 255)`)
107
151
  field's `validates`; on a model it is a Ruby line written into the class as it is
108
152
  (`has_secure_password`, `has_many :tags, through: :post_tags`, `scope ...`). A message or name
109
153
  given per locale, `message: { ja: "...", en: "..." }` or `@ar.name(ja: "...")`, goes to
110
- `config/locales/models/<model>/<locale>.yml` under the key Rails reads.
154
+ `config/locales/models/<model>/<locale>.yml` under the key Rails reads. From `app/models` that
155
+ directory is the application's own; from anywhere else, `locales` has to name it, relative to
156
+ `output`.
111
157
 
112
158
  ```prisma
113
159
  generator Hekireki-ActiveRecord {
@@ -160,55 +206,65 @@ ja:
160
206
  The tables stay Prisma's to create, so set `config.active_record.migration_error = false` and
161
207
  create the test database with `prisma migrate deploy`.
162
208
 
163
- A `DateTime` is stored as Prisma Client stores it. Every `@updatedAt` column is bumped, not only
164
- the one aliased to `updated_at`. A column holding fewer than three digits of a second
165
- (`@db.Timestamp(0)`, MySQL's bare `@db.DateTime`) is sent Prisma's milliseconds for the database
166
- to round (`precision: 3`), where Active Record would cut them off first; a `@db.Timetz` column is
167
- read as a time, not a String (Active Record still warns `unknown OID 1266` once as it reads the
168
- table's columns, before the declared type takes over). On SQLite every `DateTime` column is
169
- declared with `PrismaDateTime`, which writes Prisma's text (`2030-01-02T03:04:05.678+00:00`) so
170
- that comparisons, unique indexes and ordering see both clients' rows alike; on SQL Server a
171
- `@db.DateTime` or `@db.SmallDateTime` column is, which sends milliseconds for the server to round
172
- to 1/300 s or to the minute as Prisma's are, where the adapter would round or cut them first. It is
173
- generated into `prisma_date_time.rb` beside the models, so Zeitwerk loads it from wherever it
174
- loads them, whatever `output` is. On SQLite and SQL Server, whose `CURRENT_TIMESTAMP` is text of
175
- another shape or the server's local time, `now()` is filled in by the model. Keep
176
- `config.active_record.default_timezone` at `:utc`, Rails' default: with `:local`, a `timestamp`
177
- column is written in the process's zone and Prisma reads it as UTC.
178
-
179
- `examples/active-record` in the repository
180
- runs a fuller schema against Active Record on SQLite, and is the place to read what each thing
181
- becomes.
209
+ A `DateTime` is stored as Prisma Client stores it:
210
+
211
+ - Every `@updatedAt` column is bumped, not only the one aliased to `updated_at`.
212
+ - A column holding fewer than three digits of a second (`@db.Timestamp(0)`, MySQL's bare
213
+ `@db.DateTime`) is sent Prisma's milliseconds for the database to round (`precision: 3`), where
214
+ Active Record would cut them off first.
215
+ - A `@db.Timetz` column is read as a time, not a String. Active Record still warns
216
+ `unknown OID 1266` once as it reads the table's columns, before the declared type takes over.
217
+ - On SQLite every `DateTime` column is declared with `PrismaDateTime`, which writes Prisma's text
218
+ (`2030-01-02T03:04:05.678+00:00`) so that comparisons, unique indexes and ordering see both
219
+ clients' rows alike. On SQL Server a `@db.DateTime` or `@db.SmallDateTime` column is too: it
220
+ sends milliseconds for the server to round to 1/300 s or to the minute as Prisma's are, where
221
+ the adapter would round or cut them first. The type is generated into `prisma_date_time.rb`
222
+ beside the models, so Zeitwerk loads it from wherever it loads them, whatever `output` is.
223
+ - On SQLite and SQL Server, whose `CURRENT_TIMESTAMP` is text of another shape or the server's
224
+ local time, `now()` is filled in by the model.
225
+
226
+ Keep `config.active_record.default_timezone` at `:utc`, Rails' default: with `:local`, a
227
+ `timestamp` column is written in the process's zone and Prisma reads it as UTC.
228
+
229
+ `examples/active-record` in the repository runs a fuller schema against Active Record on SQLite,
230
+ and is the place to read what each thing becomes.
182
231
 
183
232
  ### Ecto
184
233
 
185
234
  `hekireki-ecto` writes one `Ecto.Schema` module per model. A model with a `/// @ecto` line on it
186
- or on one of its fields also gets a `changeset/2`: `cast` of every field it can write,
187
- `validate_required` of the required fields Prisma gives no default, a `unique_constraint` for each
188
- `@unique` and `@@unique`, a `foreign_key_constraint` for each foreign key, and a
189
- `no_assoc_constraint` for each `has_one` or `has_many` whose rows the database will not let go of
190
- (`Restrict` or `NoAction` on delete, which Prisma makes of a required relation that names neither),
191
- so a refused delete is an error on the association. Each constraint is
192
- named as the database reports it: Prisma's `<table>_<columns>_key` and `_fkey`, cut to the
193
- database's limit in bytes as Prisma cuts them, or the `map:` given. On SQLite a unique key takes
194
- the name Ecto derives itself, and a foreign key gets no constraint, since SQLite names none when it
195
- refuses a row; with `relationMode = "prisma"` there is no foreign key in the database to report.
196
-
197
- A `/// @ecto.` line on a field is an `Ecto.Changeset` function that takes the field first, without
198
- the field: `validate_length(max: 50)`, or `validate_required(message: "...")` for a message of the
199
- field's own. `unique_constraint(message: "...")` on a `@unique` field and
235
+ or on one of its fields also gets a `changeset/2`:
236
+
237
+ - `cast` of every field it can write;
238
+ - `validate_required` of the required fields Prisma gives no default;
239
+ - a `unique_constraint` for each `@unique` and `@@unique`;
240
+ - a `foreign_key_constraint` for each foreign key;
241
+ - a `no_assoc_constraint` for each `has_one` or `has_many` whose rows the database will not let
242
+ go of (`Restrict` or `NoAction` on delete, which Prisma makes of a required relation that names
243
+ neither), so a refused delete is an error on the association.
244
+
245
+ Each constraint is named as the database reports it: Prisma's `<table>_<columns>_key` and
246
+ `_fkey`, cut to the database's limit in bytes as Prisma cuts them, or the `map:` given. On SQLite
247
+ a unique key takes the name Ecto derives itself, and a foreign key gets no constraint, since
248
+ SQLite names none when it refuses a row; with `relationMode = "prisma"` there is no foreign key in
249
+ the database to report.
250
+
251
+ A `/// @ecto.` line on a field is an `Ecto.Changeset` function that takes the field first, written
252
+ without the field: `validate_length(max: 50)`, or `validate_required(message: "...")` for a
253
+ message of the field's own. `unique_constraint(message: "...")` on a `@unique` field and
200
254
  `foreign_key_constraint(message: "...")` on a foreign key give the constraint its message. On a
201
255
  relation field, `assoc_constraint` (the side with the key) puts a missing row's error on the
202
256
  association, and `no_assoc_constraint(message: "...")` on a `has_one` or `has_many` gives a refused
203
- delete its message (or asks for one where the database cascades). On a model a line is a step of the pipeline written as it is
204
- (`validate_confirmation(:password)`), `unique_constraint([:a, :b], message: "...")` on the fields of
205
- a `@@unique` gives that constraint its message, `cast(empty_values: [])` hands its options to the
206
- changeset's `cast`, and a bare `/// @ecto` asks for the changeset with nothing added. With empty
207
- values of the model's own, `""` is a value, as it is to the column, so the required fields are
208
- checked by a `validate_not_null` written into the module, which counts only `nil` as missing
209
- (`validate_required` would count `""` too); a field's own `validate_required` line keeps Ecto's
210
- meaning. Ecto has no association for a foreign key of several columns, so the constraints of one
211
- are `foreign_key_constraint`s with the error on the relation's name.
257
+ delete its message (or asks for one where the database cascades).
258
+
259
+ On a model, a line is a step of the pipeline written as it is (`validate_confirmation(:password)`);
260
+ `unique_constraint([:a, :b], message: "...")` on the fields of a `@@unique` gives that constraint
261
+ its message; `cast(empty_values: [])` hands its options to the changeset's `cast`; and a bare
262
+ `/// @ecto` asks for the changeset with nothing added. With empty values of the model's own, `""`
263
+ is a value, as it is to the column, so the required fields are checked by a `validate_not_null`
264
+ written into the module, which counts only `nil` as missing (`validate_required` would count `""`
265
+ too); a field's own `validate_required` line keeps Ecto's meaning. Ecto has no association for a
266
+ foreign key of several columns, so the constraints of one are `foreign_key_constraint`s with the
267
+ error on the relation's name.
212
268
 
213
269
  ```prisma
214
270
  model User {
@@ -242,25 +298,33 @@ the module's documentation names the session time zone a `@db.Timestamptz`, `@db
242
298
 
243
299
  `examples/ecto` in the repository runs a schema against Ecto on SQLite.
244
300
 
245
- ### Kysely
301
+ ### Exposed
246
302
 
247
- `hekireki-kysely` writes one `DB` interface, each column typed as the driver of the datasource
248
- reads and binds it: better-sqlite3 on SQLite, pg on PostgreSQL, mysql2 on MySQL. Kysely converts
249
- nothing and runs no hook, so what the types cannot say is the caller's:
303
+ `hekireki-exposed` keeps a `DateTime` as Prisma Client keeps it, with no conversion through the
304
+ JVM's zone: an `Instant` bound and read as the UTC instant, to the millisecond (a finer value is
305
+ truncated, as a JavaScript Date holds it, in every native type), the UTC date of a `@db.Date`, the
306
+ UTC time of a `@db.Time`, and a `@db.Timetz` at offset zero.
250
307
 
251
- - On SQLite a `DateTime` is text, compared as text: write it as Prisma does,
252
- `date.toISOString().replace('Z', '+00:00')`, or `=`, `@unique` and `@@id` do not meet Prisma's
253
- rows. A `DateTime` with `now()` or a literal default is asked for on insert there, as Prisma
254
- Client writes it itself: SQLite's own default is other text (`CURRENT_TIMESTAMP` sorts before
255
- Prisma's rows, and Prisma reads the literal as an Invalid Date).
256
- - pg and mysql2 read a column without a zone in the process's zone, Prisma in UTC: set pg's type
257
- parsers 1114, 1082, 1115 and 1182 to UTC with `pg.defaults.parseInputDatesAsUTC = true`, and
258
- give mysql2 `timezone: 'Z'`. MySQL refuses ISO text with a `Z`; write a `Date`
259
- or MySQL's `2030-01-02 03:04:05.678901`.
260
- - `@db.Time` and `@db.Timetz` are `string`, the time of day the drivers read.
261
- - `@updatedAt` is asked for on insert, optional or not, and must be set on every update.
308
+ `now()`, literal defaults and every `@updatedAt` are filled in by the client on a DAO or DSL
309
+ insert, and the DAO bumps `@updatedAt` on update. A DSL `Table.update` has no such hook, so set it
310
+ there yourself: `it[updatedAt] = Instant.now()`.
262
311
 
263
- `examples/kysely` in the repository runs a schema against Kysely on SQLite.
312
+ pgjdbc sets the session to the JVM's zone, so open the connection in UTC, as Prisma's is, for a
313
+ `dbgenerated("CURRENT_TIMESTAMP")` default or `now()` in SQL:
314
+
315
+ ```kotlin
316
+ Database.connect(url, setupConnection = { it.createStatement().use { s -> s.execute("SET TIME ZONE 'UTC'") } })
317
+ ```
318
+
319
+ ### EF Core
320
+
321
+ `hekireki-efcore` stores a `DateTime` as Prisma Client does, whatever its `DateTimeKind`: the UTC
322
+ instant (a `Local` value converted), read back as `Utc`, in Prisma's text form on SQLite, and
323
+ `now()` filled in by EF Core rather than by the database's clock. It takes Npgsql's legacy
324
+ timestamp behaviour to be off.
325
+
326
+ On MySQL, compare a `@db.Time` column with a parameter rather than a constant:
327
+ MySql.EntityFrameworkCore writes a constant `TimeSpan` as `TIME '03:04:05'`, without its fraction.
264
328
 
265
329
  ### SeaORM
266
330
 
@@ -279,14 +343,22 @@ nothing and runs no hook, so what the types cannot say is the caller's:
279
343
 
280
344
  `examples/sea-orm` in the repository runs a schema against SeaORM on SQLite, PostgreSQL and MySQL.
281
345
 
346
+ ### Atlas
347
+
348
+ `hekireki-atlas` writes the tables as Prisma Migrate makes them, so that `atlas schema diff`
349
+ against a database Prisma made has nothing to change. Its `schemaName` is `public` unless given
350
+ (`main` on SQLite): on MySQL, where the schema is the database, give the database's name.
351
+
282
352
  ## Studio
283
353
 
284
354
  ```bash
285
- npx hekireki studio # `schema` of prisma.config.ts, else ./prisma/schema.prisma or ./schema.prisma, port 5555
355
+ npx hekireki studio
286
356
  npx hekireki studio --url file:./dev.db
287
357
  ```
288
358
 
289
- Your schema and database in the browser, on SQLite, PostgreSQL and MySQL.
359
+ Your schema and database in the browser, on SQLite, PostgreSQL and MySQL. Without flags, Studio
360
+ reads the `schema` of `prisma.config.ts`, else `./prisma/schema.prisma` or `./schema.prisma`, and
361
+ listens on port 5555.
290
362
 
291
363
  **Browse the rows** of each model: search, add, edit and export them.
292
364
 
@@ -316,6 +388,9 @@ npx hekireki seed # Through the project's Prisma Client
316
388
  npx hekireki seed --sql seed.sql # Or as a SQL script
317
389
  ```
318
390
 
391
+ The `hekireki-seed` generator writes a schema module; `hekireki.config.ts` imports it and is typed
392
+ against it, so each model's fields are known as the config is written.
393
+
319
394
  ```ts
320
395
  // hekireki.config.ts
321
396
  import { defineConfig } from 'hekireki'
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/activerecord.ts
4
4
  registerGenerator("activerecord");
5
5
  //#endregion
package/dist/bin/ajv.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/ajv.ts
4
4
  registerGenerator("ajv");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/arktype.ts
4
4
  registerGenerator("arktype");
5
5
  //#endregion
package/dist/bin/atlas.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/atlas.ts
4
4
  registerGenerator("atlas");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/django.ts
4
4
  registerGenerator("django");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/drizzle.ts
4
4
  registerGenerator("drizzle");
5
5
  //#endregion
package/dist/bin/ecto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/ecto.ts
4
4
  registerGenerator("ecto");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/efcore.ts
4
4
  registerGenerator("efcore");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/effect.ts
4
4
  registerGenerator("effect");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/eloquent.ts
4
4
  registerGenerator("eloquent");
5
5
  //#endregion
package/dist/bin/er.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/er.ts
4
4
  registerGenerator("er");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/exposed.ts
4
4
  registerGenerator("exposed");
5
5
  //#endregion
package/dist/bin/gorm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/gorm.ts
4
4
  registerGenerator("gorm");
5
5
  //#endregion
@@ -6,7 +6,7 @@ import { Console, Data, Effect, Schema } from "effect";
6
6
  import path from "node:path";
7
7
  import { CliError, Command, Flag } from "effect/cli";
8
8
  //#region package.json
9
- var version = "0.37.0";
9
+ var version = "0.39.0";
10
10
  //#endregion
11
11
  //#region src/schema/path.ts
12
12
  /** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
@@ -140,7 +140,7 @@ const studioFlags = {
140
140
  function runStudio(args) {
141
141
  return Effect.gen(function* () {
142
142
  const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
143
- const { startStudioServer } = yield* Effect.promise(() => import("../start-DCHq_ac3.js"));
143
+ const { startStudioServer } = yield* Effect.promise(() => import("../start-AZKmzv5G.js"));
144
144
  const started = yield* startStudioServer({
145
145
  schemaPath,
146
146
  port: args.port,
@@ -188,7 +188,7 @@ const seedFlags = {
188
188
  };
189
189
  function runSeedCommand(args) {
190
190
  return Effect.gen(function* () {
191
- const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-qU5ejzJJ.js"));
191
+ const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-C7QR2qhb.js"));
192
192
  const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
193
193
  yield* Console.log(seedBanner(report));
194
194
  });
@@ -231,7 +231,7 @@ function runMigrateCheckCommand(args) {
231
231
  "migrate",
232
232
  "check"
233
233
  ]);
234
- const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-DmUsB0Wq.js"));
234
+ const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-BS2daXFS.js"));
235
235
  const report = yield* runMigrateCheck({
236
236
  ...args,
237
237
  schemaPath,
@@ -278,7 +278,7 @@ function runMigratePlanCommand(args) {
278
278
  "migrate",
279
279
  "plan"
280
280
  ]);
281
- const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-DmUsB0Wq.js"));
281
+ const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-BS2daXFS.js"));
282
282
  const report = yield* runMigrateCheck({
283
283
  ...args,
284
284
  schemaPath,
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/kysely.ts
4
4
  registerGenerator("kysely");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/pydantic.ts
4
4
  registerGenerator("pydantic");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/sea-orm.ts
4
4
  registerGenerator("sea-orm");
5
5
  //#endregion
package/dist/bin/seed.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/seed.ts
4
4
  registerGenerator("seed");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/sqlalchemy.ts
4
4
  registerGenerator("sqlalchemy");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CVN0pzc4.js";
2
+ import { t as registerGenerator } from "../bin-BqUSO3tD.js";
3
3
  //#region src/bin/typebox.ts
4
4
  registerGenerator("typebox");
5
5
  //#endregion