@c9up/atlas 0.2.5 → 0.2.7
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/db.win32-x64-msvc.node +0 -0
- package/dist/BaseEntity.d.ts +40 -27
- package/dist/BaseEntity.d.ts.map +1 -1
- package/dist/BaseEntity.js +82 -81
- package/dist/BaseEntity.js.map +1 -1
- package/dist/BaseModel.d.ts +10 -0
- package/dist/BaseModel.d.ts.map +1 -1
- package/dist/BaseModel.js +10 -0
- package/dist/BaseModel.js.map +1 -1
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +31 -5
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ConnectionManager.d.ts.map +1 -1
- package/dist/ConnectionManager.js +22 -1
- package/dist/ConnectionManager.js.map +1 -1
- package/dist/ModelQuery.d.ts +22 -1
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +43 -20
- package/dist/ModelQuery.js.map +1 -1
- package/dist/Transaction.d.ts +9 -0
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +14 -0
- package/dist/Transaction.js.map +1 -1
- package/dist/adapters/NapiDbAdapter.d.ts.map +1 -1
- package/dist/adapters/NapiDbAdapter.js +7 -0
- package/dist/adapters/NapiDbAdapter.js.map +1 -1
- package/dist/decorators/entity.d.ts +4 -0
- package/dist/decorators/entity.d.ts.map +1 -1
- package/dist/decorators/entity.js +9 -1
- package/dist/decorators/entity.js.map +1 -1
- package/dist/decorators/hooks.d.ts +28 -0
- package/dist/decorators/hooks.d.ts.map +1 -1
- package/dist/decorators/hooks.js +43 -0
- package/dist/decorators/hooks.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/query/DatabaseQueryBuilder.d.ts +24 -0
- package/dist/query/DatabaseQueryBuilder.d.ts.map +1 -1
- package/dist/query/DatabaseQueryBuilder.js +98 -3
- package/dist/query/DatabaseQueryBuilder.js.map +1 -1
- package/dist/schema/SchemaBuilder.d.ts +2 -1
- package/dist/schema/SchemaBuilder.d.ts.map +1 -1
- package/dist/schema/SchemaBuilder.js +2 -1
- package/dist/schema/SchemaBuilder.js.map +1 -1
- package/dist/schema/TableBuilder.d.ts +140 -132
- package/dist/schema/TableBuilder.d.ts.map +1 -1
- package/dist/schema/TableBuilder.js +232 -231
- package/dist/schema/TableBuilder.js.map +1 -1
- package/dist/services/db.d.ts +7 -0
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/db.js.map +1 -1
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +4 -4
- package/src/BaseEntity.ts +115 -85
- package/src/BaseModel.ts +10 -0
- package/src/BaseRepository.ts +36 -4
- package/src/ConnectionManager.ts +26 -1
- package/src/ModelQuery.ts +73 -23
- package/src/Transaction.ts +23 -0
- package/src/adapters/NapiDbAdapter.ts +7 -0
- package/src/decorators/entity.ts +13 -1
- package/src/decorators/hooks.ts +67 -0
- package/src/index.ts +8 -1
- package/src/query/DatabaseQueryBuilder.ts +118 -7
- package/src/schema/SchemaBuilder.ts +2 -1
- package/src/schema/TableBuilder.ts +331 -303
- package/src/services/db.ts +7 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type AtlasDialect } from "../query/native.js";
|
|
10
10
|
import { type DefaultValue } from "./raw.js";
|
|
11
|
-
import { type AlterOperation, type CheckOperator, type CheckValue, type ColumnDefinition, type ForeignKeyReference, type IndexDefinition, type ReferentialAction, type TextVariant } from "./types.js";
|
|
11
|
+
import { type AlterOperation, type CheckExpression, type CheckOperator, type CheckValue, type ColumnDefinition, type ForeignKeyReference, type IndexDefinition, type ReferentialAction, type TextVariant } from "./types.js";
|
|
12
12
|
/**
|
|
13
13
|
* The chainable returned by `table.foreign([...])`, so the target reads in
|
|
14
14
|
* Knex order: `.references([...]).inTable('other').onDelete('cascade')`. It
|
|
@@ -29,6 +29,104 @@ export declare class ForeignKeyBuilder {
|
|
|
29
29
|
onDelete(action: ReferentialAction): this;
|
|
30
30
|
onUpdate(action: ReferentialAction): this;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The chainable a column-type method hands back — Knex's `ColumnBuilder`.
|
|
34
|
+
*
|
|
35
|
+
* It is bound to ITS OWN column, which is what lets `table.comment()` mean the
|
|
36
|
+
* table comment and `table.string('x').comment()` the column one. A builder
|
|
37
|
+
* flattened onto the table cannot tell those apart, and Knex has both.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ColumnBuilder {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(table: TableBuilder, column: ColumnDefinition);
|
|
42
|
+
notNullable(): this;
|
|
43
|
+
nullable(): this;
|
|
44
|
+
/**
|
|
45
|
+
* Set a column default. JS literals are quoted/escaped (`'x'`, `123`,
|
|
46
|
+
* `true` — Lucid/Knex semantics); wrap SQL expressions in {@link raw} (or
|
|
47
|
+
* use `Migration.now()`) to emit them verbatim.
|
|
48
|
+
*/
|
|
49
|
+
defaultTo(value: DefaultValue): this;
|
|
50
|
+
/** MySQL `UNSIGNED` numeric modifier (Lucid `unsigned()`). No-op on pg/sqlite. */
|
|
51
|
+
unsigned(): this;
|
|
52
|
+
/**
|
|
53
|
+
* Declare the current column a foreign key.
|
|
54
|
+
*
|
|
55
|
+
* - `references('users', 'id')` — atlas form `(table, column='id')`.
|
|
56
|
+
* - `references('users.id')` — Lucid/Knex dotted `'table.column'` shorthand, so
|
|
57
|
+
* a migration copied from Lucid resolves the target the same way. A single
|
|
58
|
+
* argument without a dot is treated as the table name (column defaults to
|
|
59
|
+
* `id`), preserving the atlas one-arg behaviour.
|
|
60
|
+
*/
|
|
61
|
+
references(tableOrPath: string, column?: string): this;
|
|
62
|
+
/**
|
|
63
|
+
* Referential action for the current column's foreign key `ON DELETE`
|
|
64
|
+
* (Lucid parity). Must follow {@link references}.
|
|
65
|
+
*/
|
|
66
|
+
onDelete(action: ReferentialAction): this;
|
|
67
|
+
/** Referential action for the current column's foreign key `ON UPDATE`. Must follow {@link references}. */
|
|
68
|
+
onUpdate(action: ReferentialAction): this;
|
|
69
|
+
/**
|
|
70
|
+
* Comment this column (Lucid/Knex column `comment()`). Inline on MySQL, a
|
|
71
|
+
* separate `COMMENT ON COLUMN` on Postgres, dropped on SQLite. The TABLE
|
|
72
|
+
* comment is `table.comment()` — the receiver tells them apart, as in Knex.
|
|
73
|
+
*/
|
|
74
|
+
comment(text: string): this;
|
|
75
|
+
/** Collate this column (Lucid/Knex column `collate()`). The table collation is `table.collate()`. */
|
|
76
|
+
collate(collation: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* Place an added column first (Lucid/Knex `first()`). MySQL-only —
|
|
79
|
+
* Postgres and SQLite always append, and the Rust compiler raises
|
|
80
|
+
* `E_UNSUPPORTED` rather than dropping the instruction silently.
|
|
81
|
+
*/
|
|
82
|
+
first(): this;
|
|
83
|
+
/** Place an added column after `column` (Lucid/Knex `after()`). MySQL-only — see {@link first}. */
|
|
84
|
+
after(column: string): this;
|
|
85
|
+
/** `CHECK (col > 0)` on this column (Lucid/Knex `checkPositive`). */
|
|
86
|
+
checkPositive(constraintName?: string): this;
|
|
87
|
+
/** `CHECK (col < 0)` on this column (Lucid/Knex `checkNegative`). */
|
|
88
|
+
checkNegative(constraintName?: string): this;
|
|
89
|
+
/** `CHECK (col IN (…))` on this column (Lucid/Knex `checkIn`). Values are quoted, never interpolated raw. */
|
|
90
|
+
checkIn(values: readonly CheckValue[], constraintName?: string): this;
|
|
91
|
+
/** `CHECK (col NOT IN (…))` on this column (Lucid/Knex `checkNotIn`). */
|
|
92
|
+
checkNotIn(values: readonly CheckValue[], constraintName?: string): this;
|
|
93
|
+
/**
|
|
94
|
+
* `CHECK (col BETWEEN lo AND hi)` on this column (Lucid/Knex
|
|
95
|
+
* `checkBetween`). Accepts one `[min, max]` interval or a list of them —
|
|
96
|
+
* several intervals are OR'd together, as in Knex.
|
|
97
|
+
*/
|
|
98
|
+
checkBetween(range: readonly CheckValue[] | readonly (readonly CheckValue[])[], constraintName?: string): this;
|
|
99
|
+
/** `CHECK (LENGTH(col) <op> n)` on this column (Lucid/Knex `checkLength`). The operator is allow-listed by the Rust compiler. */
|
|
100
|
+
checkLength(operator: CheckOperator, length: number, constraintName?: string): this;
|
|
101
|
+
/**
|
|
102
|
+
* `CHECK (col ~ 'pattern')` on this column (Lucid/Knex `checkRegex`).
|
|
103
|
+
* Postgres spells it `~`; MySQL and SQLite use `REGEXP`.
|
|
104
|
+
*
|
|
105
|
+
* SQLite parses `REGEXP` but ships no implementation — the constraint only
|
|
106
|
+
* works if the connection registers a `regexp` function. Knex behaves the
|
|
107
|
+
* same way, so this is parity rather than a new trap, but it is worth
|
|
108
|
+
* knowing before you rely on it there.
|
|
109
|
+
*/
|
|
110
|
+
checkRegex(pattern: string, constraintName?: string): this;
|
|
111
|
+
/** Mark this column the primary key (Lucid/Knex column `primary()`). */
|
|
112
|
+
primary(): this;
|
|
113
|
+
/** Mark this column `UNIQUE` (Lucid/Knex column `unique()`). */
|
|
114
|
+
unique(): this;
|
|
115
|
+
/** Index this column (Lucid/Knex column `index()`). */
|
|
116
|
+
index(name?: string): this;
|
|
117
|
+
/**
|
|
118
|
+
* Apply this definition as a type change instead of an `ADD COLUMN`
|
|
119
|
+
* (Lucid/Knex `alter()`).
|
|
120
|
+
*
|
|
121
|
+
* Nullability moves only if `.nullable()` / `.notNullable()` was called
|
|
122
|
+
* before this — a bare `t.string('x').alter()` changes the type and leaves
|
|
123
|
+
* the NOT NULL constraint exactly as it is.
|
|
124
|
+
*
|
|
125
|
+
* SQLite cannot alter a column in place; the Rust compiler rejects it with
|
|
126
|
+
* `E_UNSUPPORTED` rather than emitting a table rebuild behind your back.
|
|
127
|
+
*/
|
|
128
|
+
alter(): this;
|
|
129
|
+
}
|
|
32
130
|
/**
|
|
33
131
|
* Whether the builder is filling a `CREATE TABLE` or an `ALTER TABLE`. In
|
|
34
132
|
* `alter` mode a column-type method (`t.string('x')`) becomes `ADD COLUMN`,
|
|
@@ -41,48 +139,48 @@ export declare class TableBuilder {
|
|
|
41
139
|
readonly tableName: string;
|
|
42
140
|
readonly mode: TableBuilderMode;
|
|
43
141
|
constructor(tableName: string, mode?: TableBuilderMode);
|
|
44
|
-
uuid(name: string):
|
|
142
|
+
uuid(name: string): ColumnBuilder;
|
|
45
143
|
/**
|
|
46
144
|
* Auto-incrementing integer primary key (Lucid `increments()`). The Rust
|
|
47
145
|
* compiler emits the dialect-appropriate identity clause (SQLite
|
|
48
146
|
* `AUTOINCREMENT`, Postgres `GENERATED ... AS IDENTITY`, MySQL
|
|
49
147
|
* `AUTO_INCREMENT`). For a 64-bit key use `bigIncrements()`.
|
|
50
148
|
*/
|
|
51
|
-
increments(name?: string):
|
|
149
|
+
increments(name?: string): ColumnBuilder;
|
|
52
150
|
/** Auto-incrementing 64-bit primary key (Lucid `bigIncrements()`). */
|
|
53
|
-
bigIncrements(name?: string):
|
|
54
|
-
string(name: string, length?: number):
|
|
151
|
+
bigIncrements(name?: string): ColumnBuilder;
|
|
152
|
+
string(name: string, length?: number): ColumnBuilder;
|
|
55
153
|
/**
|
|
56
154
|
* Text column (Lucid/Knex `text(name, textType)`). `textType` widens the
|
|
57
155
|
* MySQL type (`MEDIUMTEXT` / `LONGTEXT`); Postgres and SQLite have a single
|
|
58
156
|
* unbounded `TEXT` and ignore it.
|
|
59
157
|
*/
|
|
60
|
-
text(name: string, textType?: TextVariant):
|
|
61
|
-
integer(name: string):
|
|
158
|
+
text(name: string, textType?: TextVariant): ColumnBuilder;
|
|
159
|
+
integer(name: string): ColumnBuilder;
|
|
62
160
|
/** 24-bit integer (Lucid/Knex `mediumint`). MySQL `MEDIUMINT`; pg/SQLite widen to `INTEGER`. */
|
|
63
|
-
mediumint(name: string):
|
|
161
|
+
mediumint(name: string): ColumnBuilder;
|
|
64
162
|
/** 8-bit integer (Lucid `tinyint`). MySQL `TINYINT`; Postgres widens to `SMALLINT`; SQLite `INTEGER`. */
|
|
65
|
-
tinyint(name: string):
|
|
163
|
+
tinyint(name: string): ColumnBuilder;
|
|
66
164
|
/** 16-bit integer (Lucid `smallint`). `SMALLINT` on pg/mysql, `INTEGER` on SQLite. */
|
|
67
|
-
smallint(name: string):
|
|
68
|
-
bigInteger(name: string):
|
|
69
|
-
decimal(name: string, precision?: number, scale?: number):
|
|
165
|
+
smallint(name: string): ColumnBuilder;
|
|
166
|
+
bigInteger(name: string): ColumnBuilder;
|
|
167
|
+
decimal(name: string, precision?: number, scale?: number): ColumnBuilder;
|
|
70
168
|
/**
|
|
71
169
|
* Single-precision float (Lucid `float`). `REAL` on pg/sqlite, `FLOAT` on
|
|
72
170
|
* MySQL. `precision`/`scale` render `FLOAT(p, s)` on MySQL only — pg and
|
|
73
171
|
* SQLite have fixed-width floats and ignore them.
|
|
74
172
|
*/
|
|
75
|
-
float(name: string, precision?: number, scale?: number):
|
|
173
|
+
float(name: string, precision?: number, scale?: number): ColumnBuilder;
|
|
76
174
|
/** Double-precision float (Lucid `double`). `DOUBLE PRECISION` on pg, `REAL` on SQLite, `DOUBLE` on MySQL. See {@link float} for precision/scale. */
|
|
77
|
-
double(name: string, precision?: number, scale?: number):
|
|
78
|
-
boolean(name: string):
|
|
79
|
-
date(name: string):
|
|
175
|
+
double(name: string, precision?: number, scale?: number): ColumnBuilder;
|
|
176
|
+
boolean(name: string): ColumnBuilder;
|
|
177
|
+
date(name: string): ColumnBuilder;
|
|
80
178
|
/**
|
|
81
179
|
* Time of day (Lucid `time`). `TIME` on pg/mysql, `TEXT` on SQLite.
|
|
82
180
|
* `precision` renders `TIME(p)` fractional seconds (ignored on SQLite,
|
|
83
181
|
* which has no time type to carry it).
|
|
84
182
|
*/
|
|
85
|
-
time(name: string, precision?: number):
|
|
183
|
+
time(name: string, precision?: number): ColumnBuilder;
|
|
86
184
|
/**
|
|
87
185
|
* Timestamp column (Lucid `timestamp(name, options)`).
|
|
88
186
|
*
|
|
@@ -94,12 +192,12 @@ export declare class TableBuilder {
|
|
|
94
192
|
timestamp(name: string, options?: {
|
|
95
193
|
useTz?: boolean;
|
|
96
194
|
precision?: number;
|
|
97
|
-
}):
|
|
195
|
+
}): ColumnBuilder;
|
|
98
196
|
/** Alias of {@link timestamp} (Lucid `dateTime`). Use `{ useTz: true }` or {@link timestamptz} for a tz-aware column. */
|
|
99
197
|
dateTime(name: string, options?: {
|
|
100
198
|
useTz?: boolean;
|
|
101
199
|
precision?: number;
|
|
102
|
-
}):
|
|
200
|
+
}): ColumnBuilder;
|
|
103
201
|
/**
|
|
104
202
|
* `timestamp WITH time zone` — Postgres normalises every writer (atlas,
|
|
105
203
|
* `DEFAULT now()`, raw SQL) to UTC, so reads are unambiguous regardless of
|
|
@@ -109,24 +207,18 @@ export declare class TableBuilder {
|
|
|
109
207
|
* from the SQL type). On MySQL/SQLite (no real tz type) it degrades to the
|
|
110
208
|
* plain timestamp mapping.
|
|
111
209
|
*/
|
|
112
|
-
timestamptz(name: string):
|
|
113
|
-
json(name: string):
|
|
210
|
+
timestamptz(name: string): ColumnBuilder;
|
|
211
|
+
json(name: string): ColumnBuilder;
|
|
114
212
|
/**
|
|
115
213
|
* Binary JSON (Lucid/Knex `jsonb`). `JSONB` on pg, `JSON` on MySQL, `TEXT`
|
|
116
214
|
* on SQLite.
|
|
117
|
-
*
|
|
118
|
-
* Deviation, named: atlas's {@link json} already maps to `JSONB` on
|
|
119
|
-
* Postgres (it predates this method), where Lucid's `json()` maps to
|
|
120
|
-
* `json`. Leaving `json()` alone avoids silently rewriting the physical
|
|
121
|
-
* type of existing columns and desyncing `SchemaCheck`, so on Postgres the
|
|
122
|
-
* two spellings coincide.
|
|
123
215
|
*/
|
|
124
|
-
jsonb(name: string):
|
|
216
|
+
jsonb(name: string): ColumnBuilder;
|
|
125
217
|
/**
|
|
126
218
|
* Binary blob (Lucid/Knex `binary(name, length)`). `BYTEA` on pg, `BLOB` on
|
|
127
219
|
* SQLite; on MySQL `length` selects `VARBINARY(n)` over `BLOB`.
|
|
128
220
|
*/
|
|
129
|
-
binary(name: string, length?: number):
|
|
221
|
+
binary(name: string, length?: number): ColumnBuilder;
|
|
130
222
|
/**
|
|
131
223
|
* A column typed with a verbatim dialect type (Lucid/Knex `specificType`) —
|
|
132
224
|
* the escape hatch for types atlas has no method for (`inet`, `tsvector`,
|
|
@@ -137,13 +229,13 @@ export declare class TableBuilder {
|
|
|
137
229
|
* narrow grammar (letters, digits, spaces, `_`, and one parenthesised
|
|
138
230
|
* argument list) and rejects anything else with `E_UNSAFE_SQL`.
|
|
139
231
|
*/
|
|
140
|
-
specificType(name: string, type: string):
|
|
232
|
+
specificType(name: string, type: string): ColumnBuilder;
|
|
141
233
|
/**
|
|
142
234
|
* Fixed value-set column (Lucid `enum`). MySQL renders a native `ENUM(...)`;
|
|
143
235
|
* Postgres and SQLite render `TEXT` plus a `CHECK (col IN (...))` that pins the
|
|
144
236
|
* value set. At least one value is required.
|
|
145
237
|
*/
|
|
146
|
-
enum(name: string, values: string[]):
|
|
238
|
+
enum(name: string, values: string[]): ColumnBuilder;
|
|
147
239
|
/**
|
|
148
240
|
* UUID primary key with Postgres-only `gen_random_uuid()` default.
|
|
149
241
|
*
|
|
@@ -164,7 +256,7 @@ export declare class TableBuilder {
|
|
|
164
256
|
* (A dialect-aware escape hatch can be added later if a future story needs
|
|
165
257
|
* per-dialect PK defaults.)
|
|
166
258
|
*/
|
|
167
|
-
id():
|
|
259
|
+
id(): ColumnBuilder;
|
|
168
260
|
/**
|
|
169
261
|
* `created_at` + `updated_at` columns with Postgres-only `DEFAULT NOW()`.
|
|
170
262
|
*
|
|
@@ -200,105 +292,24 @@ export declare class TableBuilder {
|
|
|
200
292
|
* `timestamps(true, true)` form both port to SQLite/Postgres/MySQL unchanged.
|
|
201
293
|
*/
|
|
202
294
|
timestamps(useTimestamps?: boolean, defaultToNow?: boolean): this;
|
|
203
|
-
notNullable(): this;
|
|
204
|
-
nullable(): this;
|
|
205
|
-
/**
|
|
206
|
-
* Set a column default. JS literals are quoted/escaped (`'x'`, `123`,
|
|
207
|
-
* `true` — Lucid/Knex semantics); wrap SQL expressions in {@link raw} (or
|
|
208
|
-
* use `Migration.now()`) to emit them verbatim.
|
|
209
|
-
*/
|
|
210
|
-
defaultTo(value: DefaultValue): this;
|
|
211
|
-
/** MySQL `UNSIGNED` numeric modifier (Lucid `unsigned()`). No-op on pg/sqlite. */
|
|
212
|
-
unsigned(): this;
|
|
213
|
-
/**
|
|
214
|
-
* Declare the current column a foreign key.
|
|
215
|
-
*
|
|
216
|
-
* - `references('users', 'id')` — atlas form `(table, column='id')`.
|
|
217
|
-
* - `references('users.id')` — Lucid/Knex dotted `'table.column'` shorthand, so
|
|
218
|
-
* a migration copied from Lucid resolves the target the same way. A single
|
|
219
|
-
* argument without a dot is treated as the table name (column defaults to
|
|
220
|
-
* `id`), preserving the atlas one-arg behaviour.
|
|
221
|
-
*/
|
|
222
|
-
references(tableOrPath: string, column?: string): this;
|
|
223
|
-
/**
|
|
224
|
-
* Referential action for the current column's foreign key `ON DELETE`
|
|
225
|
-
* (Lucid parity). Must follow {@link references}.
|
|
226
|
-
*/
|
|
227
|
-
onDelete(action: ReferentialAction): this;
|
|
228
|
-
/** Referential action for the current column's foreign key `ON UPDATE`. Must follow {@link references}. */
|
|
229
|
-
onUpdate(action: ReferentialAction): this;
|
|
230
|
-
/**
|
|
231
|
-
* Comment the current **column** (Lucid/Knex column `comment()`). Inline on
|
|
232
|
-
* MySQL, a separate `COMMENT ON COLUMN` on Postgres, dropped on SQLite.
|
|
233
|
-
*
|
|
234
|
-
* Deviation, named: Knex's `table.comment()` is the TABLE comment, because
|
|
235
|
-
* its column methods return a separate column builder. Atlas flattens the
|
|
236
|
-
* column modifiers onto the table builder (`.notNullable()`, `.unique()`,
|
|
237
|
-
* `.defaultTo()` all work this way), so `comment()` follows that same rule
|
|
238
|
-
* and the table comment is {@link tableComment}. Resolving it by "is a
|
|
239
|
-
* column pending?" would be exactly the kind of guessing that bites later.
|
|
240
|
-
*/
|
|
241
|
-
comment(text: string): this;
|
|
242
|
-
/** Collate the current **column** (Lucid/Knex column `collate()`). See {@link comment} for why the table form is {@link tableCollate}. */
|
|
243
|
-
collate(collation: string): this;
|
|
244
|
-
/**
|
|
245
|
-
* Place an added column first (Lucid/Knex `first()`). MySQL-only —
|
|
246
|
-
* Postgres and SQLite always append, and the Rust compiler raises
|
|
247
|
-
* `E_UNSUPPORTED` rather than dropping the instruction silently.
|
|
248
|
-
*/
|
|
249
|
-
first(): this;
|
|
250
|
-
/** Place an added column after `column` (Lucid/Knex `after()`). MySQL-only — see {@link first}. */
|
|
251
|
-
after(column: string): this;
|
|
252
|
-
/** `CHECK (col > 0)` on the current column (Lucid/Knex `checkPositive`). */
|
|
253
|
-
checkPositive(constraintName?: string): this;
|
|
254
|
-
/** `CHECK (col < 0)` on the current column (Lucid/Knex `checkNegative`). */
|
|
255
|
-
checkNegative(constraintName?: string): this;
|
|
256
|
-
/** `CHECK (col IN (…))` on the current column (Lucid/Knex `checkIn`). Values are quoted, never interpolated raw. */
|
|
257
|
-
checkIn(values: readonly CheckValue[], constraintName?: string): this;
|
|
258
|
-
/** `CHECK (col NOT IN (…))` on the current column (Lucid/Knex `checkNotIn`). */
|
|
259
|
-
checkNotIn(values: readonly CheckValue[], constraintName?: string): this;
|
|
260
|
-
/**
|
|
261
|
-
* `CHECK (col BETWEEN lo AND hi)` on the current column (Lucid/Knex
|
|
262
|
-
* `checkBetween`). Accepts one `[min, max]` interval or a list of them —
|
|
263
|
-
* several intervals are OR'd together, as in Knex.
|
|
264
|
-
*/
|
|
265
|
-
checkBetween(range: readonly CheckValue[] | readonly (readonly CheckValue[])[], constraintName?: string): this;
|
|
266
|
-
/** `CHECK (LENGTH(col) <op> n)` on the current column (Lucid/Knex `checkLength`). The operator is allow-listed by the Rust compiler. */
|
|
267
|
-
checkLength(operator: CheckOperator, length: number, constraintName?: string): this;
|
|
268
|
-
/**
|
|
269
|
-
* `CHECK (col ~ 'pattern')` on the current column (Lucid/Knex `checkRegex`).
|
|
270
|
-
* Postgres spells it `~`; MySQL and SQLite use `REGEXP`.
|
|
271
|
-
*
|
|
272
|
-
* SQLite parses `REGEXP` but ships no implementation — the constraint only
|
|
273
|
-
* works if the connection registers a `regexp` function. Knex behaves the
|
|
274
|
-
* same way, so this is parity rather than a new trap, but it is worth
|
|
275
|
-
* knowing before you rely on it there.
|
|
276
|
-
*/
|
|
277
|
-
checkRegex(pattern: string, constraintName?: string): this;
|
|
278
295
|
/**
|
|
279
296
|
* A free-form `CHECK (predicate)` (Lucid/Knex `check`). The predicate is
|
|
280
297
|
* emitted verbatim — exactly as trusted as {@link Schema.raw}, so never
|
|
281
|
-
* build it from user input. Prefer the typed `check*` helpers
|
|
282
|
-
* safe by construction.
|
|
298
|
+
* build it from user input. Prefer the typed `check*` helpers on the column
|
|
299
|
+
* builder, which are safe by construction.
|
|
283
300
|
*/
|
|
284
301
|
check(predicate: string, constraintName?: string): this;
|
|
285
302
|
/** Drop named CHECK constraints (Lucid/Knex `dropChecks`). */
|
|
286
303
|
dropChecks(...constraintNames: string[]): this;
|
|
304
|
+
/** Composite `PRIMARY KEY (…)` table constraint (Lucid/Knex `primary([...])`). */
|
|
305
|
+
primary(columns: readonly string[], constraintName?: string): this;
|
|
287
306
|
/**
|
|
288
|
-
*
|
|
289
|
-
* existing column modifier). With a column list, declare a composite
|
|
290
|
-
* `PRIMARY KEY (…)` table constraint (Lucid/Knex `primary([...])`).
|
|
291
|
-
*/
|
|
292
|
-
primary(columns?: readonly string[], constraintName?: string): this;
|
|
293
|
-
/**
|
|
294
|
-
* With no argument, mark the current column `UNIQUE` (the existing column
|
|
295
|
-
* modifier). With a column list, declare a composite `UNIQUE (…)` table
|
|
296
|
-
* constraint (Lucid/Knex `unique([...])`).
|
|
307
|
+
* Composite `UNIQUE (…)` table constraint (Lucid/Knex `unique([...])`).
|
|
297
308
|
*
|
|
298
309
|
* Note this is a real constraint, unlike {@link uniqueIndex}, which creates
|
|
299
310
|
* a separate `CREATE UNIQUE INDEX`.
|
|
300
311
|
*/
|
|
301
|
-
unique(columns
|
|
312
|
+
unique(columns: readonly string[], constraintName?: string): this;
|
|
302
313
|
/**
|
|
303
314
|
* Declare a composite foreign key (Lucid/Knex
|
|
304
315
|
* `foreign([...]).references([...]).inTable(…)`). Returns a small chainable
|
|
@@ -318,24 +329,21 @@ export declare class TableBuilder {
|
|
|
318
329
|
engine(name: string): this;
|
|
319
330
|
/** MySQL default charset (Lucid/Knex `charset`). Ignored on pg/sqlite. */
|
|
320
331
|
charset(name: string): this;
|
|
321
|
-
/** MySQL default collation for the table
|
|
322
|
-
|
|
323
|
-
/** Table comment
|
|
324
|
-
|
|
332
|
+
/** MySQL default collation for the table (Lucid/Knex `collate`). The column form is `table.<type>(…).collate()`. */
|
|
333
|
+
collate(name: string): this;
|
|
334
|
+
/** Table comment (Lucid/Knex `comment`). The column form is `table.<type>(…).comment()`. */
|
|
335
|
+
comment(text: string): this;
|
|
325
336
|
index(columns: string | string[], name?: string): this;
|
|
326
337
|
uniqueIndex(columns: string | string[], name?: string): this;
|
|
327
338
|
/**
|
|
328
339
|
* Apply the pending column definition as a type change instead of an
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* Nullability moves only if `.nullable()` / `.notNullable()` was called
|
|
332
|
-
* before this — a bare `t.string('x').alter()` changes the type and leaves
|
|
333
|
-
* the NOT NULL constraint exactly as it is.
|
|
334
|
-
*
|
|
335
|
-
* SQLite cannot alter a column in place; the Rust compiler rejects it with
|
|
336
|
-
* `E_UNSUPPORTED` rather than emitting a table rebuild behind your back.
|
|
340
|
+
* @internal Backs `ColumnBuilder.alter()`.
|
|
337
341
|
*/
|
|
338
|
-
|
|
342
|
+
alterPendingColumn(): void;
|
|
343
|
+
/** @internal Backs `ColumnBuilder.nullable()` / `.notNullable()`. */
|
|
344
|
+
markNullabilityTouched(): void;
|
|
345
|
+
/** @internal Backs the `ColumnBuilder.check*()` helpers, for a named column. */
|
|
346
|
+
addColumnCheck(column: string, build: (column: string) => CheckExpression, constraintName?: string): void;
|
|
339
347
|
/** Drop a column (Lucid/Knex `dropColumn`). */
|
|
340
348
|
dropColumn(name: string): this;
|
|
341
349
|
/** Drop several columns in call order (Lucid/Knex `dropColumns`). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableBuilder.d.ts","sourceRoot":"","sources":["../../src/schema/TableBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,UAAU,CAAC;AACjE,OAAO,EACN,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"TableBuilder.d.ts","sourceRoot":"","sources":["../../src/schema/TableBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,UAAU,CAAC;AACjE,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,gBAAgB,EAErB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAGtB,KAAK,WAAW,EAEhB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,qBAAa,iBAAiB;;gBAGjB,UAAU,EAAE,mBAAmB;IAI3C,gDAAgD;IAChD,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI;IAMrD;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK5B,QAAQ,CAAC,MAAM,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