@bakery-framework/orm 2.0.0-alpha.9 → 2.0.0-rc.2
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 +9 -9
- package/package.json +3 -3
- package/src/adapters/base.ts +181 -62
- package/src/adapters/mysql.ts +29 -17
- package/src/adapters/observe.ts +11 -11
- package/src/adapters/pgsql.ts +54 -39
- package/src/adapters/registry.ts +13 -13
- package/src/adapters/sqlite.ts +175 -44
- package/src/adapters.ts +4 -4
- package/src/backup.ts +1 -1
- package/src/connection.ts +1 -1
- package/src/define.ts +22 -22
- package/src/field.ts +55 -40
- package/src/globals.d.ts +1 -1
- package/src/index.ts +4 -4
- package/src/orm/index.ts +2 -2
- package/src/orm/mutation.ts +36 -28
- package/src/orm/query.ts +92 -89
- package/src/pool.ts +5 -5
- package/src/schema-registry.ts +3 -3
- package/src/schema-util.ts +48 -17
- package/src/sync/builder.ts +32 -32
- package/src/sync/diff.ts +12 -12
- package/src/sync/engine.ts +19 -19
- package/src/sync/execute.ts +16 -16
- package/src/sync/history.ts +5 -5
- package/src/sync/index.ts +12 -12
- package/src/sync/ledger.ts +23 -23
- package/src/sync/load.ts +16 -16
- package/src/sync/plan.ts +1 -2
- package/src/sync/rename.ts +1 -1
- package/src/sync/rollback.ts +3 -3
- package/src/sync/types.ts +20 -4
- package/src/sync/view-sql.ts +9 -9
- package/templates/schema.example.ts +4 -4
package/src/sync/view-sql.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Canonicalizing a view's `SELECT` so the two sides of the diff can be compared.
|
|
3
3
|
*
|
|
4
|
-
* A view body is compared as **text
|
|
4
|
+
* A view body is compared as **text**: there is no parser here, and there will
|
|
5
5
|
* not be one. That works only if both sides are spelled the same way, and they
|
|
6
6
|
* are not: you write
|
|
7
7
|
*
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* select `p`.`id` AS `id`,`p`.`name` AS `name` from `buzzy`.`users` `p` ...
|
|
13
13
|
*
|
|
14
14
|
* fully qualified, fully quoted, with every alias spelled out. Compare those
|
|
15
|
-
* literally and the view is recreated on every single sync, forever
|
|
15
|
+
* literally and the view is recreated on every single sync, forever: the same
|
|
16
16
|
* perpetual-churn failure the column diff has hit twice.
|
|
17
17
|
*
|
|
18
18
|
* So everything here must hold two properties, and both are tested:
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* - **Idempotent**: `f(f(x)) === f(x)`.
|
|
21
21
|
* - **Convergent**: `f(what you wrote) === f(what the server returns)`.
|
|
22
22
|
*
|
|
23
|
-
* Which is why this only removes *noise
|
|
23
|
+
* Which is why this only removes *noise*: quoting, schema qualification,
|
|
24
24
|
* redundant aliases, whitespace. It never reorders, rewrites or reflows
|
|
25
25
|
* anything semantic, because a transformation the server would not also produce
|
|
26
26
|
* is one that makes the two sides differ rather than agree.
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Words that must keep their quoting: unquoting one turns an identifier into
|
|
31
|
-
* syntax. Deliberately small
|
|
31
|
+
* syntax. Deliberately small: it only has to cover words a column or table is
|
|
32
32
|
* plausibly *named* after, since anything else was never quoted to begin with.
|
|
33
33
|
*/
|
|
34
34
|
const RESERVED = new Set([
|
|
@@ -98,7 +98,7 @@ function unquoteIdentifiers(sql: string): string {
|
|
|
98
98
|
* Drop `db.` from `db.table`, for the database the view lives in.
|
|
99
99
|
*
|
|
100
100
|
* MySQL qualifies every table in a stored view with the schema it was created
|
|
101
|
-
* in, so the body carries a hard-coded database name
|
|
101
|
+
* in, so the body carries a hard-coded database name, and the same schema
|
|
102
102
|
* deployed against a differently-named database would then compare unequal and
|
|
103
103
|
* be recreated forever. It is also simply wrong to write down: the view already
|
|
104
104
|
* lives in that database.
|
|
@@ -116,7 +116,7 @@ function stripOwnSchema(sql: string, database?: string): string {
|
|
|
116
116
|
* `x AS x` is what MySQL writes for every selected column. It says nothing, and
|
|
117
117
|
* you would not have typed it.
|
|
118
118
|
*
|
|
119
|
-
* Matched on the *last* segment so `p.id AS id` collapses too
|
|
119
|
+
* Matched on the *last* segment so `p.id AS id` collapses too: the qualifier
|
|
120
120
|
* is part of where the value comes from, not of what the output column is
|
|
121
121
|
* called.
|
|
122
122
|
*/
|
|
@@ -140,7 +140,7 @@ export function normalizeViewBody(sql: string, database?: string): string {
|
|
|
140
140
|
out = dropRedundantAliases(out)
|
|
141
141
|
// Qualifier removal can leave `from products`; alias removal can leave a
|
|
142
142
|
// doubled space too. Collapse once more so the result is stable under a
|
|
143
|
-
// second pass
|
|
143
|
+
// second pass, which is what makes this idempotent.
|
|
144
144
|
return out.replace(/\s+/g, ' ').trim()
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -148,7 +148,7 @@ export function normalizeViewBody(sql: string, database?: string): string {
|
|
|
148
148
|
* The same body, broken across lines for a generated file.
|
|
149
149
|
*
|
|
150
150
|
* Safe only because the comparison collapses whitespace before comparing: this
|
|
151
|
-
* adds newlines and nothing else, so a
|
|
151
|
+
* adds newlines and nothing else, so a normalized pretty body and a normalized
|
|
152
152
|
* canonical one are the same string.
|
|
153
153
|
*/
|
|
154
154
|
export function formatViewBody(sql: string, database?: string): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Template schema
|
|
2
|
+
* Template schema. Copy this to `schema.ts` to get started:
|
|
3
3
|
*
|
|
4
4
|
* ```sh
|
|
5
5
|
* cp schema.example.ts schema.ts
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* `schema.ts` itself is gitignored: it belongs to the application, and
|
|
10
10
|
* `db:sync` rewrites it (it can generate the file from an existing database
|
|
11
|
-
* with `--choose=db`). This example is tracked so the shape
|
|
12
|
-
* importantly, the registration block at the bottom
|
|
11
|
+
* with `--choose=db`). This example is tracked so the shape (and, more
|
|
12
|
+
* importantly, the registration block at the bottom) is discoverable in a
|
|
13
13
|
* fresh clone.
|
|
14
14
|
*
|
|
15
15
|
* The framework never imports this file for types. Everything runs and
|
|
@@ -80,7 +80,7 @@ export type DBOptionals = {
|
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Registers this schema with the framework's type system, which is what makes
|
|
83
|
-
* `DB.from('posts')` know its columns. Keep this block
|
|
83
|
+
* `DB.from('posts')` know its columns. Keep this block, without it the ORM
|
|
84
84
|
* still works, but every table and column is `any`.
|
|
85
85
|
*/
|
|
86
86
|
declare module '@bakery-framework/orm/schema-registry' {
|