@rudderjs/database 1.1.0 → 1.2.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.
Files changed (126) hide show
  1. package/README.md +70 -0
  2. package/dist/db.d.ts +21 -3
  3. package/dist/db.d.ts.map +1 -1
  4. package/dist/db.js +27 -5
  5. package/dist/db.js.map +1 -1
  6. package/dist/index.d.ts +14 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +23 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/native/adapter.d.ts +202 -0
  11. package/dist/native/adapter.d.ts.map +1 -0
  12. package/dist/native/adapter.js +440 -0
  13. package/dist/native/adapter.js.map +1 -0
  14. package/dist/native/compiler.d.ts +371 -0
  15. package/dist/native/compiler.d.ts.map +1 -0
  16. package/dist/native/compiler.js +978 -0
  17. package/dist/native/compiler.js.map +1 -0
  18. package/dist/native/dialect-mysql.d.ts +26 -0
  19. package/dist/native/dialect-mysql.d.ts.map +1 -0
  20. package/dist/native/dialect-mysql.js +188 -0
  21. package/dist/native/dialect-mysql.js.map +1 -0
  22. package/dist/native/dialect-pg.d.ts +26 -0
  23. package/dist/native/dialect-pg.d.ts.map +1 -0
  24. package/dist/native/dialect-pg.js +192 -0
  25. package/dist/native/dialect-pg.js.map +1 -0
  26. package/dist/native/dialect.d.ts +255 -0
  27. package/dist/native/dialect.d.ts.map +1 -0
  28. package/dist/native/dialect.js +237 -0
  29. package/dist/native/dialect.js.map +1 -0
  30. package/dist/native/driver.d.ts +37 -0
  31. package/dist/native/driver.d.ts.map +1 -0
  32. package/dist/native/driver.js +19 -0
  33. package/dist/native/driver.js.map +1 -0
  34. package/dist/native/drivers/better-sqlite3.d.ts +56 -0
  35. package/dist/native/drivers/better-sqlite3.d.ts.map +1 -0
  36. package/dist/native/drivers/better-sqlite3.js +171 -0
  37. package/dist/native/drivers/better-sqlite3.js.map +1 -0
  38. package/dist/native/drivers/mysql.d.ts +30 -0
  39. package/dist/native/drivers/mysql.d.ts.map +1 -0
  40. package/dist/native/drivers/mysql.js +176 -0
  41. package/dist/native/drivers/mysql.js.map +1 -0
  42. package/dist/native/drivers/postgres.d.ts +57 -0
  43. package/dist/native/drivers/postgres.d.ts.map +1 -0
  44. package/dist/native/drivers/postgres.js +155 -0
  45. package/dist/native/drivers/postgres.js.map +1 -0
  46. package/dist/native/errors.d.ts +43 -0
  47. package/dist/native/errors.d.ts.map +1 -0
  48. package/dist/native/errors.js +64 -0
  49. package/dist/native/errors.js.map +1 -0
  50. package/dist/native/index.d.ts +27 -0
  51. package/dist/native/index.d.ts.map +1 -0
  52. package/dist/native/index.js +55 -0
  53. package/dist/native/index.js.map +1 -0
  54. package/dist/native/isolation.d.ts +14 -0
  55. package/dist/native/isolation.d.ts.map +1 -0
  56. package/dist/native/isolation.js +37 -0
  57. package/dist/native/isolation.js.map +1 -0
  58. package/dist/native/query-builder.d.ts +303 -0
  59. package/dist/native/query-builder.d.ts.map +1 -0
  60. package/dist/native/query-builder.js +984 -0
  61. package/dist/native/query-builder.js.map +1 -0
  62. package/dist/native/replica-picker.d.ts +22 -0
  63. package/dist/native/replica-picker.d.ts.map +1 -0
  64. package/dist/native/replica-picker.js +65 -0
  65. package/dist/native/replica-picker.js.map +1 -0
  66. package/dist/native/schema/alter-blueprint.d.ts +37 -0
  67. package/dist/native/schema/alter-blueprint.d.ts.map +1 -0
  68. package/dist/native/schema/alter-blueprint.js +56 -0
  69. package/dist/native/schema/alter-blueprint.js.map +1 -0
  70. package/dist/native/schema/blueprint.d.ts +151 -0
  71. package/dist/native/schema/blueprint.d.ts.map +1 -0
  72. package/dist/native/schema/blueprint.js +286 -0
  73. package/dist/native/schema/blueprint.js.map +1 -0
  74. package/dist/native/schema/column.d.ts +168 -0
  75. package/dist/native/schema/column.d.ts.map +1 -0
  76. package/dist/native/schema/column.js +190 -0
  77. package/dist/native/schema/column.js.map +1 -0
  78. package/dist/native/schema/ddl-compiler.d.ts +34 -0
  79. package/dist/native/schema/ddl-compiler.d.ts.map +1 -0
  80. package/dist/native/schema/ddl-compiler.js +352 -0
  81. package/dist/native/schema/ddl-compiler.js.map +1 -0
  82. package/dist/native/schema/inspect.d.ts +67 -0
  83. package/dist/native/schema/inspect.d.ts.map +1 -0
  84. package/dist/native/schema/inspect.js +312 -0
  85. package/dist/native/schema/inspect.js.map +1 -0
  86. package/dist/native/schema/introspect.d.ts +34 -0
  87. package/dist/native/schema/introspect.d.ts.map +1 -0
  88. package/dist/native/schema/introspect.js +101 -0
  89. package/dist/native/schema/introspect.js.map +1 -0
  90. package/dist/native/schema/migration.d.ts +8 -0
  91. package/dist/native/schema/migration.d.ts.map +1 -0
  92. package/dist/native/schema/migration.js +19 -0
  93. package/dist/native/schema/migration.js.map +1 -0
  94. package/dist/native/schema/migrator.d.ts +144 -0
  95. package/dist/native/schema/migrator.d.ts.map +1 -0
  96. package/dist/native/schema/migrator.js +239 -0
  97. package/dist/native/schema/migrator.js.map +1 -0
  98. package/dist/native/schema/rebuild.d.ts +11 -0
  99. package/dist/native/schema/rebuild.d.ts.map +1 -0
  100. package/dist/native/schema/rebuild.js +92 -0
  101. package/dist/native/schema/rebuild.js.map +1 -0
  102. package/dist/native/schema/schema-builder.d.ts +46 -0
  103. package/dist/native/schema/schema-builder.d.ts.map +1 -0
  104. package/dist/native/schema/schema-builder.js +153 -0
  105. package/dist/native/schema/schema-builder.js.map +1 -0
  106. package/dist/native/schema/schema-facade.d.ts +63 -0
  107. package/dist/native/schema/schema-facade.d.ts.map +1 -0
  108. package/dist/native/schema/schema-facade.js +124 -0
  109. package/dist/native/schema/schema-facade.js.map +1 -0
  110. package/dist/native/schema/schema-types.d.ts +27 -0
  111. package/dist/native/schema/schema-types.d.ts.map +1 -0
  112. package/dist/native/schema/schema-types.js +52 -0
  113. package/dist/native/schema/schema-types.js.map +1 -0
  114. package/dist/native/schema/types-generator.d.ts +73 -0
  115. package/dist/native/schema/types-generator.d.ts.map +1 -0
  116. package/dist/native/schema/types-generator.js +181 -0
  117. package/dist/native/schema/types-generator.js.map +1 -0
  118. package/dist/registry-bridge.d.ts +24 -4
  119. package/dist/registry-bridge.d.ts.map +1 -1
  120. package/dist/registry-bridge.js +20 -0
  121. package/dist/registry-bridge.js.map +1 -1
  122. package/dist/sticky.d.ts +22 -0
  123. package/dist/sticky.d.ts.map +1 -0
  124. package/dist/sticky.js +61 -0
  125. package/dist/sticky.js.map +1 -0
  126. package/package.json +32 -2
