@fougere/adapter-sql 0.5.0-alpha.1 → 0.7.0-alpha.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 +4 -4
- package/dist/adapter.schema.json +16 -0
- package/dist/check.d.ts +2 -27
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +2 -27
- package/dist/check.js.map +1 -1
- package/dist/crud.d.ts +19 -85
- package/dist/crud.d.ts.map +1 -1
- package/dist/crud.js +25 -102
- package/dist/crud.js.map +1 -1
- package/dist/ddl.d.ts +8 -53
- package/dist/ddl.d.ts.map +1 -1
- package/dist/ddl.js +16 -55
- package/dist/ddl.js.map +1 -1
- package/dist/dialect.d.ts +7 -50
- package/dist/dialect.d.ts.map +1 -1
- package/dist/dialect.js +2 -5
- package/dist/dialect.js.map +1 -1
- package/dist/diff.d.ts +6 -44
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +20 -50
- package/dist/diff.js.map +1 -1
- package/dist/fields.d.ts +10 -9
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +8 -1
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/order.d.ts +23 -0
- package/dist/order.d.ts.map +1 -0
- package/dist/order.js +40 -0
- package/dist/order.js.map +1 -0
- package/dist/query.d.ts +2 -17
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +1 -11
- package/dist/query.js.map +1 -1
- package/dist/setup.d.ts +15 -35
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +18 -12
- package/dist/setup.js.map +1 -1
- package/dist/sqlite.d.ts +2 -2
- package/dist/sqlite.d.ts.map +1 -1
- package/dist/sqlite.js +22 -12
- package/dist/sqlite.js.map +1 -1
- package/dist/step.d.ts +4 -33
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +11 -46
- package/dist/step.js.map +1 -1
- package/dist/table.d.ts +15 -77
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +34 -146
- package/dist/table.js.map +1 -1
- package/dist/values.d.ts +1 -17
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +2 -7
- package/dist/values.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter.schema.json +16 -0
- package/src/check.ts +2 -27
- package/src/crud.ts +28 -105
- package/src/ddl.ts +14 -55
- package/src/dialect.ts +7 -50
- package/src/diff.ts +18 -50
- package/src/fields.ts +17 -8
- package/src/index.ts +6 -6
- package/src/order.ts +63 -0
- package/src/query.ts +2 -17
- package/src/setup.ts +33 -37
- package/src/sqlite.ts +28 -14
- package/src/step.ts +12 -54
- package/src/table.ts +42 -185
- package/src/values.ts +3 -24
package/dist/ddl.d.ts
CHANGED
|
@@ -1,47 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DDL — the table description, rendered as SQL.
|
|
3
|
-
*
|
|
4
|
-
* Kysely's schema builder is what makes this dialect-agnostic: it owns the
|
|
5
|
-
* identifier quoting and the per-engine syntax, so this module only decides
|
|
6
|
-
* *what* to emit. Compilation needs no connection — a `DummyDriver` paired with
|
|
7
|
-
* a real query compiler renders the statement for any engine, which is why the
|
|
8
|
-
* whole surface is testable without a database.
|
|
9
|
-
*/
|
|
1
|
+
/** DDL — the table description, rendered as SQL. */
|
|
10
2
|
import { Kysely } from 'kysely';
|
|
11
3
|
import { type AppLike, type ColumnDef, type TableDef } from './table.js';
|
|
12
4
|
import { type DialectName } from './dialect.js';
|
|
13
5
|
/** A Kysely bound to a dialect's compiler but to no connection — renders SQL only. */
|
|
14
6
|
export declare function compiler(name: DialectName): Kysely<any>;
|
|
15
|
-
/**
|
|
16
|
-
* Render `CREATE TABLE` for one described table.
|
|
17
|
-
*
|
|
18
|
-
* `IF NOT EXISTS` is emitted everywhere it exists — SQL Server has no such
|
|
19
|
-
* clause, so there the statement is bare and the caller must not replay it
|
|
20
|
-
* blindly (the diff pass, once it lands, answers that properly).
|
|
21
|
-
*
|
|
22
|
-
* `skipReferences` names the columns whose FK is rendered WITHOUT the inline
|
|
23
|
-
* `references()` — the column itself still gets created; `orderTables` sends a
|
|
24
|
-
* column here when its target is part of a cycle, so the constraint reaches the
|
|
25
|
-
* table separately, once every table involved exists (`addForeignKeyConstraintSQL`).
|
|
26
|
-
*/
|
|
7
|
+
/** Render `CREATE TABLE` for one described table. */
|
|
27
8
|
export declare function createTableSQL(table: TableDef, dialectName: DialectName, options?: {
|
|
28
9
|
skipReferences?: Set<string>;
|
|
29
10
|
}): string;
|
|
30
|
-
/**
|
|
31
|
-
* `CREATE INDEX` for every column that asked for one.
|
|
32
|
-
*
|
|
33
|
-
* Separate statements, never part of `CREATE TABLE`: an index is not a constraint, it
|
|
34
|
-
* changes no answer — only what a read costs. `IF NOT EXISTS` everywhere it exists, so
|
|
35
|
-
* replaying the batch is safe (SQL Server has no such clause, same rule as the tables).
|
|
36
|
-
*/
|
|
11
|
+
/** `CREATE INDEX` for every column that asked for one. */
|
|
37
12
|
export declare function indexSQL(table: TableDef, column: ColumnDef, dialectName: DialectName): string;
|
|
38
13
|
/** Every index one table asks for — one statement each. */
|
|
39
14
|
export declare function createIndexSQL(table: TableDef, dialectName: DialectName): string[];
|
|
40
15
|
/**
|
|
41
|
-
* `ALTER TABLE ADD CONSTRAINT` for one FK `orderTables` deferred — closes a
|
|
42
|
-
*
|
|
43
|
-
* `ALTER TABLE` is limited to RENAME/ADD COLUMN/RENAME COLUMN/DROP COLUMN) — a
|
|
44
|
-
* caller on that dialect never produces a deferred edge to render here.
|
|
16
|
+
* `ALTER TABLE ADD CONSTRAINT` for one FK `orderTables` deferred — closes a relation cycle once
|
|
17
|
+
* every table in it exists.
|
|
45
18
|
*/
|
|
46
19
|
export declare function addForeignKeyConstraintSQL(table: TableDef, column: ColumnDef, dialectName: DialectName): string;
|
|
47
20
|
export interface GenerateOptions {
|
|
@@ -51,20 +24,8 @@ export interface GenerateOptions {
|
|
|
51
24
|
dialect?: DialectName;
|
|
52
25
|
}
|
|
53
26
|
/**
|
|
54
|
-
* `CREATE TABLE` for every entity the app hosts — scanned frond entities plus
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* SQLite resolves FK targets lazily and accepts any order, and it has no
|
|
58
|
-
* `ALTER TABLE ADD CONSTRAINT` to close a cycle with — every FK stays inline,
|
|
59
|
-
* unordered. Every other engine needs a referenced table to exist first:
|
|
60
|
-
* `orderTables` sorts the batch and reports the edges a cycle forces to defer,
|
|
61
|
-
* rendered as `ALTER TABLE ADD CONSTRAINT` after every `CREATE TABLE`.
|
|
62
|
-
*
|
|
63
|
-
* Caveat for a repeat call (`autoMigrate`): `CREATE TABLE IF NOT EXISTS` is
|
|
64
|
-
* idempotent, `ADD CONSTRAINT` is not — on pg/mysql/mssql, calling this twice
|
|
65
|
-
* for an app with a relation cycle re-issues the same constraint and errors.
|
|
66
|
-
* The introspection-based `migrate()` (`diff.ts`) doesn't have this problem: it
|
|
67
|
-
* only ever emits a table's constraints once, the run that creates it.
|
|
27
|
+
* `CREATE TABLE` for every entity the app hosts — scanned frond entities plus auth runtime
|
|
28
|
+
* entities when present.
|
|
68
29
|
*/
|
|
69
30
|
export declare function generateSQL(app: AppLike, options?: GenerateOptions): string[];
|
|
70
31
|
/**
|
|
@@ -76,12 +37,6 @@ export type SqlSink = {
|
|
|
76
37
|
} | {
|
|
77
38
|
exec(sql: string): unknown;
|
|
78
39
|
};
|
|
79
|
-
/**
|
|
80
|
-
* Create every missing table. Additive only — an existing table is left alone.
|
|
81
|
-
*
|
|
82
|
-
* Stays SYNCHRONOUS when the sink is (a raw better-sqlite3 handle), so a caller
|
|
83
|
-
* that doesn't await still gets its tables before the next statement. Returns a
|
|
84
|
-
* promise only when the sink actually returns one.
|
|
85
|
-
*/
|
|
40
|
+
/** Create every missing table. */
|
|
86
41
|
export declare function autoMigrate(app: AppLike, sink: SqlSink, options?: GenerateOptions): void | Promise<void>;
|
|
87
42
|
//# sourceMappingURL=ddl.d.ts.map
|
package/dist/ddl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ddl.d.ts","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ddl.d.ts","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,OAAO,EACL,MAAM,EAOP,MAAM,QAAQ,CAAC;AAChB,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,QAAQ,EACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc/E,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAcvD;AAID,qDAAqD;AACrD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,QAAQ,EACf,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,GACzC,MAAM,CA6CR;AAED,0DAA0D;AAC1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,CAW7F;AAED,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,CAIlF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,CAQ/G;AAID,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,sCAAsC;IACtC,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CA4B7E;AAED;;;GAGG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GACjC;IAAE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAMnC,kCAAkC;AAClC,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxG"}
|
package/dist/ddl.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DDL — the table description, rendered as SQL.
|
|
3
|
-
*
|
|
4
|
-
* Kysely's schema builder is what makes this dialect-agnostic: it owns the
|
|
5
|
-
* identifier quoting and the per-engine syntax, so this module only decides
|
|
6
|
-
* *what* to emit. Compilation needs no connection — a `DummyDriver` paired with
|
|
7
|
-
* a real query compiler renders the statement for any engine, which is why the
|
|
8
|
-
* whole surface is testable without a database.
|
|
9
|
-
*/
|
|
1
|
+
/** DDL — the table description, rendered as SQL. */
|
|
10
2
|
import { Kysely, DummyDriver, sql, SqliteAdapter, SqliteQueryCompiler, SqliteIntrospector, PostgresAdapter, PostgresQueryCompiler, PostgresIntrospector, MysqlAdapter, MysqlQueryCompiler, MysqlIntrospector, MssqlAdapter, MssqlQueryCompiler, MssqlIntrospector, } from 'kysely';
|
|
11
|
-
import { isKeyed,
|
|
3
|
+
import { isKeyed, toTableName, toTables, } from './table.js';
|
|
4
|
+
import { orderTables } from './order.js';
|
|
12
5
|
import { columnTypeFor, resolveDialect } from './dialect.js';
|
|
13
6
|
import { checkFor } from './check.js';
|
|
14
7
|
// ─── Compile-only engines ──────────────────────────
|
|
@@ -37,18 +30,7 @@ export function compiler(name) {
|
|
|
37
30
|
return engine;
|
|
38
31
|
}
|
|
39
32
|
// ─── CREATE TABLE ──────────────────────────────────
|
|
40
|
-
/**
|
|
41
|
-
* Render `CREATE TABLE` for one described table.
|
|
42
|
-
*
|
|
43
|
-
* `IF NOT EXISTS` is emitted everywhere it exists — SQL Server has no such
|
|
44
|
-
* clause, so there the statement is bare and the caller must not replay it
|
|
45
|
-
* blindly (the diff pass, once it lands, answers that properly).
|
|
46
|
-
*
|
|
47
|
-
* `skipReferences` names the columns whose FK is rendered WITHOUT the inline
|
|
48
|
-
* `references()` — the column itself still gets created; `orderTables` sends a
|
|
49
|
-
* column here when its target is part of a cycle, so the constraint reaches the
|
|
50
|
-
* table separately, once every table involved exists (`addForeignKeyConstraintSQL`).
|
|
51
|
-
*/
|
|
33
|
+
/** Render `CREATE TABLE` for one described table. */
|
|
52
34
|
export function createTableSQL(table, dialectName, options) {
|
|
53
35
|
const dialect = resolveDialect(dialectName);
|
|
54
36
|
const composite = table.compositePrimary.length > 0;
|
|
@@ -67,7 +49,7 @@ export function createTableSQL(table, dialectName, options) {
|
|
|
67
49
|
built = built.notNull();
|
|
68
50
|
if (column.default !== undefined)
|
|
69
51
|
built = built.defaultTo(column.default);
|
|
70
|
-
// Uniqueness is the storage's to enforce: no shape can express it, since
|
|
52
|
+
// Uniqueness is the storage's to enforce: no shape can express it, since validating
|
|
71
53
|
// one value never sees the other rows.
|
|
72
54
|
if (column.unique)
|
|
73
55
|
built = built.unique();
|
|
@@ -97,18 +79,17 @@ export function createTableSQL(table, dialectName, options) {
|
|
|
97
79
|
}
|
|
98
80
|
return builder.compile().sql;
|
|
99
81
|
}
|
|
100
|
-
/**
|
|
101
|
-
* `CREATE INDEX` for every column that asked for one.
|
|
102
|
-
*
|
|
103
|
-
* Separate statements, never part of `CREATE TABLE`: an index is not a constraint, it
|
|
104
|
-
* changes no answer — only what a read costs. `IF NOT EXISTS` everywhere it exists, so
|
|
105
|
-
* replaying the batch is safe (SQL Server has no such clause, same rule as the tables).
|
|
106
|
-
*/
|
|
82
|
+
/** `CREATE INDEX` for every column that asked for one. */
|
|
107
83
|
export function indexSQL(table, column, dialectName) {
|
|
108
84
|
let builder = compiler(dialectName)
|
|
109
85
|
.schema.createIndex(`${table.name}_${column.name}_idx`)
|
|
110
86
|
.on(table.name)
|
|
111
87
|
.column(column.name);
|
|
88
|
+
// A `unique()` on a table that already exists has nowhere else to land: `createTable`
|
|
89
|
+
// writes it as a column constraint, and no engine here can ALTER one in. As an index it
|
|
90
|
+
// arrives — or the statement fails on the rows that already break it, which is the answer.
|
|
91
|
+
if (column.unique)
|
|
92
|
+
builder = builder.unique();
|
|
112
93
|
if (dialectName !== 'mssql')
|
|
113
94
|
builder = builder.ifNotExists();
|
|
114
95
|
return builder.compile().sql;
|
|
@@ -120,10 +101,8 @@ export function createIndexSQL(table, dialectName) {
|
|
|
120
101
|
.map((column) => indexSQL(table, column, dialectName));
|
|
121
102
|
}
|
|
122
103
|
/**
|
|
123
|
-
* `ALTER TABLE ADD CONSTRAINT` for one FK `orderTables` deferred — closes a
|
|
124
|
-
*
|
|
125
|
-
* `ALTER TABLE` is limited to RENAME/ADD COLUMN/RENAME COLUMN/DROP COLUMN) — a
|
|
126
|
-
* caller on that dialect never produces a deferred edge to render here.
|
|
104
|
+
* `ALTER TABLE ADD CONSTRAINT` for one FK `orderTables` deferred — closes a relation cycle once
|
|
105
|
+
* every table in it exists.
|
|
127
106
|
*/
|
|
128
107
|
export function addForeignKeyConstraintSQL(table, column, dialectName) {
|
|
129
108
|
const ref = column.references;
|
|
@@ -136,20 +115,8 @@ export function addForeignKeyConstraintSQL(table, column, dialectName) {
|
|
|
136
115
|
return builder.compile().sql;
|
|
137
116
|
}
|
|
138
117
|
/**
|
|
139
|
-
* `CREATE TABLE` for every entity the app hosts — scanned frond entities plus
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* SQLite resolves FK targets lazily and accepts any order, and it has no
|
|
143
|
-
* `ALTER TABLE ADD CONSTRAINT` to close a cycle with — every FK stays inline,
|
|
144
|
-
* unordered. Every other engine needs a referenced table to exist first:
|
|
145
|
-
* `orderTables` sorts the batch and reports the edges a cycle forces to defer,
|
|
146
|
-
* rendered as `ALTER TABLE ADD CONSTRAINT` after every `CREATE TABLE`.
|
|
147
|
-
*
|
|
148
|
-
* Caveat for a repeat call (`autoMigrate`): `CREATE TABLE IF NOT EXISTS` is
|
|
149
|
-
* idempotent, `ADD CONSTRAINT` is not — on pg/mysql/mssql, calling this twice
|
|
150
|
-
* for an app with a relation cycle re-issues the same constraint and errors.
|
|
151
|
-
* The introspection-based `migrate()` (`diff.ts`) doesn't have this problem: it
|
|
152
|
-
* only ever emits a table's constraints once, the run that creates it.
|
|
118
|
+
* `CREATE TABLE` for every entity the app hosts — scanned frond entities plus auth runtime
|
|
119
|
+
* entities when present.
|
|
153
120
|
*/
|
|
154
121
|
export function generateSQL(app, options) {
|
|
155
122
|
const resolve = options?.tableName ?? toTableName;
|
|
@@ -178,13 +145,7 @@ export function generateSQL(app, options) {
|
|
|
178
145
|
function runOn(sink, statement) {
|
|
179
146
|
return 'execute' in sink ? sink.execute(statement) : sink.exec(statement);
|
|
180
147
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Create every missing table. Additive only — an existing table is left alone.
|
|
183
|
-
*
|
|
184
|
-
* Stays SYNCHRONOUS when the sink is (a raw better-sqlite3 handle), so a caller
|
|
185
|
-
* that doesn't await still gets its tables before the next statement. Returns a
|
|
186
|
-
* promise only when the sink actually returns one.
|
|
187
|
-
*/
|
|
148
|
+
/** Create every missing table. */
|
|
188
149
|
export function autoMigrate(app, sink, options) {
|
|
189
150
|
const pending = generateSQL(app, options)
|
|
190
151
|
.map((statement) => runOn(sink, statement))
|
package/dist/ddl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ddl.js","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":"AAAA
|
|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C,GAAY,EAAE,IAAa,EAAE,OAAyB;IAChF,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;SACtC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SAC1C,MAAM,CAAC,CAAC,MAAM,EAA8B,EAAE,CAAC,OAAQ,MAAc,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC"}
|
package/dist/dialect.d.ts
CHANGED
|
@@ -1,60 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dialect — the only place that speaks SQL.
|
|
3
|
-
*
|
|
4
|
-
* A dialect answers two questions and nothing else: which column type carries
|
|
5
|
-
* this shape, and does this engine support `RETURNING`. Everything structural
|
|
6
|
-
* (which columns exist, which are keys) is decided upstream in `TableDef`.
|
|
7
|
-
*/
|
|
1
|
+
/** Dialect — the only place that speaks SQL. */
|
|
8
2
|
import type { ColumnDef } from './table.js';
|
|
9
3
|
export type DialectName = 'sqlite' | 'pg' | 'mysql' | 'mssql';
|
|
10
4
|
export interface Dialect {
|
|
11
5
|
name: DialectName;
|
|
12
|
-
/**
|
|
13
|
-
* SQL type for a column. `keyed` is true when the column belongs to a primary
|
|
14
|
-
* key — MySQL and SQL Server cannot index an unbounded text column, so they
|
|
15
|
-
* narrow to a bounded varchar there.
|
|
16
|
-
*/
|
|
6
|
+
/** SQL type for a column. */
|
|
17
7
|
columnType(column: ColumnDef, keyed: boolean): string;
|
|
18
8
|
/**
|
|
19
9
|
* Does `INSERT … RETURNING` work? MySQL has no such clause and SQL Server
|
|
20
10
|
* spells it `OUTPUT`; both take the insert-then-select path instead.
|
|
21
11
|
*/
|
|
22
12
|
supportsReturning: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* How many values one statement may bind — what splits a batch read into several.
|
|
25
|
-
*
|
|
26
|
-
* A key set comes from a PAGE, and a page has no ceiling (`list()` with no limit
|
|
27
|
-
* reads the table), so `where id in (…)` eventually meets the engine's limit.
|
|
28
|
-
* Measured on SQLite: 32 766 binds, and 32 767 answers `too many SQL variables`.
|
|
29
|
-
* SQL Server is the low one at 2100, which is why this is per dialect and not one
|
|
30
|
-
* constant — a batch that works on SQLite and dies on SQL Server is the same value
|
|
31
|
-
* behaving differently per engine, the thing this file exists to absorb.
|
|
32
|
-
*
|
|
33
|
-
* The number below is the limit MINUS a margin for the other values a statement
|
|
34
|
-
* carries (a filter, a cursor): a batch read is never the only thing in the query.
|
|
35
|
-
*/
|
|
13
|
+
/** How many values one statement may bind — what splits a batch read into several. */
|
|
36
14
|
maxBindings: number;
|
|
37
|
-
/**
|
|
38
|
-
* How this engine spells "write it, or replace what is there".
|
|
39
|
-
*
|
|
40
|
-
* `'on conflict'` is the standard clause (SQLite, Postgres); MySQL spells the same
|
|
41
|
-
* thing `ON DUPLICATE KEY UPDATE`; SQL Server has only `MERGE`, a different statement
|
|
42
|
-
* with different semantics — so it answers `false` and the port refuses by name
|
|
43
|
-
* rather than emulating a write with a read in front of it, which would be a lie
|
|
44
|
-
* about atomicity in an engine that has no transaction here either.
|
|
45
|
-
*/
|
|
15
|
+
/** How this engine spells "write it, or replace what is there". */
|
|
46
16
|
upsert: 'on conflict' | 'on duplicate key' | false;
|
|
47
|
-
/**
|
|
48
|
-
* Is this the engine refusing a duplicate, rather than failing?
|
|
49
|
-
*
|
|
50
|
-
* A driver reports it as a plain `Error` whose wording is the engine's own, so only a
|
|
51
|
-
* dialect can tell — the same reason `maxBindings` and `upsert` live here. Without it
|
|
52
|
-
* every engine's phrasing would be matched in one place, and this file exists so no
|
|
53
|
-
* other one learns a dialect.
|
|
54
|
-
*
|
|
55
|
-
* A false negative costs an INTERNAL_ERROR where a CONFLICT was due — which is what
|
|
56
|
-
* every engine answered before this existed, so nothing is made worse by a gap.
|
|
57
|
-
*/
|
|
17
|
+
/** Is this the engine refusing a duplicate, rather than failing? */
|
|
58
18
|
isUniqueViolation(error: unknown): boolean;
|
|
59
19
|
}
|
|
60
20
|
export declare const sqliteDialect: Dialect;
|
|
@@ -64,11 +24,8 @@ export declare const mssqlDialect: Dialect;
|
|
|
64
24
|
export declare const dialects: Record<DialectName, Dialect>;
|
|
65
25
|
export declare function resolveDialect(name: DialectName): Dialect;
|
|
66
26
|
/**
|
|
67
|
-
* The type this column is emitted with — what the entity stated when it named THIS
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* The fallback is what keeps the statement local: `columnType: { pg: 'tsvector' }` leaves
|
|
71
|
-
* SQLite exactly where it was, so the same entity still boots on every dialect.
|
|
27
|
+
* The type this column is emitted with — what the entity stated when it named THIS engine, the
|
|
28
|
+
* shape's own answer otherwise.
|
|
72
29
|
*/
|
|
73
30
|
export declare function columnTypeFor(dialect: Dialect, column: ColumnDef, keyed: boolean): string;
|
|
74
31
|
//# sourceMappingURL=dialect.d.ts.map
|
package/dist/dialect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC;AAE9D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,6BAA6B;IAC7B,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACtD;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sFAAsF;IACtF,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,KAAK,CAAC;IACnD,oEAAoE;IACpE,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAC5C;AAkBD,eAAO,MAAM,aAAa,EAAE,OAqB3B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,OA0BvB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,OAwB1B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,OAwB1B,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAKjD,CAAC;AAEF,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAIzD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAEzF"}
|
package/dist/dialect.js
CHANGED
|
@@ -123,11 +123,8 @@ export function resolveDialect(name) {
|
|
|
123
123
|
return dialect;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* The type this column is emitted with — what the entity stated when it named THIS
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* The fallback is what keeps the statement local: `columnType: { pg: 'tsvector' }` leaves
|
|
130
|
-
* SQLite exactly where it was, so the same entity still boots on every dialect.
|
|
126
|
+
* The type this column is emitted with — what the entity stated when it named THIS engine, the
|
|
127
|
+
* shape's own answer otherwise.
|
|
131
128
|
*/
|
|
132
129
|
export function columnTypeFor(dialect, column, keyed) {
|
|
133
130
|
return column.stated?.columnType?.[dialect.name] ?? dialect.columnType(column, keyed);
|
package/dist/dialect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/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U,cAAc,CAAC,IAAiB;IAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,aAAa,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3G,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,MAAiB,EAAE,KAAc;IAC/E,OAAO,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxF,CAAC"}
|
package/dist/diff.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diff — what the database is missing, compared to what the entities describe.
|
|
3
|
-
*
|
|
4
|
-
* Two states, one comparison, one realisation. The desired state comes from the
|
|
5
|
-
* entities; the actual one from Kysely's introspection, which is already
|
|
6
|
-
* engine-agnostic. The comparison itself is pure — no IO, no SQL.
|
|
7
|
-
*
|
|
8
|
-
* ADDITIVE ONLY, and that incapacity is the guarantee: a missing table is
|
|
9
|
-
* created, a missing column is added, and **nothing else ever happens**. Drops,
|
|
10
|
-
* renames and type changes are human intentions — a rename is not even
|
|
11
|
-
* detectable from a diff (it reads as a drop plus an add). Those belong in a
|
|
12
|
-
* written migration, never in an automatic pass.
|
|
13
|
-
*/
|
|
1
|
+
/** Diff — what the database is missing, compared to what the entities describe. */
|
|
14
2
|
import { type Kysely } from 'kysely';
|
|
15
3
|
import { type GenerateOptions } from './ddl.js';
|
|
16
4
|
import { type DialectName } from './dialect.js';
|
|
@@ -41,45 +29,19 @@ export type Change = {
|
|
|
41
29
|
/** Compare the two states. Pure — the only place that decides what is missing. */
|
|
42
30
|
export declare function delta(desired: TableDef[], actual: SchemaState): Change[];
|
|
43
31
|
/**
|
|
44
|
-
* Order the changes `delta` found, dialect-aware — `delta` itself stays pure and
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* SQLite resolves FK targets lazily and accepts any order, with no `ALTER TABLE
|
|
48
|
-
* ADD CONSTRAINT` to defer to — changes pass through unchanged. Every other
|
|
49
|
-
* engine needs a `createTable`'s FK targets to already exist: `orderTables`
|
|
50
|
-
* sorts the NEW tables among themselves and reports the edges a cycle forces to
|
|
51
|
-
* defer as `addConstraint` changes. An `addColumn` always lands last — its
|
|
52
|
-
* table already exists (that's why it's `addColumn` and not `createTable`), but
|
|
53
|
-
* its FK target might be one of THIS batch's new tables, so it waits until
|
|
54
|
-
* every `createTable`/`addConstraint` above it has run.
|
|
32
|
+
* Order the changes `delta` found, dialect-aware — `delta` itself stays pure and unordered, this
|
|
33
|
+
* is the one place that adds engine knowledge to the plan.
|
|
55
34
|
*/
|
|
56
35
|
export declare function orderChanges(changes: Change[], dialectName: DialectName): Change[];
|
|
57
|
-
/**
|
|
58
|
-
* Render one change.
|
|
59
|
-
*
|
|
60
|
-
* A column added to a populated table cannot be `NOT NULL` without a default —
|
|
61
|
-
* every engine refuses it. So an added column keeps its `NOT NULL` only when a
|
|
62
|
-
* default answers the existing rows; otherwise it lands nullable, and tightening
|
|
63
|
-
* it is a written migration.
|
|
64
|
-
*/
|
|
36
|
+
/** Render one change. */
|
|
65
37
|
export declare function changeSQL(change: Change, dialectName: DialectName): string;
|
|
66
38
|
/** Everything the database is missing, as statements ready to run. */
|
|
67
39
|
export declare function planMigration(app: AppLike, db: Kysely<any>, options?: GenerateOptions): Promise<{
|
|
68
40
|
changes: Change[];
|
|
69
41
|
statements: string[];
|
|
70
42
|
}>;
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
*
|
|
74
|
-
* Returns what it did, so a caller can log or refuse. Replaces the old
|
|
75
|
-
* create-if-not-exists pass: it also catches a field added to an existing entity,
|
|
76
|
-
* which used to be silently ignored.
|
|
77
|
-
*/
|
|
78
|
-
/**
|
|
79
|
-
* Bring the schema up to date. Takes the setup itself — `migrate(app, setup)` — so the
|
|
80
|
-
* common case never has to reach into `setup.db`, the one handle that meets no judge.
|
|
81
|
-
* A bare Kysely instance is still accepted, for a caller who holds only that.
|
|
82
|
-
*/
|
|
43
|
+
/** Bring the database up to what the entities describe — additively. */
|
|
44
|
+
/** Bring the schema up to date. */
|
|
83
45
|
export declare function migrate(app: AppLike, target: Kysely<any> | {
|
|
84
46
|
db: Kysely<any>;
|
|
85
47
|
}, options?: GenerateOptions): Promise<Change[]>;
|
package/dist/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAkE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhH,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,QAAQ,EACd,MAAM,YAAY,CAAC;AAGpB,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAEnD,2FAA2F;AAC3F,wBAAsB,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAOvE;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,EAAE,CAEjF;AAED,MAAM,MAAM,MAAM,GACd;IAAE,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,CAOnB"}
|
package/dist/diff.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diff — what the database is missing, compared to what the entities describe.
|
|
3
|
-
*
|
|
4
|
-
* Two states, one comparison, one realisation. The desired state comes from the
|
|
5
|
-
* entities; the actual one from Kysely's introspection, which is already
|
|
6
|
-
* engine-agnostic. The comparison itself is pure — no IO, no SQL.
|
|
7
|
-
*
|
|
8
|
-
* ADDITIVE ONLY, and that incapacity is the guarantee: a missing table is
|
|
9
|
-
* created, a missing column is added, and **nothing else ever happens**. Drops,
|
|
10
|
-
* renames and type changes are human intentions — a rename is not even
|
|
11
|
-
* detectable from a diff (it reads as a drop plus an add). Those belong in a
|
|
12
|
-
* written migration, never in an automatic pass.
|
|
13
|
-
*/
|
|
1
|
+
/** Diff — what the database is missing, compared to what the entities describe. */
|
|
14
2
|
import { sql } from 'kysely';
|
|
15
3
|
import { addForeignKeyConstraintSQL, compiler, createTableSQL, indexSQL } from './ddl.js';
|
|
16
4
|
import { checkFor } from './check.js';
|
|
17
5
|
import { columnTypeFor, resolveDialect } from './dialect.js';
|
|
18
|
-
import { isKeyed,
|
|
6
|
+
import { isKeyed, toTables, toTableName, } from './table.js';
|
|
7
|
+
import { orderTables } from './order.js';
|
|
19
8
|
/** Read the live schema. Only names are needed — an additive pass never inspects types. */
|
|
20
9
|
export async function actualState(db) {
|
|
21
10
|
const state = new Map();
|
|
@@ -48,26 +37,21 @@ export function delta(desired, actual) {
|
|
|
48
37
|
// cannot see whether an index exists. `CREATE INDEX IF NOT EXISTS` is idempotent, so
|
|
49
38
|
// proposing it every time is cheaper and more honest than introspecting to guess —
|
|
50
39
|
// the alternative would be an index that a `unique()` added later never gets.
|
|
40
|
+
//
|
|
41
|
+
// `unique` comes here too, and for that very reason: written as a column constraint it
|
|
42
|
+
// only ever reached a table being created, so the rule was declared and never realized on
|
|
43
|
+
// a database that had already lived. A unique index is the one form that can arrive late.
|
|
51
44
|
for (const table of desired) {
|
|
52
45
|
for (const column of table.columns) {
|
|
53
|
-
if (column.index)
|
|
46
|
+
if (column.index || (column.unique && !column.primary))
|
|
54
47
|
changes.push({ kind: 'createIndex', table, column });
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
return changes;
|
|
58
51
|
}
|
|
59
52
|
/**
|
|
60
|
-
* Order the changes `delta` found, dialect-aware — `delta` itself stays pure and
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* SQLite resolves FK targets lazily and accepts any order, with no `ALTER TABLE
|
|
64
|
-
* ADD CONSTRAINT` to defer to — changes pass through unchanged. Every other
|
|
65
|
-
* engine needs a `createTable`'s FK targets to already exist: `orderTables`
|
|
66
|
-
* sorts the NEW tables among themselves and reports the edges a cycle forces to
|
|
67
|
-
* defer as `addConstraint` changes. An `addColumn` always lands last — its
|
|
68
|
-
* table already exists (that's why it's `addColumn` and not `createTable`), but
|
|
69
|
-
* its FK target might be one of THIS batch's new tables, so it waits until
|
|
70
|
-
* every `createTable`/`addConstraint` above it has run.
|
|
53
|
+
* Order the changes `delta` found, dialect-aware — `delta` itself stays pure and unordered, this
|
|
54
|
+
* is the one place that adds engine knowledge to the plan.
|
|
71
55
|
*/
|
|
72
56
|
export function orderChanges(changes, dialectName) {
|
|
73
57
|
if (dialectName === 'sqlite')
|
|
@@ -90,14 +74,7 @@ export function orderChanges(changes, dialectName) {
|
|
|
90
74
|
// Indexes last: the column they stand on may be one this very batch added.
|
|
91
75
|
return [...createChanges, ...constraintChanges, ...addColumns, ...indexes];
|
|
92
76
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Render one change.
|
|
95
|
-
*
|
|
96
|
-
* A column added to a populated table cannot be `NOT NULL` without a default —
|
|
97
|
-
* every engine refuses it. So an added column keeps its `NOT NULL` only when a
|
|
98
|
-
* default answers the existing rows; otherwise it lands nullable, and tightening
|
|
99
|
-
* it is a written migration.
|
|
100
|
-
*/
|
|
77
|
+
/** Render one change. */
|
|
101
78
|
export function changeSQL(change, dialectName) {
|
|
102
79
|
const dialect = resolveDialect(dialectName);
|
|
103
80
|
if (change.kind === 'createTable') {
|
|
@@ -119,11 +96,14 @@ export function changeSQL(change, dialectName) {
|
|
|
119
96
|
.schema.alterTable(table.name)
|
|
120
97
|
.addColumn(column.name, sql.raw(type), (col) => {
|
|
121
98
|
let built = col;
|
|
122
|
-
if (column.default !== undefined)
|
|
99
|
+
if (column.default !== undefined)
|
|
123
100
|
built = built.defaultTo(column.default);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
// Stated whether a default fills it or not: the same declaration gave NOT NULL on a
|
|
102
|
+
// fresh table and nothing on a migrated one, so two databases of one entity promised
|
|
103
|
+
// different things. Without a default the engine refuses on a table holding rows —
|
|
104
|
+
// which is the refusal `planStep` already names, arriving here instead of never.
|
|
105
|
+
if (!column.nullable)
|
|
106
|
+
built = built.notNull();
|
|
127
107
|
if (column.references) {
|
|
128
108
|
built = built.references(`${column.references.table}.${column.references.column}`);
|
|
129
109
|
if (column.references.onDelete)
|
|
@@ -145,18 +125,8 @@ export async function planMigration(app, db, options) {
|
|
|
145
125
|
const changes = orderChanges(delta(desiredTables(app, options), await actualState(db)), dialect);
|
|
146
126
|
return { changes, statements: changes.map((change) => changeSQL(change, dialect)) };
|
|
147
127
|
}
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
* Returns what it did, so a caller can log or refuse. Replaces the old
|
|
152
|
-
* create-if-not-exists pass: it also catches a field added to an existing entity,
|
|
153
|
-
* which used to be silently ignored.
|
|
154
|
-
*/
|
|
155
|
-
/**
|
|
156
|
-
* Bring the schema up to date. Takes the setup itself — `migrate(app, setup)` — so the
|
|
157
|
-
* common case never has to reach into `setup.db`, the one handle that meets no judge.
|
|
158
|
-
* A bare Kysely instance is still accepted, for a caller who holds only that.
|
|
159
|
-
*/
|
|
128
|
+
/** Bring the database up to what the entities describe — additively. */
|
|
129
|
+
/** Bring the schema up to date. */
|
|
160
130
|
export async function migrate(app, target, options) {
|
|
161
131
|
const db = target.db ?? target;
|
|
162
132
|
const { changes, statements } = await planMigration(app, db, options);
|
package/dist/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAwB,MAAM,UAAU,CAAC;AAChH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAoB,MAAM,cAAc,CAAC;AAC/E,OAAO,EACL,OAAO,EACP,QAAQ,EACR,WAAW,GAIZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKzC,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAe;IAC/C,MAAM,KAAK,GAAgB,IAAI,GAAG,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM;YAAE,SAAS;QAC3B,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,GAAY,EAAE,OAAyB;IACnE,OAAO,QAAQ,CAAC,GAAG,EAAE,O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AAY,EACZ,EAAe,EACf,OAAyB;IAEzB,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC;IAC7C,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACjG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;AACtF,CAAC;AAED,wEAAwE;AACxE,mCAAmC;AACnC,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAY,EACZ,MAAyC,EACzC,OAAyB;IAEzB,MAAM,EAAE,GAAI,MAA+B,CAAC,EAAE,IAAK,MAAsB,CAAC;IAC1E,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IACtE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/fields.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What an entity may state for THIS adapter, declared from OUTSIDE `@fougere/schema` —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* It replaces what the shape would have given, and only for the engine it names: an
|
|
6
|
-
* engine absent here keeps the shape's answer, so the entity still boots on every
|
|
7
|
-
* dialect. What an engine must HONOR is not stated here — it is a decision, and it
|
|
8
|
-
* belongs in `fougere.config.ts` beside `remotes:`, `sources:` and `ports:`.
|
|
2
|
+
* What an entity may state for THIS adapter, declared from OUTSIDE `@fougere/schema` — which names
|
|
3
|
+
* no engine and no column type, and must not learn one to let this exist.
|
|
9
4
|
*/
|
|
10
|
-
import
|
|
5
|
+
import { AdapterFieldValidator } from '@fougere/schema';
|
|
6
|
+
import ENTRY_FORMAT from './adapter.schema.json';
|
|
7
|
+
/** The engines the format names — the one list, read off the file that states it. */
|
|
8
|
+
type Engine = keyof typeof ENTRY_FORMAT.properties.columnType.properties;
|
|
11
9
|
/** What sql holds, addressed by field — the shape every augmentation of the registry takes. */
|
|
12
10
|
export type SqlFields<K extends string> = Readonly<Partial<Record<K, SqlField>>>;
|
|
13
11
|
export interface SqlField {
|
|
14
12
|
/** The column type to emit, per engine. An engine absent here keeps the shape's own. */
|
|
15
|
-
readonly columnType?: Readonly<Partial<Record<
|
|
13
|
+
readonly columnType?: Readonly<Partial<Record<Engine, string>>>;
|
|
16
14
|
}
|
|
15
|
+
/** Judges what an entity states under `adapters.sql`, against the format this adapter ships. */
|
|
16
|
+
export declare const sqlEntries: AdapterFieldValidator;
|
|
17
17
|
declare module '@fougere/schema' {
|
|
18
18
|
interface FougereEntityAdapters<K extends string> {
|
|
19
19
|
sql?: SqlFields<K>;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
export {};
|
|
22
23
|
//# sourceMappingURL=fields.d.ts.map
|