hekireki 0.31.0 → 0.33.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.
- package/README.md +195 -98
- package/dist/bin/activerecord.js +1 -1
- package/dist/bin/ajv.js +1 -1
- package/dist/bin/arktype.js +1 -1
- package/dist/bin/atlas.js +1 -1
- package/dist/bin/django.js +1 -1
- package/dist/bin/drizzle.js +1 -1
- package/dist/bin/ecto.js +1 -1
- package/dist/bin/efcore.js +1 -1
- package/dist/bin/effect.js +1 -1
- package/dist/bin/eloquent.js +1 -1
- package/dist/bin/er.js +1 -1
- package/dist/bin/exposed.js +1 -1
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/hekireki.js +51 -75
- package/dist/bin/kysely.js +1 -1
- package/dist/bin/pydantic.js +1 -1
- package/dist/bin/sea-orm.js +1 -1
- package/dist/bin/seed.js +1 -1
- package/dist/bin/sqlalchemy.js +1 -1
- package/dist/bin/typebox.js +1 -1
- package/dist/bin/valibot.js +1 -1
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-CiVKUVYM.js → bin-BedDciI4.js} +4164 -1227
- package/dist/{discover-DVB1eehy.js → discover-C_OWaNiu.js} +1 -1
- package/dist/{emit-CdFQK71O.js → emit-BeblTVH8.js} +2 -2
- package/dist/{file-BPNqvwXD.js → file-Df9ykHXv.js} +1 -5
- package/dist/{migrate-B10ui4rh.js → migrate-CvfrvM4u.js} +4 -4
- package/dist/{plan-BDkcp2gn.js → plan-dRHRS5pw.js} +11 -8
- package/dist/{run-BMAnuiJ1.js → run-BKGjRYpT.js} +20 -17
- package/dist/{schema-B-2ni3YF.js → schema-RYU_i7qd.js} +2 -2
- package/dist/{sql-Bb3cwfJt.js → sql-MFsOi3_t.js} +3 -3
- package/dist/{start-BhcpaMcT.js → start-Crxh2c9d.js} +14 -17
- package/dist/studio/assets/{client-Cml1DF4R.js → client-DjOVdm86.js} +1 -1
- package/dist/studio/assets/{code-block-ON7BoQW2.js → code-block-Bo0pcw3d.js} +1 -1
- package/dist/studio/assets/{confirm-dialog-IdKC4Tr2.js → confirm-dialog-BQVcIkfP.js} +1 -1
- package/dist/studio/assets/{copy-D3Vc_bt4.js → copy-DVfEjDPw.js} +1 -1
- package/dist/studio/assets/{copy-button-CbaXuxba.js → copy-button-Di-sHQ2O.js} +1 -1
- package/dist/studio/assets/{dist-DmM7_t8o.js → dist-CebhqUaX.js} +5 -5
- package/dist/studio/assets/{docs-ExwrGDZu.js → docs-BpQXqPH3.js} +1 -1
- package/dist/studio/assets/{enums._name-C9BGV9--.js → enums._name-BufcpUnz.js} +1 -1
- package/dist/studio/assets/{index-ClVBmPHO.js → index-CXzs-Au7.js} +4 -4
- package/dist/studio/assets/{labels-C7nHuKvb.js → labels-DuphOVul.js} +1 -1
- package/dist/studio/assets/{lazyRouteComponent-CDmLrXMS.js → lazyRouteComponent-tS2t_LrD.js} +1 -1
- package/dist/studio/assets/{lu-BrVGIhAn.js → lu-cVORv6D3.js} +1 -1
- package/dist/studio/assets/{marked-text-BRnsKz9k.js → marked-text-DtpHRSKt.js} +1 -1
- package/dist/studio/assets/{models._name-ByPeXRmm.js → models._name-BNMTjU6P.js} +1 -1
- package/dist/studio/assets/{prisma-BnoDMkaK.js → prisma-CBc_VcSl.js} +1 -1
- package/dist/studio/assets/{result-table-CpErC1Pk.js → result-table-CrTPC-aR.js} +1 -1
- package/dist/studio/assets/{routes-CKzRT8uT.js → routes-B3m6jQHR.js} +1 -1
- package/dist/studio/assets/{schema-gate-B50_6S0h.js → schema-gate-BC3i18Tp.js} +1 -1
- package/dist/studio/assets/{schema-view-fqeCWRR2.js → schema-view-C427B7Jc.js} +1 -1
- package/dist/studio/assets/{sql-CRhtXB4v.js → sql-B3t2pCf4.js} +1 -1
- package/dist/studio/assets/{table-Rze42PM3.js → table-bAwthXaP.js} +1 -1
- package/dist/studio/assets/{tabs-ClImdGQ1.js → tabs-Bj63lLvK.js} +1 -1
- package/dist/studio/assets/{useFormValidation-Bgjs6o3Q.js → useFormValidation-B7STfHY3.js} +1 -1
- package/dist/studio/assets/{useMultipleSelectionState-DUiRXMUh.js → useMultipleSelectionState-vASeYbQk.js} +1 -1
- package/dist/studio/assets/{useOverlayTriggerState-2DwfYtnL.js → useOverlayTriggerState-BO95y8NP.js} +1 -1
- package/dist/studio/index.html +6 -6
- package/dist/{utils-Cgi66Lfo.js → utils-ckthTWS0.js} +38 -2
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -30,21 +30,61 @@ generator Hekireki-Zod {
|
|
|
30
30
|
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
31
31
|
| `hekireki-zod` | [Zod](https://zod.dev/) | `type`, `comment`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
|
|
32
32
|
| `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `comment`, `relation` |
|
|
33
|
-
| `hekireki-pydantic` | Pydantic | `
|
|
33
|
+
| `hekireki-pydantic` | Pydantic | `relation` |
|
|
34
34
|
| `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django` | Drizzle, Kysely, SQLAlchemy, Django | |
|
|
35
35
|
| `hekireki-activerecord` | Active Record | `locales` |
|
|
36
36
|
| `hekireki-gorm` | GORM | `package` |
|
|
37
37
|
| `hekireki-sea-orm` | SeaORM | `renameAll` |
|
|
38
38
|
| `hekireki-ecto` | Ecto | `app` |
|
|
39
39
|
| `hekireki-eloquent` | Eloquent | `namespace` |
|
|
40
|
-
| `hekireki-efcore` (PostgreSQL)
|
|
40
|
+
| `hekireki-efcore` (PostgreSQL, MySQL, SQLite) | EF Core | `namespace`, `context` |
|
|
41
41
|
| `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
|
|
42
|
-
| `hekireki-atlas` | Atlas HCL | `schemaName
|
|
42
|
+
| `hekireki-atlas` | Atlas HCL | `schemaName` |
|
|
43
43
|
| `hekireki-er` | ER diagram | `outputs` (`.md`, `.dbml`, `.png`, `.svg`), `theme` |
|
|
44
44
|
| `hekireki-seed` | The schema module `hekireki.config.ts` is typed against | |
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
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'") } })`.
|
|
85
|
+
|
|
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:
|
|
48
88
|
|
|
49
89
|
```prisma
|
|
50
90
|
model User {
|
|
@@ -56,60 +96,18 @@ model User {
|
|
|
56
96
|
|
|
57
97
|
### Rails
|
|
58
98
|
|
|
59
|
-
`hekireki-activerecord` writes `app/models`
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
What the model does carry: an `attribute` default for each literal `@default`, for `uuid()`,
|
|
72
|
-
`ulid()`, `cuid()`, `cuid(2)` and `nanoid()` (the `ulid`, `cuid`, `cuid2` and `nanoid` gems) and an
|
|
73
|
-
empty array for a list without one, as the Prisma client reads it; `implicit_order_column` on the
|
|
74
|
-
created timestamp when the primary key is random (`uuid()`, `cuid()`, `nanoid()`); `alias_attribute`
|
|
75
|
-
for a `createdAt` or `@updatedAt` column so Rails fills and bumps it as the Prisma client would;
|
|
76
|
-
`enum` with snake_case keys (`PENDING_REVIEW` gives `record.pending_review?` and the
|
|
77
|
-
`pending_review` scope, the stored value stays the database's), its `default:`, `prefix: true` when a
|
|
78
|
-
key is a method Ruby or Active Record already has, and `validate: true` so a value outside the enum
|
|
79
|
-
is a validation error rather than an `ArgumentError`; `dependent:` on every `has_many` and `has_one`
|
|
80
|
-
as the foreign key's `onDelete` acts (`Cascade` destroys, `SetNull` nullifies, `Restrict` and
|
|
81
|
-
`NoAction` refuse with an error); and validations from the columns: a required column without a
|
|
82
|
-
default is `presence` (`inclusion` in `[ true, false ]` for a `Boolean`, `exclusion` of `nil` for
|
|
83
|
-
`Json` and `Bytes`), `@unique` and `@@unique` are `uniqueness`, `@db.VarChar(n)` is `length`.
|
|
84
|
-
|
|
85
|
-
Validation stays in the model, as Active Record has it. A `/// @ar.` call on a field is one
|
|
86
|
-
validator on one `///` line, written as Rails spells it (`presence`, `length(maximum: 255)`), and
|
|
87
|
-
becomes an option of that field's `validates`, replacing the one the schema implied when it names
|
|
88
|
-
the same validator; a `/// @ar.` line on the model is written into the class as it is. A message
|
|
89
|
-
given per locale, `message: { ja: "...", en: "..." }` or `too_long: { ja: "...", en: "..." }`, is
|
|
90
|
-
not written into the model: it goes to `config/locales/models/todo/<locale>.yml` under the key the
|
|
91
|
-
[Rails i18n guide](https://guides.rubyonrails.org/i18n.html#error-message-scopes) lists for that
|
|
92
|
-
validator (`activerecord.errors.models.todo.attributes.title.blank`). `too_long` is a key already;
|
|
93
|
-
`message` stands for every key the validator can raise: `blank` for `presence`, all three of
|
|
94
|
-
`length`, and for `numericality` and `comparison` the keys of the options given
|
|
95
|
-
(`greater_than: 0` raises `greater_than`), so the one translation covers whichever fails. A locale's
|
|
96
|
-
value may be plural forms, `{ one: "...", other: "%{count} ..." }`, which I18n picks by `count`, and
|
|
97
|
-
`%{count}`, `%{value}`, `%{model}` and `%{attribute}` interpolate as Rails' own messages do.
|
|
98
|
-
`@ar.name(ja: "...", en: "...")` on a field or a model translates its name the same way
|
|
99
|
-
(`activerecord.attributes.todo.title`, `activerecord.models.todo`), plural forms included.
|
|
100
|
-
The files are laid out as the guide's
|
|
101
|
-
[organization of locale files](https://guides.rubyonrails.org/i18n.html#organization-of-locale-files)
|
|
102
|
-
has them, `models/<model>/<locale>.yml`, one directory per model and one file per locale it names,
|
|
103
|
-
so model and attribute names stay apart from the text of the views and from the defaults; Rails
|
|
104
|
-
loads `config/locales` through its subdirectories. `locales` names that directory; from
|
|
105
|
-
`app/models` it is `config/locales`. The comment has one shape: the description first, then the
|
|
106
|
-
`@ar.` calls, one to a `///` line. On a field each is `name` or `name(arguments)` with its
|
|
107
|
-
parentheses closed on that line; on the model each is a Ruby line as the class body would have it
|
|
108
|
-
(`validates :a, :b, presence: true`, `normalizes :title, with: ->(title) { title.strip }`), not
|
|
109
|
-
ending in a comma. A description line after a call, a call that runs on to the next `///` or a
|
|
110
|
-
call of another shape stops `prisma generate` with the model and field it is on. Rails joins attribute and message with a space (`errors.format`), which Japanese does not want: the
|
|
111
|
-
`rails-i18n` gem's `ja.yml` sets it to `%{attribute}%{message}`, and the generated files sit beside
|
|
112
|
-
it. Point `output` at `app/models`, and `todo.rb` is the model, nothing left to edit by hand:
|
|
99
|
+
`hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
|
|
100
|
+
per Prisma model, as a Rails developer would write them (and `prisma_date_time.rb` where a column
|
|
101
|
+
needs it). What Rails works out on its own (`table_name`, `class_name`, `foreign_key`,
|
|
102
|
+
`inverse_of` where the names follow its conventions) is left unsaid; what the schema promises is
|
|
103
|
+
written: `attribute` defaults, `enum`, timestamps, associations with `dependent:` from `onDelete`,
|
|
104
|
+
and validations from the columns (`presence`, `uniqueness`, `length`).
|
|
105
|
+
|
|
106
|
+
A `/// @ar.` line on a field is a validator (`presence`, `length(maximum: 255)`) added to that
|
|
107
|
+
field's `validates`; on a model it is a Ruby line written into the class as it is
|
|
108
|
+
(`has_secure_password`, `has_many :tags, through: :post_tags`, `scope ...`). A message or name
|
|
109
|
+
given per locale, `message: { ja: "...", en: "..." }` or `@ar.name(ja: "...")`, goes to
|
|
110
|
+
`config/locales/models/<model>/<locale>.yml` under the key Rails reads.
|
|
113
111
|
|
|
114
112
|
```prisma
|
|
115
113
|
generator Hekireki-ActiveRecord {
|
|
@@ -133,11 +131,6 @@ model Todo {
|
|
|
133
131
|
```
|
|
134
132
|
|
|
135
133
|
```ruby
|
|
136
|
-
# app/models/application_record.rb
|
|
137
|
-
class ApplicationRecord < ActiveRecord::Base
|
|
138
|
-
primary_abstract_class
|
|
139
|
-
end
|
|
140
|
-
|
|
141
134
|
# app/models/todo.rb
|
|
142
135
|
class Todo < ApplicationRecord
|
|
143
136
|
attribute :completed, default: false
|
|
@@ -164,43 +157,127 @@ ja:
|
|
|
164
157
|
too_long: '%{count}文字以内で入力してください'
|
|
165
158
|
```
|
|
166
159
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
The tables stay Prisma's to create, so set `config.active_record.migration_error = false` and
|
|
161
|
+
create the test database with `prisma migrate deploy`.
|
|
162
|
+
|
|
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.
|
|
182
|
+
|
|
183
|
+
### Ecto
|
|
184
|
+
|
|
185
|
+
`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
|
|
200
|
+
`foreign_key_constraint(message: "...")` on a foreign key give the constraint its message. On a
|
|
201
|
+
relation field, `assoc_constraint` (the side with the key) puts a missing row's error on the
|
|
202
|
+
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.
|
|
176
212
|
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
private
|
|
187
|
-
def switch_locale(&action)
|
|
188
|
-
locale = params[:locale] || I18n.default_locale
|
|
189
|
-
I18n.with_locale(locale, &action)
|
|
190
|
-
end
|
|
191
|
-
end
|
|
213
|
+
```prisma
|
|
214
|
+
model User {
|
|
215
|
+
id Int @id @default(autoincrement())
|
|
216
|
+
/// @ecto.validate_required(message: "名前を入力してください")
|
|
217
|
+
/// @ecto.validate_length(max: 50, message: "%{count}文字以内で入力してください")
|
|
218
|
+
name String
|
|
219
|
+
age Int?
|
|
220
|
+
email String? @unique
|
|
221
|
+
}
|
|
192
222
|
```
|
|
193
223
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
224
|
+
```elixir
|
|
225
|
+
def changeset(user, attrs) do
|
|
226
|
+
user
|
|
227
|
+
|> cast(attrs, [:name, :age, :email])
|
|
228
|
+
|> validate_required([:name], message: "名前を入力してください")
|
|
229
|
+
|> validate_length(:name, max: 50, message: "%{count}文字以内で入力してください")
|
|
230
|
+
|> unique_constraint(:email, name: "User_email_key")
|
|
231
|
+
end
|
|
200
232
|
```
|
|
201
233
|
|
|
202
|
-
|
|
203
|
-
|
|
234
|
+
A `DateTime` is kept as Prisma Client keeps it, through modules written alongside the schemas:
|
|
235
|
+
`PrismaDateTime` holds the instant in UTC in milliseconds (on SQLite the text Prisma writes,
|
|
236
|
+
`2030-01-01T09:00:00.000+00:00`, so an equality or a range finds Prisma's rows), `PrismaDate` a
|
|
237
|
+
`@db.Date` and `PrismaTime` a `@db.Time` or `@db.Timetz`. `now()` and `@updatedAt` are
|
|
238
|
+
`timestamps()` calls of those types. An optional `@updatedAt` is stored as null on insert only when
|
|
239
|
+
given by `Ecto.Changeset.force_change/3`, as a struct's `nil` is no change. On PostgreSQL and MySQL
|
|
240
|
+
the module's documentation names the session time zone a `@db.Timestamptz`, `@db.Timetz` or
|
|
241
|
+
`TIMESTAMP` column needs.
|
|
242
|
+
|
|
243
|
+
`examples/ecto` in the repository runs a schema against Ecto on SQLite.
|
|
244
|
+
|
|
245
|
+
### Kysely
|
|
246
|
+
|
|
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:
|
|
250
|
+
|
|
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.
|
|
262
|
+
|
|
263
|
+
`examples/kysely` in the repository runs a schema against Kysely on SQLite.
|
|
264
|
+
|
|
265
|
+
### SeaORM
|
|
266
|
+
|
|
267
|
+
`hekireki-sea-orm` writes one entity per model into a directory, with a `mod.rs` and a
|
|
268
|
+
`prelude.rs`. A `DateTime` is kept as Prisma Client keeps it:
|
|
269
|
+
|
|
270
|
+
- `now()`, `@updatedAt` and a literal default are filled by `ActiveModelBehavior::before_save`, in
|
|
271
|
+
UTC with milliseconds, so the crate needs `chrono` and `async-trait` beside `sea-orm`.
|
|
272
|
+
- On SQLite every `DateTime` is a `PrismaDateTime` (written into `prisma_date_time.rs`), which
|
|
273
|
+
binds Prisma's text, `2030-01-02T03:04:05.000+00:00`: filter with
|
|
274
|
+
`Column::At.eq(PrismaDateTime(instant))`, not a bare `DateTimeUtc`, which sqlx writes without
|
|
275
|
+
the `.000` of a whole second.
|
|
276
|
+
- On PostgreSQL and MySQL a `DateTime` is a `NaiveDateTime` in UTC, `@db.Timestamptz` a
|
|
277
|
+
`DateTimeWithTimeZone`, a MySQL `@db.Timestamp` a `DateTimeUtc`. `@db.Timetz` is refused: sqlx
|
|
278
|
+
has no type to read it into.
|
|
279
|
+
|
|
280
|
+
`examples/sea-orm` in the repository runs a schema against SeaORM on SQLite, PostgreSQL and MySQL.
|
|
204
281
|
|
|
205
282
|
## Studio
|
|
206
283
|
|
|
@@ -209,8 +286,28 @@ npx hekireki studio # ./prisma/schema.prisma or ./schema.prisma
|
|
|
209
286
|
npx hekireki studio --url file:./dev.db
|
|
210
287
|
```
|
|
211
288
|
|
|
212
|
-
|
|
213
|
-
|
|
289
|
+
Your schema and database in the browser, on SQLite, PostgreSQL and MySQL.
|
|
290
|
+
|
|
291
|
+
**Browse the rows** of each model: search, add, edit and export them.
|
|
292
|
+
|
|
293
|
+

|
|
294
|
+
|
|
295
|
+
**Run SQL** with completion from the schema. The ER diagram marks the tables a statement reads,
|
|
296
|
+
and the result comes with the TypeScript types of its rows.
|
|
297
|
+
|
|
298
|
+

|
|
299
|
+
|
|
300
|
+
**Try Prisma Client calls** and see the SQL each one sends.
|
|
301
|
+
|
|
302
|
+

|
|
303
|
+
|
|
304
|
+
**Edit the schema** beside its ER diagram, which follows the file as it changes.
|
|
305
|
+
|
|
306
|
+

|
|
307
|
+
|
|
308
|
+
**Read the docs** of every model: its fields, and an example of each operation.
|
|
309
|
+
|
|
310
|
+

|
|
214
311
|
|
|
215
312
|
## Seed
|
|
216
313
|
|
package/dist/bin/activerecord.js
CHANGED
package/dist/bin/ajv.js
CHANGED
package/dist/bin/arktype.js
CHANGED
package/dist/bin/atlas.js
CHANGED
package/dist/bin/django.js
CHANGED
package/dist/bin/drizzle.js
CHANGED
package/dist/bin/ecto.js
CHANGED
package/dist/bin/efcore.js
CHANGED
package/dist/bin/effect.js
CHANGED
package/dist/bin/eloquent.js
CHANGED
package/dist/bin/er.js
CHANGED
package/dist/bin/exposed.js
CHANGED
package/dist/bin/gorm.js
CHANGED