@expressive/sql 0.11.0 → 0.13.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/CHANGELOG.md +324 -0
- package/README.md +1 -1
- package/dist/bin.d.ts +2 -1
- package/dist/bin.js +18 -3
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +20 -3
- package/dist/cli.js +74 -57
- package/dist/cli.js.map +1 -1
- package/dist/connection/Connection.js +1 -1
- package/dist/connection/Connection.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/sqlite/SQLiteConnection.d.ts +26 -2
- package/dist/sqlite/SQLiteConnection.js +92 -17
- package/dist/sqlite/SQLiteConnection.js.map +1 -1
- package/dist/sqlite/SQLiteGenerator.d.ts +7 -4
- package/dist/sqlite/SQLiteGenerator.js +11 -3
- package/dist/sqlite/SQLiteGenerator.js.map +1 -1
- package/dist/sqlite/engine.d.ts +1 -1
- package/dist/sqlite/engine.js +1 -1
- package/dist/sqlite/engine.js.map +1 -1
- package/package.json +8 -6
- package/skills/expressive-sql/SKILL.md +12 -7
- package/dist/dispatch.d.ts +0 -6
- package/dist/dispatch.js +0 -44
- package/dist/dispatch.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# @expressive/sql
|
|
2
|
+
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#85](https://github.com/gabeklein/expressive-orm/pull/85) [`95fbe6b`](https://github.com/gabeklein/expressive-orm/commit/95fbe6bb05b9b03d7fab5b66359881c5010a2d28) `db.session(fn, source)` runs every statement inside on `source` - a D1 binding, a libSQL client or an `Engine` - with its own identity map, so a Worker can run each request on that request's binding without swapping the connection's engine.
|
|
8
|
+
|
|
9
|
+
`sync`, or awaiting the connection, inside a session on a source other than the connection's own rejects - sync from a deploy step.
|
|
10
|
+
|
|
11
|
+
- [#92](https://github.com/gabeklein/expressive-orm/pull/92) [`1ee58d4`](https://github.com/gabeklein/expressive-orm/commit/1ee58d4b607af3edcf3f8fdabf8c8c58fabefd35) `SQLiteConnection.new(types, options)` takes the source in options - `{ source, timestamps }` - or a filename or address string as before. A D1 binding, libSQL client or `Engine` moves into `{ source }`: `new(types, env.DB)` becomes `new(types, { source: env.DB })`, and `new(types, source, { timestamps })` becomes `new(types, { source, timestamps })`. Any other object in its place, or a third argument, throws instead of being misread.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#89](https://github.com/gabeklein/expressive-orm/pull/89) [`7f58539`](https://github.com/gabeklein/expressive-orm/commit/7f58539bc120268aa6b8f0953232c9f4c17904fd) A nullability mismatch names both sides - `Column title in table post allows NULL, but Post.title is required` - in place of `has incorrect nullable value`.
|
|
16
|
+
|
|
17
|
+
- [#81](https://github.com/gabeklein/expressive-orm/pull/81) [`dd1d90c`](https://github.com/gabeklein/expressive-orm/commit/dd1d90c006305e824e1b48f75585856460b16561) Declare the packages free of side effects, so a bundle importing only entities from `@expressive/sql` or `@expressive/postgres` drops SQLite, Postgres and `sql-formatter` - it matches importing the same names from `@expressive/orm`.
|
|
18
|
+
|
|
19
|
+
- [#75](https://github.com/gabeklein/expressive-orm/pull/75) [`0c262b3`](https://github.com/gabeklein/expressive-orm/commit/0c262b3bed35a4f70d469d8b568bcef01a642355) **`expressive sql` is built on `@expressive/cli`.** `--help` works at every level, `sync -f` is short for `--force`, and usage errors name the problem - a missing or nonexistent entry, an unknown command or option.
|
|
20
|
+
|
|
21
|
+
- [#80](https://github.com/gabeklein/expressive-orm/pull/80) [`cc010a9`](https://github.com/gabeklein/expressive-orm/commit/cc010a9c6d05aeb9887fcff8e765c898eb9c82d7) The `expressive` bin is the shared command `@expressive/dev` also ships: whichever package links the bin runs both `expressive sql` and `expressive dev`, and lists the other as not installed when it is missing. `expressive sql` alone, or `expressive sql help`, prints help.
|
|
22
|
+
- Updated dependencies [[`7c69ac6`](https://github.com/gabeklein/expressive-orm/commit/7c69ac699a94f3586b20db5cff161f1298640692), [`dd1d90c`](https://github.com/gabeklein/expressive-orm/commit/dd1d90c006305e824e1b48f75585856460b16561)]:
|
|
23
|
+
- @expressive/orm@0.22.0
|
|
24
|
+
|
|
25
|
+
## 0.12.0
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- [#78](https://github.com/gabeklein/expressive-orm/pull/78) [`3a60a89`](https://github.com/gabeklein/expressive-orm/commit/3a60a895b1e2418fec9d4b41dfbd18b74a9dfb7b) SQLite stores a `timestamp` as INTEGER epoch milliseconds again, and the connection chooses: `SQLiteConnection.new(types, source, { timestamps })` takes `"ms"` (default), `"seconds"` or `"iso"` (ISO 8601 UTC text). `sql.now` in a `Query` or comparison, and a `fallback: sql.now` column default, render in the connection's storage, so `lessThan(sql.now)` and `date.created()` are right on an integer column. `sync`, `plan` and `expressive sql check` refuse a timestamp column declared the other way - INTEGER under `"iso"`, TEXT under `"ms"` - naming the option that keeps it, where before they reported plain type drift and `sync --force` would cast epoch numbers to unreadable text. `date` and `time` types stay text. Published packages now include `CHANGELOG.md`.
|
|
30
|
+
|
|
31
|
+
**Breaking:** a SQLite or D1 database created by 0.6 through 0.11 keeps timestamps as ISO text; `sync` now refuses it until you pass `{ timestamps: "iso" }` or migrate the columns.
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [[`3a60a89`](https://github.com/gabeklein/expressive-orm/commit/3a60a895b1e2418fec9d4b41dfbd18b74a9dfb7b)]:
|
|
36
|
+
- @expressive/orm@0.21.1
|
|
37
|
+
|
|
38
|
+
## 0.11.0
|
|
39
|
+
|
|
40
|
+
### Minor Changes
|
|
41
|
+
|
|
42
|
+
- [#73](https://github.com/gabeklein/expressive-orm/pull/73) [`4c19f4b`](https://github.com/gabeklein/expressive-orm/commit/4c19f4b25a643b3e5526bd7552ffcd3545ff0809) `Remote` requests carry a format version, `v: 1`, and `Remote.handle` refuses with a `Remote.Error` whose `code` says why: `version`, `malformed`, `unknown`, `invalid` or `failed`. Failures past validation still read `Request failed.`, with the original as `cause`; errors thrown by `check` pass through.
|
|
43
|
+
|
|
44
|
+
**Breaking:** a server on this version refuses requests without `v` - those from a 0.20 `Remote` client - with code `version`. Update client and server together.
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [[`4c19f4b`](https://github.com/gabeklein/expressive-orm/commit/4c19f4b25a643b3e5526bd7552ffcd3545ff0809)]:
|
|
49
|
+
- @expressive/orm@0.21.0
|
|
50
|
+
|
|
51
|
+
## 0.10.0
|
|
52
|
+
|
|
53
|
+
### Minor Changes
|
|
54
|
+
|
|
55
|
+
- [#69](https://github.com/gabeklein/expressive-orm/pull/69) [`b9a1b16`](https://github.com/gabeklein/expressive-orm/commit/b9a1b164559577122bb9f1b134f9b4792dcecadd) A class bound as an object - `Connection.new({ User, Post })` - takes its default table name from its key, in snake case. Keys survive minification where class names don't, so a bundled app keeps its tables without `static table`. An explicit `static table` still wins, and an array binds as before. A class listed twice now throws.
|
|
56
|
+
|
|
57
|
+
**Breaking:** an object whose key differs from the class name - `{ users: User }` - now reads and writes table `users` where it used `user`. `sync` would create the new table empty. Set `static table = "user"` to keep the old one.
|
|
58
|
+
|
|
59
|
+
- [#70](https://github.com/gabeklein/expressive-orm/pull/70) [`7adc7a0`](https://github.com/gabeklein/expressive-orm/commit/7adc7a034d0fc4d6e5d7a9eee8f54ff63df69495) `Remote` - a connection forwarding every read and write through a function you give it, to `Remote.handle(connection, options)` on a server. Requests name classes by the key they are bound under and fields by property, never table or column, so the server alone decides storage. The server validates each request and runs it as the class's own statics would, and masks failures past validation as `Request failed.`; `expose` names the classes and properties served and `check` authorizes each request with a context you pass. Reads, inserts, writes by id, relations and instance writes travel; `count`, writes by filter, `Query`, transactions and live rows don't.
|
|
60
|
+
|
|
61
|
+
SQL generation now refuses an unknown operator, sort order, or a limit or offset that isn't a whole number. A failed SQLite statement over 4KB is reported unformatted. Ordering by, or matching null on, a required relation no longer throws.
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [[`b9a1b16`](https://github.com/gabeklein/expressive-orm/commit/b9a1b164559577122bb9f1b134f9b4792dcecadd), [`7adc7a0`](https://github.com/gabeklein/expressive-orm/commit/7adc7a034d0fc4d6e5d7a9eee8f54ff63df69495)]:
|
|
66
|
+
- @expressive/orm@0.20.0
|
|
67
|
+
|
|
68
|
+
## 0.9.1
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- [#64](https://github.com/gabeklein/expressive-orm/pull/64) [`e38054e`](https://github.com/gabeklein/expressive-orm/commit/e38054e27400a618b31b5f0f7845f2be3cc54cac) Agent skills checked against the source: test setup on `Memory` and how classes join the last connection, persisted `Memory`, React Native, forcing a sync, the CLI entry, Postgres `sync(false)` and `static schema`, and corrections to `timezone`, `one(id)` and `static schema`. `Connection`'s JSDoc is attached to the class again.
|
|
73
|
+
- Updated dependencies [[`2ddee0c`](https://github.com/gabeklein/expressive-orm/commit/2ddee0c5d766eb48e4d992cfdfc22fc34f3ec550), [`d8a845d`](https://github.com/gabeklein/expressive-orm/commit/d8a845d97914029de95998b4731d34c57720b440), [`e38054e`](https://github.com/gabeklein/expressive-orm/commit/e38054e27400a618b31b5f0f7845f2be3cc54cac)]:
|
|
74
|
+
- @expressive/orm@0.19.0
|
|
75
|
+
|
|
76
|
+
## 0.9.0
|
|
77
|
+
|
|
78
|
+
### Minor Changes
|
|
79
|
+
|
|
80
|
+
- [#54](https://github.com/gabeklein/expressive-orm/pull/54) [`3ff4f2b`](https://github.com/gabeklein/expressive-orm/commit/3ff4f2b7cc5086e0740780398db410e88a8dcad0) Breaking: `Type.one(where?, expect?)` resolves the live entity, loaded as `load(where, 1)` - a loaded entity settles the fetched row and is returned as is. It takes a filter only; `get(id)` covers ids, and an id throws. `Type.find` is now `Type.query(where?, limit?, offset?)`, still resolving frozen rows through the driver's `select` alone; `query(callback)` stays the `Query` builder, and `query()` without arguments now reads rows rather than building a `Query`. `rows()` handles follow: `find` is `query`, and `one` resolves an entity.
|
|
81
|
+
|
|
82
|
+
`date.created()` marks the class's recency. Without a filter - `{}` and all-`undefined` filters included - `query`, `load` and `one` take the newest first by it then by `id`, else by an incrementing `id`, else unordered - and `one()` without a filter then throws asking for one. A second `created()` on one class throws.
|
|
83
|
+
|
|
84
|
+
- [#56](https://github.com/gabeklein/expressive-orm/pull/56) [`d946b59`](https://github.com/gabeklein/expressive-orm/commit/d946b597a91d1f4219aee47301d6b9adea29c563) Breaking: `Type.all(pageSize, where?)` is gone - use `query(where, pageSize)`, arguments swapped. `query(where, limit, offset?)` with a numeric `limit` now returns `Type.Results` rather than a plain `Promise<Columns[]>`: it resolves its first `limit` rows when awaited and, iterated with `for await`, yields every match `limit` rows per select. A `limit` typed `number | undefined` resolves rows. A limit of `0` reads every match in one batch. `rows()` handles follow.
|
|
85
|
+
|
|
86
|
+
A read with a limit is always totally ordered: the filter's `asc()` / `desc()`, else the class's newest first, then by id. Every limited select now carries an `ORDER BY` - `one`, `load(where, limit)` and the by-id load behind `get` included. `one({ ... })` now resolves the newest match rather than any.
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- Updated dependencies [[`3ff4f2b`](https://github.com/gabeklein/expressive-orm/commit/3ff4f2b7cc5086e0740780398db410e88a8dcad0), [`d946b59`](https://github.com/gabeklein/expressive-orm/commit/d946b597a91d1f4219aee47301d6b9adea29c563)]:
|
|
91
|
+
- @expressive/orm@0.18.0
|
|
92
|
+
|
|
93
|
+
## 0.8.3
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- Updated dependencies [[`5e6ac69`](https://github.com/gabeklein/expressive-orm/commit/5e6ac69fd0980879590d6d0bf7dddd00fed76615), [`9f0596d`](https://github.com/gabeklein/expressive-orm/commit/9f0596dfa3f9c3921f1f440aa49e88ffa37d48ec)]:
|
|
98
|
+
- @expressive/orm@0.17.0
|
|
99
|
+
|
|
100
|
+
## 0.8.2
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- Updated dependencies [[`da081bd`](https://github.com/gabeklein/expressive-orm/commit/da081bd0ed401965f6ec097099034022adb6e215)]:
|
|
105
|
+
- @expressive/orm@0.16.0
|
|
106
|
+
|
|
107
|
+
## 0.8.1
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- [#49](https://github.com/gabeklein/expressive-orm/pull/49) [`8d351b8`](https://github.com/gabeklein/expressive-orm/commit/8d351b81030922a9135f779f94af6baae37d475f) **`@expressive/sql` bundles under Metro for iOS and Android.** The SQLite driver loader sits in its own module, which a `react-native` package field swaps for one that loads nothing, so Metro no longer rejects its dynamic `import()`. On React Native, pass an `Engine` in place of a filename; a filename or libSQL address rejects, asking for one. Expo web and Expo Router server bundles still do not bundle `@expressive/sql`.
|
|
112
|
+
- Updated dependencies [[`8d351b8`](https://github.com/gabeklein/expressive-orm/commit/8d351b81030922a9135f779f94af6baae37d475f)]:
|
|
113
|
+
- @expressive/orm@0.15.1
|
|
114
|
+
|
|
115
|
+
## 0.8.0
|
|
116
|
+
|
|
117
|
+
### Minor Changes
|
|
118
|
+
|
|
119
|
+
- [#51](https://github.com/gabeklein/expressive-orm/pull/51) [`8905fb4`](https://github.com/gabeklein/expressive-orm/commit/8905fb4a3553437e2ac3d7c3e33e564c7a46cd55) Fields declare portable datatypes and connections own storage. A field checks plain values the same on every side - integer ranges, decimal precision and scale, string length - and a connection takes and returns them, Dates and JSON values included, storing them through codecs chosen by the field's base helper (`Connection.Codec`, a protected `codecs` getter). One schema module importing only `@expressive/orm` binds to SQLite, D1, Postgres, `memory()` or a connection forwarding to a server, and the SQL floor checks forwarded values again before storing them. `Connection.new` throws for a field the connection can't store.
|
|
120
|
+
|
|
121
|
+
Breaking: orm declares the portable types - `str` text, varchar, char, uuid; `num` integer (now the default everywhere), smallint, bigint, real, double, decimal, numeric; `date` timestamp, date, time, with `timezone`; `bool` boolean. Storage-only types are dropped - `date` ms, seconds, integer and text, `num` float, `bool` with `either`, `one` integer and bigint (a relation takes its key's type), Postgres `serial` and `interval` - with their `sql.*` tokens. The column classes and `X.Type` hooks are gone (`StringColumn`, `NumericColumn`, `BooleanColumn`, `TimeColumn`, `ForeignColumn`); `@expressive/sql` exports `codecs` instead. `Field.datatype` is gone. `memory()` stores values as given.
|
|
122
|
+
|
|
123
|
+
Every helper gains `.and(...presets)`, returning the same helper with those options first; `date.created` and `date.updated` are presets of `date`.
|
|
124
|
+
|
|
125
|
+
A `date({ type: "date" })` column is a calendar day, not an instant: a Date gives its local day, a `"YYYY-MM-DD"` string is that day, and it reads as local midnight. It crosses every connection and is stored as `YYYY-MM-DD`, so a client and server in different time zones agree.
|
|
126
|
+
|
|
127
|
+
- [#50](https://github.com/gabeklein/expressive-orm/pull/50) [`f5cafff`](https://github.com/gabeklein/expressive-orm/commit/f5cafff8d048e390a48dd6c67315ccdc2496e464) `Type.load(where?, limit?, offset?)` resolves live entities for a filter in one select, reusing and settling loaded ones; `rows()` handles gain `load`. `connection.before(Type, { delete(row) })` gates a delete by id - a throw cancels it - and `connection.after(Type, { delete(row) })` runs best-effort effects once it is done: awaited, errors logged rather than thrown, after commit inside a transaction. Each returns a remover.
|
|
128
|
+
|
|
129
|
+
### Patch Changes
|
|
130
|
+
|
|
131
|
+
- Updated dependencies [[`8905fb4`](https://github.com/gabeklein/expressive-orm/commit/8905fb4a3553437e2ac3d7c3e33e564c7a46cd55), [`f5cafff`](https://github.com/gabeklein/expressive-orm/commit/f5cafff8d048e390a48dd6c67315ccdc2496e464)]:
|
|
132
|
+
- @expressive/orm@0.15.0
|
|
133
|
+
|
|
134
|
+
## 0.7.0
|
|
135
|
+
|
|
136
|
+
### Minor Changes
|
|
137
|
+
|
|
138
|
+
- [#36](https://github.com/gabeklein/expressive-orm/pull/36) [`7024b85`](https://github.com/gabeklein/expressive-orm/commit/7024b85d4386b1aad9f238543926d1b1dd5980d9) **`SQLiteConnection` runs on Cloudflare D1 and libSQL (Turso).** In place of a filename it takes a D1 binding, a libSQL client, or a `libsql:`, `https:`, `http:`, `ws:` or `wss:` address, which opens `@libsql/client` and reads a token from `?authToken=`. D1 applies `sync` as one batch, refuses `transaction`, and refuses a rebuild since it keeps foreign keys on. Every libSQL client, the built-in loader's included, runs each `transaction` on a libSQL write transaction, applies `sync` as one batch and rebuilds a table through `migrate`; schema checks inside a transaction run on it. The `@libsql/client` peer is now `>=0.18.0` - older clients lose an in-memory database on its first transaction. A table created by `sync` now plans its indexes as statements of their own, so a batch that runs one statement per entry creates them.
|
|
139
|
+
|
|
140
|
+
## 0.6.0
|
|
141
|
+
|
|
142
|
+
### Minor Changes
|
|
143
|
+
|
|
144
|
+
- [#40](https://github.com/gabeklein/expressive-orm/pull/40) [`1d1dbb5`](https://github.com/gabeklein/expressive-orm/commit/1d1dbb55f3b0cccb2049d41035aa31f7772ed65e) **`Generator` exposes protected hooks for dialects.** `literal(value)` renders every literal in values, `SET` and `WHERE`; `insertWith(cte, into, select)` places a data CTE in an insert; `table(table)` renders a table with its alias for `FROM`, joins, `UPDATE` and `DELETE`. A schema-qualified table's alias is now quoted everywhere, fixing Postgres queries and updates that aliased one.
|
|
145
|
+
|
|
146
|
+
- [#47](https://github.com/gabeklein/expressive-orm/pull/47) [`9cf9cde`](https://github.com/gabeklein/expressive-orm/commit/9cf9cde5a0b5e74c8f514e44ee68a88d7cb63f03) Driver seams move to `@expressive/orm/driver`: `Builder`, `Where`, `Computed`, `DataField`, `DataTable`, `Parameter` and `QueryTemplate`. The root entry - and `@expressive/sql`'s, which re-exports it - keeps the app API. `Where` stays on the root as a type. A driver imports these, and `evaluate`, from `@expressive/orm/driver`.
|
|
147
|
+
|
|
148
|
+
- [#41](https://github.com/gabeklein/expressive-orm/pull/41) [`4f3e23c`](https://github.com/gabeklein/expressive-orm/commit/4f3e23c9e75cd4f9dc65e7ebda02577829e4d0d1) **`memory()` runs transactions, and every driver gets them from `@expressive/orm`.** `transaction(fn)`, the connection lock (`lock()`, `idle()`) and the journal that restores instances move from `@expressive/sql`'s `Connection` to `@expressive/orm`'s, over a protected `transact(fn)` hook, so a driver without SQL implements `transact` and nothing else. On `memory()` a rollback restores every table and the next id, subscribers hear of changes once a transaction commits, and statements from outside an open transaction wait for it. Like the SQL drivers, it needs `AsyncLocalStorage` and throws without it.
|
|
149
|
+
|
|
150
|
+
- [#39](https://github.com/gabeklein/expressive-orm/pull/39) [`0c5d036`](https://github.com/gabeklein/expressive-orm/commit/0c5d03630311ccbcbfa29515537577ad509ecaac) **SQLite engines can bring their own transactions and batches.** An `Engine` may implement `transaction()`, returning a session whose statements, `commit` and `rollback` back `transaction(fn)`, and `batch(sql)`, through which `sync` applies atomically. A batched rebuild turns foreign keys off around it and is refused where the engine keeps them on. A failed rollback no longer hides the error that caused it.
|
|
151
|
+
|
|
152
|
+
- [#34](https://github.com/gabeklein/expressive-orm/pull/34) [`7603ed0`](https://github.com/gabeklein/expressive-orm/commit/7603ed0b12d4305c34adc1cca5b0126dcdde01ee) **`SQLiteConnection` takes an engine.** `new SQLiteConnection(types, engine)` runs on any object implementing the exported `Engine` type (`all`, `get`, `run`, `exec`, `close`), for a SQLite the built-in loader can't open. A filename still selects the built-in engine. A given engine is used as is and left open by `close()`.
|
|
153
|
+
|
|
154
|
+
### Patch Changes
|
|
155
|
+
|
|
156
|
+
- [#46](https://github.com/gabeklein/expressive-orm/pull/46) [`acd61f1`](https://github.com/gabeklein/expressive-orm/commit/acd61f112e38d330fe7c990e974bf6595a59699a) Document the public API in JSDoc, so hovers and completions carry each symbol's contract, and correct the agent skills against the source: `json()` takes one option, relation writes insert an object without `id`, `where(Other)` needs a join condition on SQL, `num()` is a 32-bit integer on SQL, default ordering of `find()` and `one()`, and an error table.
|
|
157
|
+
|
|
158
|
+
- [#44](https://github.com/gabeklein/expressive-orm/pull/44) [`567a398`](https://github.com/gabeklein/expressive-orm/commit/567a3982aeea543aeadec8d9529b836187671330) Ship each package's agent skill in the package, at `skills/expressive-<pkg>/SKILL.md`, so the docs an agent reads match the installed version. Agents read them from `node_modules/@expressive/<pkg>/skills/` - point one there with a line in `AGENTS.md`, or `npx skills add gabeklein/expressive`.
|
|
159
|
+
- Updated dependencies [[`7603ed0`](https://github.com/gabeklein/expressive-orm/commit/7603ed0b12d4305c34adc1cca5b0126dcdde01ee), [`acd61f1`](https://github.com/gabeklein/expressive-orm/commit/acd61f112e38d330fe7c990e974bf6595a59699a), [`9cf9cde`](https://github.com/gabeklein/expressive-orm/commit/9cf9cde5a0b5e74c8f514e44ee68a88d7cb63f03), [`4f3e23c`](https://github.com/gabeklein/expressive-orm/commit/4f3e23c9e75cd4f9dc65e7ebda02577829e4d0d1), [`567a398`](https://github.com/gabeklein/expressive-orm/commit/567a3982aeea543aeadec8d9529b836187671330), [`acd61f1`](https://github.com/gabeklein/expressive-orm/commit/acd61f112e38d330fe7c990e974bf6595a59699a)]:
|
|
160
|
+
- @expressive/orm@0.14.0
|
|
161
|
+
|
|
162
|
+
## 0.5.0
|
|
163
|
+
|
|
164
|
+
### Minor Changes
|
|
165
|
+
|
|
166
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`23f442c`](https://github.com/gabeklein/expressive-orm/commit/23f442c449927b10c9fb9b240eaa5161e6a01672) **Datatypes as modifiers.** `sql.*` names a column's datatype, with factories for sized ones: `num(sql.bigint, null)`, `str(sql.varchar(120), unique)`, `num(sql.decimal(10, 2))`. A datatype of another helper, like `num(sql.text)`, is a type error. `@expressive/postgres` adds `sql.serial`, `sql.timestamptz`, `sql.timetz` and `sql.interval`. `unique` and `index` join `optional` as modifiers; `null` replaces `orNull`, which is deprecated.
|
|
167
|
+
|
|
168
|
+
**Indexes.** `index`, or `{ index: "name" }`, makes `sync` create a missing index, named `<table>_<column>` by default. On SQLite an existing single-column index on the column counts.
|
|
169
|
+
|
|
170
|
+
**`key()` declares any id.** `key()` is an incrementing integer, typed `number`; `key(sql.text, { column: "name" })` a string required on insert; `key(sql.uuid)` a string generated on insert as a UUIDv7 when absent. A non-integer numeric key does not increment. `uuid()` is deprecated for `key(sql.uuid)` or `str(sql.uuid)`.
|
|
171
|
+
|
|
172
|
+
**Epoch dates.** `date(sql.ms)` stores a `Date` as epoch milliseconds - INTEGER on SQLite, BIGINT on Postgres; `date(sql.seconds)` names the existing epoch-seconds `integer` storage.
|
|
173
|
+
|
|
174
|
+
**`Query` is a `Promise`.** It has `catch` and `finally`, so returning one from an async function typechecks.
|
|
175
|
+
|
|
176
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`0149fbe`](https://github.com/gabeklein/expressive-orm/commit/0149fbefd67b74f87ac9599b6f9b9bde4935e434) **A relation's column is named after its property.** `author = one(User)` stores `author_id`, not `user_id`; relations named after their class keep their column. Two fields on one column throw when the class is first used. On a table still holding the old column, sync reports the relation instead of adding an empty one: add `{ column: "user_id" }` to keep it.
|
|
177
|
+
|
|
178
|
+
- [#16](https://github.com/gabeklein/expressive-orm/pull/16) [`d4ee4e4`](https://github.com/gabeklein/expressive-orm/commit/d4ee4e443867520f8422b4c9b5bb240157ae3449) `@expressive/sql` is Expressive ORM on SQL: it depends on and re-exports `@expressive/orm`, holds the SQL datatype vocabulary and the SQL connection base, and absorbs `@expressive/sqlite`. Installed alone it is a working embedded store on Bun or Node 24. Import `Type`, `Query`, the field helpers and a connection from here.
|
|
179
|
+
|
|
180
|
+
**Moved and removed**
|
|
181
|
+
|
|
182
|
+
- `Table`, `Field`, `Query`, `Builder`, `Parameter`, `DataTable`, `Primary` and the `Str`, `Num`, `Bool`, `Time` and `One` columns are removed. Entities are `Type` subclasses with orm's `str`, `num`, `bool`, `date`, `uuid`, `json` and `one` helpers; `Query` comes from orm, re-exported here.
|
|
183
|
+
- `SQLiteConnection` moves in from `@expressive/sqlite`. Construct connections with `SQLiteConnection.new(types, filename?)`.
|
|
184
|
+
- `Connection.None` is removed; a query without a connection prints orm's intent dump.
|
|
185
|
+
- `@expressive/orm` is a dependency; `@expressive/mvc` is a peer.
|
|
186
|
+
|
|
187
|
+
**SQLite**
|
|
188
|
+
|
|
189
|
+
- The driver is picked at runtime: `bun:sqlite`, `node:sqlite` (Node 24), then `better-sqlite3`, `sqlite3` or `@libsql/client`, the last three optional peers.
|
|
190
|
+
- `sync` validates existing tables, creates missing ones and adds missing columns with `ALTER TABLE ... ADD COLUMN`, so a database file reopens after a field is added. A column it cannot add - primary, `unique`, `NOT NULL` without a `fallback`, or defaulting to `"NOW"` - is reported with the reason and nothing changes. Type drift is reported, never altered; columns not on the class are ignored. `sync(false)` throws for a missing table or column. Awaiting the connection runs it.
|
|
191
|
+
- Schema renders `PRIMARY KEY` for any primary column, `DEFAULT` for every `fallback` with `"NOW"` as `CURRENT_TIMESTAMP`, and `one()`'s `onDelete` / `onUpdate`. Each type renders as its affinity - `TEXT`, `INTEGER`, `REAL` or `NUMERIC` (`numeric` and `decimal` were `REAL`) - while a field's `datatype` stays the declared type. `json` is `TEXT`.
|
|
192
|
+
- `date` stores ISO strings by default; `"NOW"` is no longer a value to `set`.
|
|
193
|
+
- `close()` destroys the connection and unbinds its classes.
|
|
194
|
+
- No live rows: neither `node:sqlite` nor `bun:sqlite` exposes an update hook. `Type.update(id, data)` still settles a loaded entity.
|
|
195
|
+
- `insert` reads the stored row back through `RETURNING`, defaults included.
|
|
196
|
+
|
|
197
|
+
**Datatypes.** One vocabulary augments orm's helpers and validates on every dialect - `varchar`/`char` length, integer ranges, numeric precision and scale:
|
|
198
|
+
|
|
199
|
+
- `str`: `text` (default), `varchar`, `char`, `uuid`
|
|
200
|
+
- `num`: `integer` (default), `smallint`, `bigint`, `real`, `float`, `double`, `numeric`, `decimal`
|
|
201
|
+
- `bool`: `boolean` (default, a JS boolean, bound as 1/0 on SQLite), `integer` (1/0), `text` and `varchar` with `either`
|
|
202
|
+
- `date`: `timestamp` (default), `date`, `time`, `integer` (unix seconds), `text`
|
|
203
|
+
- `one`: `integer` (default), `bigint`
|
|
204
|
+
|
|
205
|
+
`num` and `date` no longer take `serial` or `datetime`. The column classes export as `StringColumn`, `NumericColumn`, `BooleanColumn`, `TimeColumn` and `ForeignColumn`; importing only a connection narrows `type` options.
|
|
206
|
+
|
|
207
|
+
**Connection base.** `Connection` extends orm's: it implements the floor - `select`, `insert`, `update`, `remove` - as builder statements against the class registered for the table (passed to `new` or bound by `Type.connection = db`), values bound as parameters and the class's primary column matched, so a renamed key round-trips. A dialect supplies `prepare` through a `Generator` subclass, and `sync`. `Generator` renders orm's `Builder`: `null` comparisons as `IS NULL` / `IS NOT NULL`, an insert with a selection with `RETURNING`, `offset` as `OFFSET`, an empty `isIn` as false and `notIn` as true.
|
|
208
|
+
|
|
209
|
+
**Fixes**
|
|
210
|
+
|
|
211
|
+
- Inline string literals quote by doubling `'`, with no backslash escapes. A value containing `\'` broke out of its string on SQLite and Postgres - an injection - and `'` was a syntax error.
|
|
212
|
+
- `static schema` throws on SQLite and Postgres `sync`; only `memory()` honours it.
|
|
213
|
+
- A failed SQLite statement reports the engine error when its SQL cannot be formatted.
|
|
214
|
+
|
|
215
|
+
**Packaging.** ESM only, built with tsdown.
|
|
216
|
+
|
|
217
|
+
Requires `@expressive/mvc` `^0.94.0`.
|
|
218
|
+
|
|
219
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`b9d339f`](https://github.com/gabeklein/expressive-orm/commit/b9d339f65bfdaf9fc68d06e2d4d9b509c86600b8) **`expressive sql check | sync [--force] <entry>`.** A bin, shared by `@expressive/*` packages, that imports the module creating your connections with `sync` held back, then reports or applies what each connection's schema needs. `check` exits 1 when anything would change and marks drift `--force` can rebuild.
|
|
220
|
+
|
|
221
|
+
**`plan(force?)`.** SQL connections return what `sync` would do - `{ steps, problems }`, each step with `action`, `reason` and `sql` - without doing it. `sync` applies the plan in one transaction, and verify-only `sync(false)` now also reports missing indexes. A table referencing one the same sync creates no longer fails as a missing referenced table.
|
|
222
|
+
|
|
223
|
+
**`sync(true, true)` rebuilds drift.** A column whose type or nullability differs from its class is altered on Postgres and rebuilt with its table on SQLite, keeping columns the class doesn't declare, indexes and triggers, and casting values. It refuses while a row would not fit - a NULL under `NOT NULL`, or text that is not a number for a numeric column - or while any row references a missing one. `plan()` is abstract on `Connection`; a custom subclass implements it.
|
|
224
|
+
|
|
225
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`3c9c7a2`](https://github.com/gabeklein/expressive-orm/commit/3c9c7a2737be328077bf4c8c34060b60fbf338ef) **Transactions.** `connection.transaction(fn)` runs `fn` in one database transaction, committing when it resolves and rolling back when it throws. Statements inside join it without a handle, through `AsyncLocalStorage` loaded on first use; a nested call joins the open transaction, so a caught nested failure commits with it. On SQLite and PGlite, other statements wait until it ends and transactions queue; `pg` runs each on its own pooled client, discarding a client whose `BEGIN`, `COMMIT` or `ROLLBACK` failed. A rollback restores instances changed inside, destroys entities created inside and keeps entities deleted inside; a commit destroys those. SQLite and Postgres support it. Where `AsyncLocalStorage` is missing it throws, and `memory()` has none.
|
|
226
|
+
|
|
227
|
+
**Driver contract.** orm's `Connection` declares an optional `transaction(fn)`. `@expressive/sql`'s `Connection` implements it over a protected `transact(fn)`, which a driver provides, plus `lock()` and an `idle()` its statements await - a pooled driver overrides both.
|
|
228
|
+
|
|
229
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`cdf383b`](https://github.com/gabeklein/expressive-orm/commit/cdf383be6f92e34b2b75b3764696855ba83c872f) **Upsert.** `Type.insert(data, { conflict })` writes `ON CONFLICT`. `"update"` overwrites the existing row with every column given, minus the target and `keep`, returns it and settles a loaded instance; `"ignore"` leaves it and resolves `undefined`. `on` names the target - a key or keys, the primary key by default. The memory driver matches.
|
|
230
|
+
|
|
231
|
+
**Composite keys.** `id = key(() => [this.account, this.role])` keys an entity by the fields it lists, with no column of its own. `id` is a string - the parts as JSON - typed as a key of their tuple (`Type.Id<T>` takes either), so it compares by value. `get`, `one`, `update` and `delete` take the key or the tuple, the identity map holds it, a part change through `set` or `update` rekeys a loaded instance, and `sync` declares `PRIMARY KEY (...)` - existing tables included. Live rows report a composite id on Postgres and memory. `one()` cannot relate to a composite-keyed class.
|
|
232
|
+
|
|
233
|
+
**Driver contract.** `insert(table, data, returns?, conflict?)` takes `Connection.Conflict` (`{ on, update? }` by column). `update` and `remove` take `Connection.Key`, which is a tuple for a composite key; `Change.id` likewise. `Field.parts` lists a composite key's fields.
|
|
234
|
+
|
|
235
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`a5fe1d2`](https://github.com/gabeklein/expressive-orm/commit/a5fe1d2b7c60a8a5a4485924d6ac50e99719caee) **`sql.now`.** The current time, wherever a date goes: a column `fallback`, an insert or update value, a comparison. In `Query` it renders as the database's clock in the column's own storage - ISO text with milliseconds, epoch ms or seconds, `date`, `time`, `timestamptz`; statics resolve it from the app's clock so settled instances hold the exact value. `fallback: "NOW"` is a deprecated alias, and a new SQLite `timestamp` default is ISO text with milliseconds rather than `CURRENT_TIMESTAMP`'s `YYYY-MM-DD HH:MM:SS`, which reads as UTC.
|
|
236
|
+
|
|
237
|
+
**`date.created()` and `date.updated()`.** Date columns defaulting to now; `created` is never overwritten after insert, `updated` is set to now on every update and upsert that doesn't give it. They are `date()` with `{ fixed: true }` and `{ update: sql.now }`, which any column takes. A fixed column is left out of update types and throws if given to `update()` or `set()`; `update` also takes a function, called once per write.
|
|
238
|
+
|
|
239
|
+
**`conflict: "replace"`.** An upsert setting every column from the new row - an omitted one to its default or NULL - except the primary key, `date.created` columns and `keep`. An upsert's `update` values apply only on conflict; a new row gets its `fallback`.
|
|
240
|
+
|
|
241
|
+
**Writes by query.** `update(where, data)` and `delete(where)` take a query object in place of an id and resolve the rows affected, settling into or destroying loaded instances; an empty query throws. `count(where?)` counts rows. `null` in a query object matches a missing value. In `Query`, `where(table).match({ ... })` adds an `equal` per key.
|
|
242
|
+
|
|
243
|
+
**`json()`** reads unparseable text as `undefined` instead of throwing, and `isLike` matches a `json()` column's stored text.
|
|
244
|
+
|
|
245
|
+
**`Key<P>`** is exported, and a composite `id` is typed `Key<[number, string]>` rather than `Optional<KeyOf<...>>`.
|
|
246
|
+
|
|
247
|
+
**Fallbacks fill on insert.** An omitted column with a `fallback` is written with it by the orm, not left to a database `DEFAULT` - a table created before the fallback existed gets it too. A nullable column defaulting to now can now be added to an existing SQLite table.
|
|
248
|
+
|
|
249
|
+
**SQLite enforces foreign keys** on every driver; `bun:sqlite` left them off.
|
|
250
|
+
|
|
251
|
+
### Patch Changes
|
|
252
|
+
|
|
253
|
+
- [#22](https://github.com/gabeklein/expressive-orm/pull/22) [`338865e`](https://github.com/gabeklein/expressive-orm/commit/338865e3a62f411801517b02fc04b0c13832fc89) Fixes found adopting an existing SQLite database:
|
|
254
|
+
|
|
255
|
+
- SQLite `sync` accepts a primary key column not declared `NOT NULL`, as tables created outside the library usually are.
|
|
256
|
+
- A count `Query` (no selection) resolves the matching row count on SQLite and Postgres; it resolved 0 on SQLite and the affected rows on Postgres.
|
|
257
|
+
- A table joined twice in one `Query`, such as two relations to the same class, is aliased instead of failing with an ambiguous column.
|
|
258
|
+
- `insert({})` writes `DEFAULT VALUES`. An insert per joined row with no values throws a clear error.
|
|
259
|
+
- Updated dependencies [[`23f442c`](https://github.com/gabeklein/expressive-orm/commit/23f442c449927b10c9fb9b240eaa5161e6a01672), [`d4ee4e4`](https://github.com/gabeklein/expressive-orm/commit/d4ee4e443867520f8422b4c9b5bb240157ae3449), [`0149fbe`](https://github.com/gabeklein/expressive-orm/commit/0149fbefd67b74f87ac9599b6f9b9bde4935e434), [`338865e`](https://github.com/gabeklein/expressive-orm/commit/338865e3a62f411801517b02fc04b0c13832fc89), [`b9d339f`](https://github.com/gabeklein/expressive-orm/commit/b9d339f65bfdaf9fc68d06e2d4d9b509c86600b8), [`3c9c7a2`](https://github.com/gabeklein/expressive-orm/commit/3c9c7a2737be328077bf4c8c34060b60fbf338ef), [`cdf383b`](https://github.com/gabeklein/expressive-orm/commit/cdf383be6f92e34b2b75b3764696855ba83c872f), [`a5fe1d2`](https://github.com/gabeklein/expressive-orm/commit/a5fe1d2b7c60a8a5a4485924d6ac50e99719caee)]:
|
|
260
|
+
- @expressive/orm@0.13.0
|
|
261
|
+
|
|
262
|
+
## 0.4.4
|
|
263
|
+
|
|
264
|
+
### Patch Changes
|
|
265
|
+
|
|
266
|
+
- allow uuid type for Primary
|
|
267
|
+
|
|
268
|
+
## 0.4.3
|
|
269
|
+
|
|
270
|
+
### Patch Changes
|
|
271
|
+
|
|
272
|
+
- fix: failed to build previous change
|
|
273
|
+
|
|
274
|
+
## 0.4.2
|
|
275
|
+
|
|
276
|
+
### Patch Changes
|
|
277
|
+
|
|
278
|
+
- 2acdeb2: primary and fields with defaults are now Optional
|
|
279
|
+
|
|
280
|
+
## 0.4.1
|
|
281
|
+
|
|
282
|
+
### Patch Changes
|
|
283
|
+
|
|
284
|
+
- b8b2195: fix: rebuild libraries
|
|
285
|
+
|
|
286
|
+
## 0.4.0
|
|
287
|
+
|
|
288
|
+
### Minor Changes
|
|
289
|
+
|
|
290
|
+
- 6f4c66b: Major upgrade: generic Fields
|
|
291
|
+
|
|
292
|
+
## 0.3.1
|
|
293
|
+
|
|
294
|
+
### Patch Changes
|
|
295
|
+
|
|
296
|
+
- 857a18c: Improved types for One
|
|
297
|
+
|
|
298
|
+
## 0.3.0
|
|
299
|
+
|
|
300
|
+
### Minor Changes
|
|
301
|
+
|
|
302
|
+
- aa94a15: Generic fields
|
|
303
|
+
|
|
304
|
+
## 0.2.1
|
|
305
|
+
|
|
306
|
+
### Patch Changes
|
|
307
|
+
|
|
308
|
+
- f5c7c31: Allow any number as Str length
|
|
309
|
+
|
|
310
|
+
## 0.2.0
|
|
311
|
+
|
|
312
|
+
### Minor Changes
|
|
313
|
+
|
|
314
|
+
- 9720a38: Multiple Updates
|
|
315
|
+
|
|
316
|
+
### Patch Changes
|
|
317
|
+
|
|
318
|
+
- 004ebe8: replaced bad test scripts
|
|
319
|
+
|
|
320
|
+
## 0.1.1
|
|
321
|
+
|
|
322
|
+
### Patch Changes
|
|
323
|
+
|
|
324
|
+
- cef396d: limit published files to "dist" in package.json
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ await gabe.set({ name: "Gabriel" });
|
|
|
42
42
|
await db.close();
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
`SQLiteConnection.new(types, filename?)` binds the classes; awaiting it creates missing tables, adds missing columns and checks existing ones. SQLite cannot add a `unique` column or one defaulting to `"NOW"`; `sync` reports those. Omit `filename` for an in-memory database.
|
|
45
|
+
`SQLiteConnection.new(types, filename?)` or `SQLiteConnection.new(types, { source?, timestamps? })` binds the classes; awaiting it creates missing tables, adds missing columns and checks existing ones. SQLite cannot add a `unique` column or one defaulting to `"NOW"`; `sync` reports those. Omit `filename` for an in-memory database. `timestamps` is `"ms"` (default), `"seconds"` or `"iso"` - see [Datatypes](https://github.com/gabeklein/expressive-orm#datatypes). As `source`, pass a Cloudflare D1 binding, a libSQL client or a `libsql://` address - see [SQLite hosts](https://github.com/gabeklein/expressive-orm#sqlite-hosts).
|
|
46
46
|
|
|
47
47
|
## Also here
|
|
48
48
|
|
package/dist/bin.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import Sql from "./cli.js";
|
|
2
|
+
export { Sql as default };
|
package/dist/bin.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Sql from "./cli.js";
|
|
3
|
+
import { cmd, main } from "@expressive/cli";
|
|
4
|
+
import { Model } from "@expressive/mvc";
|
|
3
5
|
|
|
4
6
|
//#region src/bin.ts
|
|
5
|
-
|
|
7
|
+
var Expressive = class extends Model {
|
|
8
|
+
constructor(..._args) {
|
|
9
|
+
super(..._args);
|
|
10
|
+
this.dev = cmd({
|
|
11
|
+
peer: "@expressive/dev",
|
|
12
|
+
help: "Run the app - Vite with HMR. Use `dev build` for production."
|
|
13
|
+
});
|
|
14
|
+
this.sql = cmd({
|
|
15
|
+
lazy: () => import("./cli.js"),
|
|
16
|
+
help: "Check or sync a database schema against your entities."
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
main(import.meta, Expressive);
|
|
6
21
|
|
|
7
22
|
//#endregion
|
|
8
|
-
export {
|
|
23
|
+
export { Sql as default };
|
|
9
24
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport {
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cmd, main } from '@expressive/cli';\nimport { Model } from '@expressive/mvc';\n\nexport { default } from './cli';\n\nclass Expressive extends Model {\n dev = cmd({\n peer: \"@expressive/dev\",\n help: \"Run the app - Vite with HMR. Use `dev build` for production.\"\n });\n\n sql = cmd({\n lazy: () => import(\"./cli\"),\n help: \"Check or sync a database schema against your entities.\"\n });\n}\n\nmain(import.meta, Expressive);\n"],"mappings":";;;;;;AAMA,IAAM,aAAN,cAAyB,MAAM;;;aACvB,IAAI;GACR,MAAM;GACN,MAAM;GACP,CAAC;aAEI,IAAI;GACR,YAAY,OAAO;GACnB,MAAM;GACP,CAAC;;;AAGJ,KAAK,OAAO,MAAM,WAAW"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
+
import { Connection } from "./connection/Connection.js";
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
3
|
+
|
|
1
4
|
//#region src/cli.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
declare abstract class Schema extends Model {
|
|
6
|
+
entry: string;
|
|
7
|
+
abstract apply(conn: Connection): Promise<boolean>;
|
|
8
|
+
run(): Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
declare class Check extends Schema {
|
|
11
|
+
apply(conn: Connection): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
declare class Sync extends Schema {
|
|
14
|
+
force: boolean;
|
|
15
|
+
apply(conn: Connection): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
declare class Sql extends Model {
|
|
18
|
+
check: Check | undefined;
|
|
19
|
+
sync: Sync | undefined;
|
|
20
|
+
}
|
|
4
21
|
//#endregion
|
|
5
|
-
export {
|
|
22
|
+
export { Sql as default };
|
|
6
23
|
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.js
CHANGED
|
@@ -1,80 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arg, cmd, flag } from "@expressive/cli";
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
2
3
|
import { pathToFileURL } from "node:url";
|
|
3
4
|
|
|
4
5
|
//#region src/cli.ts
|
|
5
6
|
const COLLECT = Symbol.for("@expressive/orm.collect");
|
|
6
|
-
const USAGE = `Usage: expressive sql <check | sync [--force]> <entry>
|
|
7
|
-
|
|
8
|
-
check list what sync would change; exits 1 if anything would
|
|
9
|
-
sync create missing tables, columns and indexes
|
|
10
|
-
--force sync also rebuilds columns whose type or nullability drifted
|
|
11
|
-
|
|
12
|
-
<entry> is the module that creates your connections, imported without syncing them.
|
|
13
|
-
Connections must be created while it loads.`;
|
|
14
7
|
async function collect(entry) {
|
|
15
8
|
const found = /* @__PURE__ */ new Set();
|
|
16
9
|
const scope = globalThis;
|
|
17
10
|
scope[COLLECT] = found;
|
|
18
11
|
try {
|
|
19
|
-
await import(pathToFileURL(
|
|
12
|
+
await import(pathToFileURL(entry).href);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
throw new Error(`Could not import ${entry}: ${error.message}`);
|
|
20
15
|
} finally {
|
|
21
16
|
delete scope[COLLECT];
|
|
22
17
|
}
|
|
18
|
+
if (!found.size) throw new Error(`${entry} created no connection.`);
|
|
23
19
|
return found;
|
|
24
20
|
}
|
|
25
|
-
async function report(conn, problems, force
|
|
21
|
+
async function report(conn, problems, force) {
|
|
26
22
|
const remain = force || !problems.length ? void 0 : new Set((await conn.plan(true)).problems);
|
|
27
|
-
for (const problem of problems)
|
|
28
|
-
}
|
|
29
|
-
async function check(conn, out) {
|
|
30
|
-
const { steps, problems } = await conn.plan();
|
|
31
|
-
const current = !steps.length && !problems.length;
|
|
32
|
-
out.log(`${conn.constructor.name}: ${current ? "up to date" : "out of date"}`);
|
|
33
|
-
for (const step of steps) out.log(` + ${step.action}`);
|
|
34
|
-
await report(conn, problems, false, out);
|
|
35
|
-
return current;
|
|
23
|
+
for (const problem of problems) console.log(` ! ${problem}${remain && !remain.has(problem) ? " (sync --force rebuilds it)" : ""}`);
|
|
36
24
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
var Schema = class extends Model {
|
|
26
|
+
constructor(..._args) {
|
|
27
|
+
super(..._args);
|
|
28
|
+
this.entry = arg({
|
|
29
|
+
type: "file",
|
|
30
|
+
exists: true,
|
|
31
|
+
required: true,
|
|
32
|
+
help: "module that creates your connections (e.g. src/db.ts) - imported with sync held back"
|
|
33
|
+
});
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return 2;
|
|
35
|
+
async run() {
|
|
36
|
+
const connections = await collect(this.entry);
|
|
37
|
+
let ok = true;
|
|
38
|
+
try {
|
|
39
|
+
for (const conn of connections) if (typeof conn.plan != "function") {
|
|
40
|
+
console.log(`${conn.constructor.name}: cannot plan a sync`);
|
|
41
|
+
ok = false;
|
|
42
|
+
} else ok = await this.apply(conn) && ok;
|
|
43
|
+
} finally {
|
|
44
|
+
for (const conn of connections) await conn.close();
|
|
45
|
+
}
|
|
46
|
+
return ok;
|
|
57
47
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
};
|
|
49
|
+
var Check = class extends Schema {
|
|
50
|
+
async apply(conn) {
|
|
51
|
+
const { steps, problems } = await conn.plan();
|
|
52
|
+
const current = !steps.length && !problems.length;
|
|
53
|
+
console.log(`${conn.constructor.name}: ${current ? "up to date" : "out of date"}`);
|
|
54
|
+
for (const step of steps) console.log(` + ${step.action}`);
|
|
55
|
+
await report(conn, problems, false);
|
|
56
|
+
return current;
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
};
|
|
59
|
+
var Sync = class extends Schema {
|
|
60
|
+
constructor(..._args2) {
|
|
61
|
+
super(..._args2);
|
|
62
|
+
this.force = flag({
|
|
63
|
+
short: "f",
|
|
64
|
+
help: "also rebuild columns whose type or nullability drifted"
|
|
65
|
+
});
|
|
74
66
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
67
|
+
async apply(conn) {
|
|
68
|
+
const { force } = this;
|
|
69
|
+
const { steps, problems } = await conn.plan(force);
|
|
70
|
+
if (problems.length) {
|
|
71
|
+
console.log(`${conn.constructor.name}: not synced`);
|
|
72
|
+
await report(conn, problems, force);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
await conn.sync(true, force);
|
|
76
|
+
console.log(`${conn.constructor.name}: ${steps.length ? "synced" : "up to date"}`);
|
|
77
|
+
for (const step of steps) console.log(` + ${step.action}`);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var Sql = class extends Model {
|
|
82
|
+
constructor(..._args3) {
|
|
83
|
+
super(..._args3);
|
|
84
|
+
this.check = cmd({
|
|
85
|
+
from: Check,
|
|
86
|
+
help: "List what sync would change, without changing anything. Exits 1 if anything would."
|
|
87
|
+
});
|
|
88
|
+
this.sync = cmd({
|
|
89
|
+
from: Sync,
|
|
90
|
+
help: "Create missing tables, columns and indexes. Drifted columns need --force."
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
77
94
|
|
|
78
95
|
//#endregion
|
|
79
|
-
export {
|
|
96
|
+
export { Sql as default };
|
|
80
97
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\n\nimport { arg, cmd, flag } from '@expressive/cli';\nimport { Model } from '@expressive/mvc';\n\nimport type { Connection } from './connection/Connection';\n\nconst COLLECT = Symbol.for(\"@expressive/orm.collect\");\n\nasync function collect(entry: string){\n const found = new Set<Connection>();\n const scope = globalThis as { [COLLECT]?: Set<Connection> };\n\n scope[COLLECT] = found;\n\n try {\n await import(pathToFileURL(entry).href);\n }\n catch (error) {\n throw new Error(`Could not import ${entry}: ${(error as Error).message}`);\n }\n finally {\n delete scope[COLLECT];\n }\n\n if (!found.size)\n throw new Error(`${entry} created no connection.`);\n\n return found;\n}\n\nasync function report(conn: Connection, problems: string[], force: boolean){\n const remain = force || !problems.length ? undefined : new Set((await conn.plan(true)).problems);\n\n for (const problem of problems)\n console.log(` ! ${problem}${remain && !remain.has(problem) ? \" (sync --force rebuilds it)\" : \"\"}`);\n}\n\nabstract class Schema extends Model {\n entry = arg({\n type: \"file\",\n exists: true,\n required: true,\n help: \"module that creates your connections (e.g. src/db.ts) - imported with sync held back\"\n });\n\n abstract apply(conn: Connection): Promise<boolean>;\n\n async run(){\n const connections = await collect(this.entry);\n let ok = true;\n\n try {\n for (const conn of connections)\n if (typeof conn.plan != \"function\") {\n console.log(`${conn.constructor.name}: cannot plan a sync`);\n ok = false;\n }\n else\n ok = await this.apply(conn) && ok;\n }\n finally {\n for (const conn of connections)\n await conn.close();\n }\n\n return ok;\n }\n}\n\nclass Check extends Schema {\n async apply(conn: Connection){\n const { steps, problems } = await conn.plan();\n const current = !steps.length && !problems.length;\n\n console.log(`${conn.constructor.name}: ${current ? \"up to date\" : \"out of date\"}`);\n\n for (const step of steps)\n console.log(` + ${step.action}`);\n\n await report(conn, problems, false);\n\n return current;\n }\n}\n\nclass Sync extends Schema {\n force = flag({ short: \"f\", help: \"also rebuild columns whose type or nullability drifted\" });\n\n async apply(conn: Connection){\n const { force } = this;\n const { steps, problems } = await conn.plan(force);\n\n if (problems.length) {\n console.log(`${conn.constructor.name}: not synced`);\n await report(conn, problems, force);\n\n return false;\n }\n\n await conn.sync(true, force);\n\n console.log(`${conn.constructor.name}: ${steps.length ? \"synced\" : \"up to date\"}`);\n\n for (const step of steps)\n console.log(` + ${step.action}`);\n\n return true;\n }\n}\n\nexport default class Sql extends Model {\n check = cmd({ from: Check, help: \"List what sync would change, without changing anything. Exits 1 if anything would.\" });\n sync = cmd({ from: Sync, help: \"Create missing tables, columns and indexes. Drifted columns need --force.\" });\n}\n"],"mappings":";;;;;AAOA,MAAM,UAAU,OAAO,IAAI,0BAA0B;AAErD,eAAe,QAAQ,OAAc;CACnC,MAAM,wBAAQ,IAAI,KAAiB;CACnC,MAAM,QAAQ;AAEd,OAAM,WAAW;AAEjB,KAAI;AACF,QAAM,OAAO,cAAc,MAAM,CAAC;UAE7B,OAAO;AACZ,QAAM,IAAI,MAAM,oBAAoB,MAAM,IAAK,MAAgB,UAAU;WAEnE;AACN,SAAO,MAAM;;AAGf,KAAI,CAAC,MAAM,KACT,OAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;AAEpD,QAAO;;AAGT,eAAe,OAAO,MAAkB,UAAoB,OAAe;CACzE,MAAM,SAAS,SAAS,CAAC,SAAS,SAAS,SAAY,IAAI,KAAK,MAAM,KAAK,KAAK,KAAK,EAAE,SAAS;AAEhG,MAAK,MAAM,WAAW,SACpB,SAAQ,IAAI,OAAO,UAAU,UAAU,CAAC,OAAO,IAAI,QAAQ,GAAG,gCAAgC,KAAK;;AAGvG,IAAe,SAAf,cAA8B,MAAM;;;eAC1B,IAAI;GACV,MAAM;GACN,QAAQ;GACR,UAAU;GACV,MAAM;GACP,CAAC;;CAIF,MAAM,MAAK;EACT,MAAM,cAAc,MAAM,QAAQ,KAAK,MAAM;EAC7C,IAAI,KAAK;AAET,MAAI;AACF,QAAK,MAAM,QAAQ,YACjB,KAAI,OAAO,KAAK,QAAQ,YAAY;AAClC,YAAQ,IAAI,GAAG,KAAK,YAAY,KAAK,sBAAsB;AAC3D,SAAK;SAGL,MAAK,MAAM,KAAK,MAAM,KAAK,IAAI;YAE7B;AACN,QAAK,MAAM,QAAQ,YACjB,OAAM,KAAK,OAAO;;AAGtB,SAAO;;;AAIX,IAAM,QAAN,cAAoB,OAAO;CACzB,MAAM,MAAM,MAAiB;EAC3B,MAAM,EAAE,OAAO,aAAa,MAAM,KAAK,MAAM;EAC7C,MAAM,UAAU,CAAC,MAAM,UAAU,CAAC,SAAS;AAE3C,UAAQ,IAAI,GAAG,KAAK,YAAY,KAAK,IAAI,UAAU,eAAe,gBAAgB;AAElF,OAAK,MAAM,QAAQ,MACjB,SAAQ,IAAI,OAAO,KAAK,SAAS;AAEnC,QAAM,OAAO,MAAM,UAAU,MAAM;AAEnC,SAAO;;;AAIX,IAAM,OAAN,cAAmB,OAAO;;;eAChB,KAAK;GAAE,OAAO;GAAK,MAAM;GAA0D,CAAC;;CAE5F,MAAM,MAAM,MAAiB;EAC3B,MAAM,EAAE,UAAU;EAClB,MAAM,EAAE,OAAO,aAAa,MAAM,KAAK,KAAK,MAAM;AAElD,MAAI,SAAS,QAAQ;AACnB,WAAQ,IAAI,GAAG,KAAK,YAAY,KAAK,cAAc;AACnD,SAAM,OAAO,MAAM,UAAU,MAAM;AAEnC,UAAO;;AAGT,QAAM,KAAK,KAAK,MAAM,MAAM;AAE5B,UAAQ,IAAI,GAAG,KAAK,YAAY,KAAK,IAAI,MAAM,SAAS,WAAW,eAAe;AAElF,OAAK,MAAM,QAAQ,MACjB,SAAQ,IAAI,OAAO,KAAK,SAAS;AAEnC,SAAO;;;AAIX,IAAqB,MAArB,cAAiC,MAAM;;;eAC7B,IAAI;GAAE,MAAM;GAAO,MAAM;GAAsF,CAAC;cACjH,IAAI;GAAE,MAAM;GAAM,MAAM;GAA6E,CAAC"}
|