@@ -0,0 +1,286 @@
1
+ // ─── Blueprint (Laravel-style table definition) ────────────
2
+ //
3
+ // PURE: records the column / index / primary-key *intents* for one table. No
4
+ // SQL is built here — the DDL compiler reads a Blueprint and emits statements
5
+ // per-dialect. This is the object handed to a `Schema.create('users', t => …)`
6
+ // callback.
7
+ //
8
+ // Column/timestamp naming follows the native engine's **camelCase** convention
9
+ // (`createdAt` / `updatedAt` / `deletedAt`) — the same columns the read path's
10
+ // soft-delete scoping already defaults to (`deletedAtColumn = 'deletedAt'`), and
11
+ // consistent with the ORM's camelCase polymorphic columns. This is a deliberate
12
+ // divergence from Laravel's snake_case.
13
+ import { ColumnBuilder, makeColumn, normalizeForeignKeyAction, } from './column.js';
14
+ import { NativeOrmError } from '../errors.js';
15
+ /** Validate that an `enum`/`set` column got a non-empty value list. The values
16
+ * themselves are quoted at compile time, so the only check here is presence. */
17
+ function requireValues(kind, values) {
18
+ if (!Array.isArray(values) || values.length === 0) {
19
+ throw new NativeOrmError('NATIVE_DDL_EMPTY_ENUM', `[RudderJS ORM native] ${kind}() requires a non-empty list of allowed values.`);
20
+ }
21
+ return values;
22
+ }
23
+ /**
24
+ * Fluent builder for a table-level foreign key (`Blueprint.foreign(...)`).
25
+ * Mutates the {@link ForeignKeyDefinition} the Blueprint recorded and returns
26
+ * `this` so the constraint chains Laravel-style:
27
+ * `t.foreign('user_id').references('id').on('users').onDelete('cascade')`.
28
+ */
29
+ export class ForeignKeyBuilder {
30
+ fk;
31
+ constructor(fk) {
32
+ this.fk = fk;
33
+ }
34
+ /** Referenced column(s) on the foreign table (defaults to `id`). */
35
+ references(columns) {
36
+ this.fk.references = Array.isArray(columns) ? columns : [columns];
37
+ return this;
38
+ }
39
+ /** Referenced table. */
40
+ on(table) {
41
+ this.fk.on = table;
42
+ return this;
43
+ }
44
+ onDelete(action) {
45
+ this.fk.onDelete = normalizeForeignKeyAction(action);
46
+ return this;
47
+ }
48
+ onUpdate(action) {
49
+ this.fk.onUpdate = normalizeForeignKeyAction(action);
50
+ return this;
51
+ }
52
+ /** `onDelete('cascade')`. */
53
+ cascadeOnDelete() { return this.onDelete('cascade'); }
54
+ /** `onDelete('restrict')`. */
55
+ restrictOnDelete() { return this.onDelete('restrict'); }
56
+ /** `onDelete('set null')` — pair with nullable column(s). */
57
+ nullOnDelete() { return this.onDelete('set null'); }
58
+ /** `onUpdate('cascade')`. */
59
+ cascadeOnUpdate() { return this.onUpdate('cascade'); }
60
+ /** Override the default `{table}_{col[_col…]}_foreign` constraint name. */
61
+ name(name) {
62
+ this.fk.name = name;
63
+ return this;
64
+ }
65
+ }
66
+ /**
67
+ * Records one table's shape. Mirrors Laravel's `Blueprint`: a column method
68
+ * returns a {@link ColumnBuilder} so modifiers chain; table-level helpers
69
+ * (`primary` / `unique` / `index`) record composite constraints.
70
+ */
71
+ export class Blueprint {
72
+ table;
73
+ columns = [];
74
+ /** Composite (or explicitly-named single) primary key. Single-column PKs set
75
+ * inline via `.primary()` live on the column instead. */
76
+ primaryColumns = null;
77
+ indexes = [];
78
+ /** Table-level foreign keys (`Blueprint.foreign(...)`). Column-level FKs
79
+ * (`constrained()`) live on their {@link ColumnDefinition} instead; the
80
+ * compiler collects both. */
81
+ foreignKeys = [];
82
+ constructor(table) {
83
+ this.table = table;
84
+ }
85
+ add(name, type, extra = {}) {
86
+ const def = makeColumn(name, type, extra);
87
+ this.columns.push(def);
88
+ return new ColumnBuilder(def);
89
+ }
90
+ // ── Auto-incrementing primary key ──
91
+ /** Auto-incrementing integer primary key (`id` by default). */
92
+ id(name = 'id') {
93
+ return this.increments(name);
94
+ }
95
+ /** Auto-incrementing integer primary key under an explicit name. */
96
+ increments(name) {
97
+ return this.add(name, 'increments', { autoIncrement: true, primary: true });
98
+ }
99
+ /** Alias of {@link increments} — bigint on pg/mysql, INTEGER on SQLite. */
100
+ bigIncrements(name) {
101
+ return this.add(name, 'increments', { autoIncrement: true, primary: true });
102
+ }
103
+ // ── Integers ──
104
+ integer(name) {
105
+ return this.add(name, 'integer');
106
+ }
107
+ bigInteger(name) {
108
+ return this.add(name, 'bigInteger');
109
+ }
110
+ /** Small integer — `smallint` (pg/mysql), `INTEGER` (sqlite). */
111
+ smallInteger(name) {
112
+ return this.add(name, 'smallInteger');
113
+ }
114
+ /** Tiny integer — `tinyint` (mysql), `smallint` (pg), `INTEGER` (sqlite). */
115
+ tinyInteger(name) {
116
+ return this.add(name, 'tinyInteger');
117
+ }
118
+ /** Medium integer — `mediumint` (mysql), `integer` (pg), `INTEGER` (sqlite). */
119
+ mediumInteger(name) {
120
+ return this.add(name, 'mediumInteger');
121
+ }
122
+ /** Unsigned big integer intended as a foreign key. Chain `.constrained()` (or
123
+ * `.references(...).on(...)`) to attach the FK constraint. */
124
+ foreignId(name) {
125
+ return this.add(name, 'bigInteger', { unsigned: true });
126
+ }
127
+ /**
128
+ * Laravel `foreignIdFor`: an unsigned big-integer FK column whose name is
129
+ * derived from a related table (`'users'` → `userId`) unless `column` is given.
130
+ * Chain `.constrained()` to attach the constraint. Naming follows the engine's
131
+ * camelCase convention (singularize + `Id`), a divergence from Laravel's
132
+ * `{snake}_id`.
133
+ */
134
+ foreignIdFor(related, column) {
135
+ const singular = related.endsWith('s') ? related.slice(0, -1) : related;
136
+ return this.foreignId(column ?? `${singular}Id`);
137
+ }
138
+ // ── Strings / text ──
139
+ string(name, length = 255) {
140
+ return this.add(name, 'string', { length });
141
+ }
142
+ /** Fixed-length `char(length)` (pg/mysql); `TEXT` on sqlite. */
143
+ char(name, length = 255) {
144
+ return this.add(name, 'char', { length });
145
+ }
146
+ text(name) {
147
+ return this.add(name, 'text');
148
+ }
149
+ /** `mediumtext` (mysql); `text` (pg/sqlite). */
150
+ mediumText(name) {
151
+ return this.add(name, 'mediumText');
152
+ }
153
+ /** `longtext` (mysql); `text` (pg/sqlite). */
154
+ longText(name) {
155
+ return this.add(name, 'longText');
156
+ }
157
+ uuid(name = 'uuid') {
158
+ return this.add(name, 'uuid');
159
+ }
160
+ /** 26-char ULID — `char(26)` (pg/mysql), `TEXT` (sqlite). */
161
+ ulid(name = 'ulid') {
162
+ return this.add(name, 'ulid');
163
+ }
164
+ /** A `uuid` column intended as a foreign key — chain `.constrained()`. */
165
+ foreignUuid(name) {
166
+ return this.add(name, 'uuid');
167
+ }
168
+ /** A `ulid` column intended as a foreign key — chain `.constrained()`. */
169
+ foreignUlid(name) {
170
+ return this.add(name, 'ulid');
171
+ }
172
+ json(name) {
173
+ return this.add(name, 'json');
174
+ }
175
+ /** `jsonb` (pg) — binary JSON; falls back to `json` (mysql) / `TEXT` (sqlite). */
176
+ jsonb(name) {
177
+ return this.add(name, 'jsonb');
178
+ }
179
+ /**
180
+ * Enumerated string column. `enum(...)` on MySQL; `varchar(255)` + a
181
+ * `CHECK (… IN (…))` constraint on pg/sqlite. Values are migration-author
182
+ * supplied — rendered as quoted literals, never bound. Throws on an empty list.
183
+ */
184
+ enum(name, values) {
185
+ return this.add(name, 'enum', { enumValues: requireValues('enum', values) });
186
+ }
187
+ /** MySQL `set(...)` — multiple allowed values stored as a comma list. Throws a
188
+ * clear NotImplemented on pg/sqlite (no native SET type). */
189
+ set(name, values) {
190
+ return this.add(name, 'set', { enumValues: requireValues('set', values) });
191
+ }
192
+ // ── Numbers ──
193
+ decimal(name, precision = 8, scale = 2) {
194
+ return this.add(name, 'decimal', { precision, scale });
195
+ }
196
+ float(name) {
197
+ return this.add(name, 'float');
198
+ }
199
+ /** Double-precision float — `double precision` (pg), `double` (mysql), `REAL` (sqlite). */
200
+ double(name) {
201
+ return this.add(name, 'double');
202
+ }
203
+ // ── Booleans / dates / binary ──
204
+ boolean(name) {
205
+ return this.add(name, 'boolean');
206
+ }
207
+ /** Calendar date (no time) — `date` (pg/mysql), `TEXT` (sqlite). */
208
+ date(name) {
209
+ return this.add(name, 'date');
210
+ }
211
+ /** Time of day (no date). Optional fractional-seconds `precision` → `time(p)`
212
+ * on pg/mysql; `TEXT` on sqlite. */
213
+ time(name, precision) {
214
+ return this.add(name, 'time', precision === undefined ? {} : { precision });
215
+ }
216
+ dateTime(name) {
217
+ return this.add(name, 'dateTime');
218
+ }
219
+ timestamp(name) {
220
+ return this.add(name, 'timestamp');
221
+ }
222
+ binary(name) {
223
+ return this.add(name, 'binary');
224
+ }
225
+ // ── Convenience clusters ──
226
+ /** `createdAt` + `updatedAt`, nullable (Laravel parity), camelCase per engine
227
+ * convention. */
228
+ timestamps() {
229
+ this.timestamp('createdAt').nullable();
230
+ this.timestamp('updatedAt').nullable();
231
+ }
232
+ /** `deletedAt` nullable — the column the soft-delete scope filters on. */
233
+ softDeletes(name = 'deletedAt') {
234
+ return this.timestamp(name).nullable();
235
+ }
236
+ /**
237
+ * Polymorphic relation columns (Laravel `morphs`): a `{name}Id` (unsigned big
238
+ * integer) + `{name}Type` (string) pair plus a composite index over both. The
239
+ * columns use the engine's **camelCase** morph convention (`commentableId` /
240
+ * `commentableType`) — the same columns `morphTo` / `morphMany` read/write —
241
+ * not Laravel's snake_case. The index covers `[{name}Type, {name}Id]` (type
242
+ * first, matching Laravel), defaulting to `{table}_{name}Type_{name}Id_index`;
243
+ * pass `indexName` to override (pair with the same name in {@link dropMorphs}).
244
+ */
245
+ morphs(name, indexName) {
246
+ this.bigInteger(`${name}Id`).unsigned();
247
+ this.string(`${name}Type`);
248
+ this.index([`${name}Type`, `${name}Id`], indexName);
249
+ }
250
+ /** Nullable variant of {@link morphs} — both columns allow NULL (the relation
251
+ * is optional). Same `[{name}Type, {name}Id]` composite index. */
252
+ nullableMorphs(name, indexName) {
253
+ this.bigInteger(`${name}Id`).unsigned().nullable();
254
+ this.string(`${name}Type`).nullable();
255
+ this.index([`${name}Type`, `${name}Id`], indexName);
256
+ }
257
+ // ── Table-level constraints ──
258
+ /** Composite (or named single) primary key. */
259
+ primary(columns) {
260
+ this.primaryColumns = Array.isArray(columns) ? columns : [columns];
261
+ }
262
+ /** Composite (or single) unique index. */
263
+ unique(columns, name) {
264
+ this.indexes.push({ columns: Array.isArray(columns) ? columns : [columns], unique: true, ...(name !== undefined && { name }) });
265
+ }
266
+ /** Composite (or single) non-unique index. */
267
+ index(columns, name) {
268
+ this.indexes.push({ columns: Array.isArray(columns) ? columns : [columns], unique: false, ...(name !== undefined && { name }) });
269
+ }
270
+ /**
271
+ * Composite / explicit foreign key:
272
+ * `t.foreign('user_id').references('id').on('users').onDelete('cascade')`.
273
+ * Returns a {@link ForeignKeyBuilder}; the referenced column defaults to `id`.
274
+ * For the single-column shorthand, prefer `t.foreignId('user_id').constrained()`.
275
+ */
276
+ foreign(columns) {
277
+ const fk = {
278
+ columns: Array.isArray(columns) ? columns : [columns],
279
+ references: ['id'],
280
+ on: '',
281
+ };
282
+ this.foreignKeys.push(fk);
283
+ return new ForeignKeyBuilder(fk);
284
+ }
285
+ }
286
+ //# sourceMappingURL=blueprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blueprint.js","sourceRoot":"","sources":["../../../src/native/schema/blueprint.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,YAAY;AACZ,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,wCAAwC;AAExC,OAAO,EACL,aAAa,EAAE,UAAU,EACzB,yBAAyB,GAE1B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C;iFACiF;AACjF,SAAS,aAAa,CAAC,IAAoB,EAAE,MAAgB;IA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AAC,EAAE,CAAC,CAAA;IAClC,CAAC;CACF"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The referential actions a foreign key may take on `ON DELETE` / `ON UPDATE`.
3
+ * Stored in the canonical SQL-keyword-lowercase form; the compiler upper-cases
4
+ * it (`'set null'` → `SET NULL`). camelCase aliases (`setNull` / `noAction`) are
5
+ * accepted at the call site and normalized here.
6
+ */
7
+ export type ForeignKeyAction = 'cascade' | 'restrict' | 'set null' | 'no action';
8
+ /** What callers may pass to `onDelete` / `onUpdate` — the canonical forms plus
9
+ * the camelCase aliases Laravel users reach for. */
10
+ export type ForeignKeyActionInput = ForeignKeyAction | 'setNull' | 'noAction';
11
+ /** A recorded foreign-key intent. Built by `ColumnBuilder.constrained()` /
12
+ * `.references().on()` (column-level) or `Blueprint.foreign()` (table-level);
13
+ * rendered as a `FOREIGN KEY` table constraint by the DDL compiler. */
14
+ export interface ForeignKeyDefinition {
15
+ /** Local column(s) the constraint covers. */
16
+ columns: string[];
17
+ /** Referenced column(s) on the foreign table. Defaults to `['id']`. */
18
+ references: string[];
19
+ /** Referenced table. Required at compile time — `constrained()` infers it,
20
+ * `.on(...)` sets it explicitly. Empty until one of those runs. */
21
+ on: string;
22
+ onDelete?: ForeignKeyAction;
23
+ onUpdate?: ForeignKeyAction;
24
+ /** Explicit constraint name; defaults to `{table}_{col[_col…]}_foreign`. */
25
+ name?: string;
26
+ }
27
+ /**
28
+ * Validate a referential action against the allowlist and normalize it to its
29
+ * canonical form. Accepts the SQL forms (`'set null'`) and the camelCase aliases
30
+ * (`'setNull'`). Throws {@link NativeOrmError} on anything else so arbitrary text
31
+ * never reaches the `ON DELETE` / `ON UPDATE` clause (DDL can't bind values).
32
+ */
33
+ export declare function normalizeForeignKeyAction(input: string): ForeignKeyAction;
34
+ /** Laravel-style table inference for `constrained()`: strip a trailing `_id` /
35
+ * `Id` from the column name and naively pluralize (`user_id` → `users`,
36
+ * `authorId` → `authors`). */
37
+ export declare function inferForeignTable(column: string): string;
38
+ /**
39
+ * The portable column types v1 supports — the common 80% (parent plan Part 2).
40
+ * Each dialect maps these to its own SQL type; SQLite's mapping lives in
41
+ * `SqliteDialect.columnTypeSql`. Exotic types (geometry, set, …) are deferred.
42
+ */
43
+ export type ColumnType = 'increments' | 'integer' | 'bigInteger' | 'tinyInteger' | 'smallInteger' | 'mediumInteger' | 'string' | 'char' | 'text' | 'mediumText' | 'longText' | 'boolean' | 'date' | 'time' | 'dateTime' | 'timestamp' | 'json' | 'jsonb' | 'uuid' | 'ulid' | 'decimal' | 'float' | 'double' | 'binary' | 'enum' | 'set';
44
+ /**
45
+ * The recorded shape of one column. Built by {@link ColumnBuilder}; consumed by
46
+ * the DDL compiler + the dialect's type mapper. Modifier flags default to the
47
+ * unset state so a bare `t.integer('age')` carries no surprises.
48
+ */
49
+ export interface ColumnDefinition {
50
+ name: string;
51
+ type: ColumnType;
52
+ /** `string(name, length)` — kept for pg/mysql `varchar(N)`; SQLite ignores it. */
53
+ length?: number;
54
+ /** `decimal(name, precision, scale)`; also the fractional-seconds precision
55
+ * for `time(name, precision)`. */
56
+ precision?: number;
57
+ scale?: number;
58
+ /** Allowed values for `enum(name, [...])` / `set(name, [...])`. Rendered as a
59
+ * quoted literal list (mysql `enum(...)`/`set(...)`) or a `CHECK (... IN ...)`
60
+ * constraint (pg/sqlite `enum`). Migration-author supplied — quoted, never bound. */
61
+ enumValues?: string[];
62
+ nullable: boolean;
63
+ /** Whether a DEFAULT was set (distinguishes `default(null)` from "no default"). */
64
+ hasDefault: boolean;
65
+ /** The default literal when {@link hasDefault}. DDL defaults are rendered as
66
+ * literals (most databases reject bound parameters in DDL), so the value is
67
+ * escaped, not parameterized — safe because migration authors, not end users,
68
+ * write these. */
69
+ default?: unknown;
70
+ /** `useCurrent()` — `DEFAULT CURRENT_TIMESTAMP`. Takes precedence over `default`. */
71
+ useCurrent: boolean;
72
+ /** `useCurrentOnUpdate()` — `ON UPDATE CURRENT_TIMESTAMP`. MySQL-only (Laravel
73
+ * grammar parity); silently ignored on pg/sqlite, which have no inline form. */
74
+ useCurrentOnUpdate: boolean;
75
+ /** `comment(text)` — a column comment. Rendered inline (`COMMENT '…'`) on MySQL,
76
+ * as a separate `COMMENT ON COLUMN` statement on pg, and ignored on sqlite. */
77
+ comment?: string;
78
+ /** `after(column)` — position an added column after another (MySQL ALTER only). */
79
+ after?: string;
80
+ /** `first()` — position an added column first (MySQL ALTER only). */
81
+ first?: boolean;
82
+ /** Single-column inline `PRIMARY KEY`. Composite PKs go through `Blueprint.primary`. */
83
+ primary: boolean;
84
+ /** Emit a `CREATE UNIQUE INDEX` for this column (Laravel-style separate index). */
85
+ unique: boolean;
86
+ /** Emit a `CREATE INDEX` for this column. */
87
+ index: boolean;
88
+ /** `unsigned()` — recorded for pg/mysql; a no-op on SQLite. */
89
+ unsigned: boolean;
90
+ /** True for `increments()` — the dialect emits the full auto-increment PK
91
+ * spec, so the compiler skips the other inline modifiers for this column. */
92
+ autoIncrement: boolean;
93
+ /** `change()` — in a `Schema.table` alter, modify the existing column rather
94
+ * than add it. On SQLite this needs the table-rebuild dance (7.4b); the alter
95
+ * compiler throws a clear "not yet" until then. */
96
+ change: boolean;
97
+ /** Column-level foreign key (`constrained()` / `.references().on()`). Recorded
98
+ * here as an intent; the compiler emits it as a table-level `FOREIGN KEY`
99
+ * constraint, not an inline column modifier. */
100
+ foreignKey?: ForeignKeyDefinition;
101
+ }
102
+ /**
103
+ * Fluent wrapper over a {@link ColumnDefinition}. Returned by every
104
+ * `Blueprint` column method so modifiers chain Laravel-style. Mutates its
105
+ * backing definition and returns `this`.
106
+ */
107
+ export declare class ColumnBuilder {
108
+ readonly def: ColumnDefinition;
109
+ constructor(def: ColumnDefinition);
110
+ /** Allow NULLs (columns are `NOT NULL` by default, matching Laravel). */
111
+ nullable(value?: boolean): this;
112
+ /** Set a column default. Pass `null` for a literal `DEFAULT NULL`. */
113
+ default(value: unknown): this;
114
+ /** Default this timestamp/dateTime column to `CURRENT_TIMESTAMP`. */
115
+ useCurrent(): this;
116
+ /** Refresh this timestamp on UPDATE (`ON UPDATE CURRENT_TIMESTAMP`). MySQL-only;
117
+ * a no-op on pg/sqlite (recorded for portability, ignored by their grammar). */
118
+ useCurrentOnUpdate(): this;
119
+ /** Attach a column comment. Inline on MySQL, a separate `COMMENT ON COLUMN`
120
+ * statement on pg, ignored on sqlite (no column comments). */
121
+ comment(text: string): this;
122
+ /** Position this (added) column after another. MySQL ALTER only — ignored
123
+ * elsewhere, matching Laravel. */
124
+ after(column: string): this;
125
+ /** Position this (added) column first. MySQL ALTER only — ignored elsewhere. */
126
+ first(): this;
127
+ /** Mark as the table's (single-column) primary key. */
128
+ primary(): this;
129
+ /** Add a unique index over this column. */
130
+ unique(): this;
131
+ /** Add a (non-unique) index over this column. */
132
+ index(): this;
133
+ /** Mark unsigned (pg/mysql); a no-op on SQLite, recorded for portability. */
134
+ unsigned(): this;
135
+ /** In a `Schema.table` alter, modify this existing column instead of adding it.
136
+ * (SQLite implements this via a table rebuild — lands in 7.4b.) */
137
+ change(): this;
138
+ /**
139
+ * Laravel `constrained()`: add a foreign key on this column. With no argument
140
+ * the referenced table is inferred from the column name (`user_id` → `users`)
141
+ * and the referenced column defaults to `id`. Pass an explicit table (and
142
+ * optionally column) to override the inference.
143
+ */
144
+ constrained(table?: string, column?: string): this;
145
+ /** Set the referenced column(s). Pair with `.on(table)` for the full FK:
146
+ * `t.foreignId('user_id').references('id').on('users')`. */
147
+ references(columns: string | string[]): this;
148
+ /** Set the referenced table for the FK started by `.references(...)`. */
149
+ on(table: string): this;
150
+ /** `ON DELETE` action (validated against the allowlist). */
151
+ onDelete(action: ForeignKeyActionInput): this;
152
+ /** `ON UPDATE` action (validated against the allowlist). */
153
+ onUpdate(action: ForeignKeyActionInput): this;
154
+ /** `onDelete('cascade')`. */
155
+ cascadeOnDelete(): this;
156
+ /** `onDelete('restrict')`. */
157
+ restrictOnDelete(): this;
158
+ /** `onDelete('set null')` — pair with a `.nullable()` column. */
159
+ nullOnDelete(): this;
160
+ /** `onUpdate('cascade')`. */
161
+ cascadeOnUpdate(): this;
162
+ /** Lazily create the FK intent on first FK-method call, then return it for
163
+ * incremental building (`.references().on().onDelete()`). */
164
+ private foreignKey;
165
+ }
166
+ /** Build a {@link ColumnDefinition} with modifier defaults filled in. */
167
+ export declare function makeColumn(name: string, type: ColumnType, extra?: Partial<ColumnDefinition>): ColumnDefinition;
168
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../../src/native/schema/column.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAA;AAEhF;qDACqD;AACrD,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,SAAS,GAAG,UAAU,CAAA;AAE7E;;wEAEwE;AACxE,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,OAAO,EAAK,MAAM,EAAE,CAAA;IACpB,uEAAuE;IACvE,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB;wEACoE;IACpE,EAAE,EAAU,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAG,gBAAgB,CAAA;IAC5B,QAAQ,CAAC,EAAG,gBAAgB,CAAA;IAC5B,4EAA4E;IAC5E,IAAI,CAAC,EAAO,MAAM,CAAA;CACnB;AAWD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAUzE;AAED;;+BAE+B;AAC/B,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKxD;AAMD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAClB,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,aAAa,GACb,cAAc,GACd,eAAe,GACf,QAAQ,GACR,MAAM,GACN,MAAM,GACN,YAAY,GACZ,UAAU,GACV,SAAS,G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,EACZ,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACpC,gBAAgB,CAgBlB"}
@@ -0,0 +1,190 @@
1
+ // ─── Column definition + chainable builder ─────────────────
2
+ //
3
+ // PURE: no driver, no `node:`, no I/O. A `ColumnBuilder` records the *intent*
4
+ // of one column (type + modifiers) as a plain {@link ColumnDefinition}; the DDL
5
+ // compiler turns those intents into SQL per-dialect. This mirrors the read
6
+ // path's split — the query builder records state, the compiler emits SQL.
7
+ //
8
+ // Laravel's `Blueprint` column methods return a fluent column object so
9
+ // modifiers chain (`t.string('email').nullable().unique()`); `ColumnBuilder` is
10
+ // that object. It mutates its backing definition in place and returns `this`.
11
+ import { NativeOrmError } from '../errors.js';
12
+ const FK_ACTIONS = {
13
+ 'cascade': 'cascade',
14
+ 'restrict': 'restrict',
15
+ 'set null': 'set null',
16
+ 'setnull': 'set null',
17
+ 'no action': 'no action',
18
+ 'noaction': 'no action',
19
+ };
20
+ /**
21
+ * Validate a referential action against the allowlist and normalize it to its
22
+ * canonical form. Accepts the SQL forms (`'set null'`) and the camelCase aliases
23
+ * (`'setNull'`). Throws {@link NativeOrmError} on anything else so arbitrary text
24
+ * never reaches the `ON DELETE` / `ON UPDATE` clause (DDL can't bind values).
25
+ */
26
+ export function normalizeForeignKeyAction(input) {
27
+ const action = FK_ACTIONS[String(input).trim().toLowerCase()];
28
+ if (!action) {
29
+ throw new NativeOrmError('NATIVE_DDL_BAD_FK_ACTION', `[RudderJS ORM native] Invalid foreign-key action ${JSON.stringify(input)}. ` +
30
+ `Use one of: cascade, restrict, set null (setNull), no action (noAction).`);
31
+ }
32
+ return action;
33
+ }
34
+ /** Laravel-style table inference for `constrained()`: strip a trailing `_id` /
35
+ * `Id` from the column name and naively pluralize (`user_id` → `users`,
36
+ * `authorId` → `authors`). */
37
+ export function inferForeignTable(column) {
38
+ let base = column;
39
+ if (base.endsWith('_id'))
40
+ base = base.slice(0, -3);
41
+ else if (base.endsWith('Id'))
42
+ base = base.slice(0, -2);
43
+ return base.endsWith('s') ? base : `${base}s`;
44
+ }
45
+ function toColumns(columns) {
46
+ return Array.isArray(columns) ? columns : [columns];
47
+ }
48
+ /**
49
+ * Fluent wrapper over a {@link ColumnDefinition}. Returned by every
50
+ * `Blueprint` column method so modifiers chain Laravel-style. Mutates its
51
+ * backing definition and returns `this`.
52
+ */
53
+ export class ColumnBuilder {
54
+ def;
55
+ constructor(def) {
56
+ this.def = def;
57
+ }
58
+ /** Allow NULLs (columns are `NOT NULL` by default, matching Laravel). */
59
+ nullable(value = true) {
60
+ this.def.nullable = value;
61
+ return this;
62
+ }
63
+ /** Set a column default. Pass `null` for a literal `DEFAULT NULL`. */
64
+ default(value) {
65
+ this.def.hasDefault = true;
66
+ this.def.default = value;
67
+ return this;
68
+ }
69
+ /** Default this timestamp/dateTime column to `CURRENT_TIMESTAMP`. */
70
+ useCurrent() {
71
+ this.def.useCurrent = true;
72
+ return this;
73
+ }
74
+ /** Refresh this timestamp on UPDATE (`ON UPDATE CURRENT_TIMESTAMP`). MySQL-only;
75
+ * a no-op on pg/sqlite (recorded for portability, ignored by their grammar). */
76
+ useCurrentOnUpdate() {
77
+ this.def.useCurrentOnUpdate = true;
78
+ return this;
79
+ }
80
+ /** Attach a column comment. Inline on MySQL, a separate `COMMENT ON COLUMN`
81
+ * statement on pg, ignored on sqlite (no column comments). */
82
+ comment(text) {
83
+ this.def.comment = text;
84
+ return this;
85
+ }
86
+ /** Position this (added) column after another. MySQL ALTER only — ignored
87
+ * elsewhere, matching Laravel. */
88
+ after(column) {
89
+ this.def.after = column;
90
+ return this;
91
+ }
92
+ /** Position this (added) column first. MySQL ALTER only — ignored elsewhere. */
93
+ first() {
94
+ this.def.first = true;
95
+ return this;
96
+ }
97
+ /** Mark as the table's (single-column) primary key. */
98
+ primary() {
99
+ this.def.primary = true;
100
+ return this;
101
+ }
102
+ /** Add a unique index over this column. */
103
+ unique() {
104
+ this.def.unique = true;
105
+ return this;
106
+ }
107
+ /** Add a (non-unique) index over this column. */
108
+ index() {
109
+ this.def.index = true;
110
+ return this;
111
+ }
112
+ /** Mark unsigned (pg/mysql); a no-op on SQLite, recorded for portability. */
113
+ unsigned() {
114
+ this.def.unsigned = true;
115
+ return this;
116
+ }
117
+ /** In a `Schema.table` alter, modify this existing column instead of adding it.
118
+ * (SQLite implements this via a table rebuild — lands in 7.4b.) */
119
+ change() {
120
+ this.def.change = true;
121
+ return this;
122
+ }
123
+ // ── Foreign keys (column-level) ──
124
+ /**
125
+ * Laravel `constrained()`: add a foreign key on this column. With no argument
126
+ * the referenced table is inferred from the column name (`user_id` → `users`)
127
+ * and the referenced column defaults to `id`. Pass an explicit table (and
128
+ * optionally column) to override the inference.
129
+ */
130
+ constrained(table, column = 'id') {
131
+ const fk = this.foreignKey();
132
+ fk.on = table ?? inferForeignTable(this.def.name);
133
+ fk.references = [column];
134
+ return this;
135
+ }
136
+ /** Set the referenced column(s). Pair with `.on(table)` for the full FK:
137
+ * `t.foreignId('user_id').references('id').on('users')`. */
138
+ references(columns) {
139
+ this.foreignKey().references = toColumns(columns);
140
+ return this;
141
+ }
142
+ /** Set the referenced table for the FK started by `.references(...)`. */
143
+ on(table) {
144
+ this.foreignKey().on = table;
145
+ return this;
146
+ }
147
+ /** `ON DELETE` action (validated against the allowlist). */
148
+ onDelete(action) {
149
+ this.foreignKey().onDelete = normalizeForeignKeyAction(action);
150
+ return this;
151
+ }
152
+ /** `ON UPDATE` action (validated against the allowlist). */
153
+ onUpdate(action) {
154
+ this.foreignKey().onUpdate = normalizeForeignKeyAction(action);
155
+ return this;
156
+ }
157
+ // ── Referential-action shorthands (Laravel parity) ──
158
+ /** `onDelete('cascade')`. */
159
+ cascadeOnDelete() { return this.onDelete('cascade'); }
160
+ /** `onDelete('restrict')`. */
161
+ restrictOnDelete() { return this.onDelete('restrict'); }
162
+ /** `onDelete('set null')` — pair with a `.nullable()` column. */
163
+ nullOnDelete() { return this.onDelete('set null'); }
164
+ /** `onUpdate('cascade')`. */
165
+ cascadeOnUpdate() { return this.onUpdate('cascade'); }
166
+ /** Lazily create the FK intent on first FK-method call, then return it for
167
+ * incremental building (`.references().on().onDelete()`). */
168
+ foreignKey() {
169
+ return (this.def.foreignKey ??= { columns: [this.def.name], references: ['id'], on: '' });
170
+ }
171
+ }
172
+ /** Build a {@link ColumnDefinition} with modifier defaults filled in. */
173
+ export function makeColumn(name, type, extra = {}) {
174
+ return {
175
+ name,
176
+ type,
177
+ nullable: false,
178
+ hasDefault: false,
179
+ useCurrent: false,
180
+ useCurrentOnUpdate: false,
181
+ primary: false,
182
+ unique: false,
183
+ index: false,
184
+ unsigned: false,
185
+ autoIncrement: false,
186
+ change: false,
187
+ ...extra,
188
+ };
189
+ }
190
+ //# sourceMappingURL=column.js.map