@remix-run/data-table 0.0.0 → 0.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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +549 -2
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +7 -0
  6. package/dist/lib/adapter.d.ts +550 -0
  7. package/dist/lib/adapter.d.ts.map +1 -0
  8. package/dist/lib/adapter.js +1 -0
  9. package/dist/lib/column.d.ts +193 -0
  10. package/dist/lib/column.d.ts.map +1 -0
  11. package/dist/lib/column.js +302 -0
  12. package/dist/lib/database/execution-context.d.ts +10 -0
  13. package/dist/lib/database/execution-context.d.ts.map +1 -0
  14. package/dist/lib/database/execution-context.js +1 -0
  15. package/dist/lib/database/helpers.d.ts +26 -0
  16. package/dist/lib/database/helpers.d.ts.map +1 -0
  17. package/dist/lib/database/helpers.js +116 -0
  18. package/dist/lib/database/query-execution.d.ts +7 -0
  19. package/dist/lib/database/query-execution.d.ts.map +1 -0
  20. package/dist/lib/database/query-execution.js +401 -0
  21. package/dist/lib/database/relations.d.ts +4 -0
  22. package/dist/lib/database/relations.d.ts.map +1 -0
  23. package/dist/lib/database/relations.js +207 -0
  24. package/dist/lib/database/write-lifecycle.d.ts +13 -0
  25. package/dist/lib/database/write-lifecycle.d.ts.map +1 -0
  26. package/dist/lib/database/write-lifecycle.js +279 -0
  27. package/dist/lib/database.d.ts +264 -0
  28. package/dist/lib/database.d.ts.map +1 -0
  29. package/dist/lib/database.js +319 -0
  30. package/dist/lib/errors.d.ts +59 -0
  31. package/dist/lib/errors.d.ts.map +1 -0
  32. package/dist/lib/errors.js +76 -0
  33. package/dist/lib/inflection.d.ts +3 -0
  34. package/dist/lib/inflection.d.ts.map +1 -0
  35. package/dist/lib/inflection.js +56 -0
  36. package/dist/lib/migrations/filename.d.ts +12 -0
  37. package/dist/lib/migrations/filename.d.ts.map +1 -0
  38. package/dist/lib/migrations/filename.js +20 -0
  39. package/dist/lib/migrations/helpers.d.ts +11 -0
  40. package/dist/lib/migrations/helpers.d.ts.map +1 -0
  41. package/dist/lib/migrations/helpers.js +77 -0
  42. package/dist/lib/migrations/journal-store.d.ts +15 -0
  43. package/dist/lib/migrations/journal-store.d.ts.map +1 -0
  44. package/dist/lib/migrations/journal-store.js +83 -0
  45. package/dist/lib/migrations/registry.d.ts +27 -0
  46. package/dist/lib/migrations/registry.d.ts.map +1 -0
  47. package/dist/lib/migrations/registry.js +51 -0
  48. package/dist/lib/migrations/runner.d.ts +20 -0
  49. package/dist/lib/migrations/runner.d.ts.map +1 -0
  50. package/dist/lib/migrations/runner.js +273 -0
  51. package/dist/lib/migrations/schema-api.d.ts +7 -0
  52. package/dist/lib/migrations/schema-api.d.ts.map +1 -0
  53. package/dist/lib/migrations/schema-api.js +326 -0
  54. package/dist/lib/migrations-node.d.ts +17 -0
  55. package/dist/lib/migrations-node.d.ts.map +1 -0
  56. package/dist/lib/migrations-node.js +65 -0
  57. package/dist/lib/migrations.d.ts +292 -0
  58. package/dist/lib/migrations.d.ts.map +1 -0
  59. package/dist/lib/migrations.js +38 -0
  60. package/dist/lib/operators.d.ts +154 -0
  61. package/dist/lib/operators.d.ts.map +1 -0
  62. package/dist/lib/operators.js +218 -0
  63. package/dist/lib/query.d.ts +159 -0
  64. package/dist/lib/query.d.ts.map +1 -0
  65. package/dist/lib/query.js +401 -0
  66. package/dist/lib/references.d.ts +41 -0
  67. package/dist/lib/references.d.ts.map +1 -0
  68. package/dist/lib/references.js +33 -0
  69. package/dist/lib/sql-helpers.d.ts +50 -0
  70. package/dist/lib/sql-helpers.d.ts.map +1 -0
  71. package/dist/lib/sql-helpers.js +111 -0
  72. package/dist/lib/sql.d.ts +45 -0
  73. package/dist/lib/sql.d.ts.map +1 -0
  74. package/dist/lib/sql.js +65 -0
  75. package/dist/lib/table.d.ts +569 -0
  76. package/dist/lib/table.d.ts.map +1 -0
  77. package/dist/lib/table.js +519 -0
  78. package/dist/lib/types.d.ts +4 -0
  79. package/dist/lib/types.d.ts.map +1 -0
  80. package/dist/lib/types.js +1 -0
  81. package/dist/migrations/node.d.ts +2 -0
  82. package/dist/migrations/node.d.ts.map +1 -0
  83. package/dist/migrations/node.js +1 -0
  84. package/dist/migrations.d.ts +8 -0
  85. package/dist/migrations.d.ts.map +1 -0
  86. package/dist/migrations.js +5 -0
  87. package/dist/operators.d.ts +3 -0
  88. package/dist/operators.d.ts.map +1 -0
  89. package/dist/operators.js +1 -0
  90. package/dist/sql-helpers.d.ts +3 -0
  91. package/dist/sql-helpers.d.ts.map +1 -0
  92. package/dist/sql-helpers.js +1 -0
  93. package/package.json +56 -7
  94. package/src/index.ts +198 -0
  95. package/src/lib/adapter.ts +653 -0
  96. package/src/lib/column.ts +384 -0
  97. package/src/lib/database/execution-context.ts +15 -0
  98. package/src/lib/database/helpers.ts +216 -0
  99. package/src/lib/database/query-execution.ts +638 -0
  100. package/src/lib/database/relations.ts +332 -0
  101. package/src/lib/database/write-lifecycle.ts +487 -0
  102. package/src/lib/database.ts +856 -0
  103. package/src/lib/errors.ts +119 -0
  104. package/src/lib/inflection.ts +69 -0
  105. package/src/lib/migrations/filename.ts +25 -0
  106. package/src/lib/migrations/helpers.ts +108 -0
  107. package/src/lib/migrations/journal-store.ts +122 -0
  108. package/src/lib/migrations/registry.ts +62 -0
  109. package/src/lib/migrations/runner.ts +374 -0
  110. package/src/lib/migrations/schema-api.ts +417 -0
  111. package/src/lib/migrations-node.ts +71 -0
  112. package/src/lib/migrations.ts +328 -0
  113. package/src/lib/operators.ts +436 -0
  114. package/src/lib/query.ts +958 -0
  115. package/src/lib/references.ts +78 -0
  116. package/src/lib/sql-helpers.ts +146 -0
  117. package/src/lib/sql.ts +84 -0
  118. package/src/lib/table.ts +1309 -0
  119. package/src/lib/types.ts +3 -0
  120. package/src/migrations/node.ts +1 -0
  121. package/src/migrations.ts +26 -0
  122. package/src/operators.ts +18 -0
  123. package/src/sql-helpers.ts +9 -0
@@ -0,0 +1,193 @@
1
+ import type { ColumnDefinition, ForeignKeyAction, IdentityOptions } from './adapter.ts';
2
+ /**
3
+ * Chainable builder used to describe physical column definitions.
4
+ */
5
+ export declare class ColumnBuilder<output = unknown> {
6
+ #private;
7
+ constructor(definition: ColumnDefinition);
8
+ /**
9
+ * Marks the column as nullable.
10
+ * @returns The column builder with `null` added to its output type.
11
+ */
12
+ nullable(): ColumnBuilder<output | null>;
13
+ /**
14
+ * Marks the column as non-nullable.
15
+ * @returns The column builder with `null` removed from its output type.
16
+ */
17
+ notNull(): ColumnBuilder<Exclude<output, null>>;
18
+ /**
19
+ * Sets a literal default value for the column.
20
+ * @param value Default value to apply when the column is omitted.
21
+ * @returns The column builder.
22
+ */
23
+ default(value: unknown): ColumnBuilder<output>;
24
+ /**
25
+ * Sets the column default to the current timestamp at write time.
26
+ * @returns The column builder.
27
+ */
28
+ defaultNow(): ColumnBuilder<output>;
29
+ /**
30
+ * Sets a raw SQL expression as the column default.
31
+ * @param expression SQL expression used as the default value.
32
+ * @returns The column builder.
33
+ */
34
+ defaultSql(expression: string): ColumnBuilder<output>;
35
+ /**
36
+ * Marks the column as part of the primary key.
37
+ * @returns The column builder.
38
+ */
39
+ primaryKey(): ColumnBuilder<output>;
40
+ /**
41
+ * Marks the column as unique.
42
+ * @param name Optional constraint name.
43
+ * @returns The column builder.
44
+ */
45
+ unique(name?: string): ColumnBuilder<output>;
46
+ /**
47
+ * Adds a foreign-key reference for the column.
48
+ * @param table Referenced table name.
49
+ * @param name Constraint name.
50
+ * @returns The column builder.
51
+ */
52
+ references(table: string, name: string): ColumnBuilder<output>;
53
+ /**
54
+ * Adds a foreign-key reference for the column.
55
+ * @param table Referenced table name.
56
+ * @param columns Referenced column list.
57
+ * @param name Constraint name.
58
+ * @returns The column builder.
59
+ */
60
+ references(table: string, columns: string | string[], name: string): ColumnBuilder<output>;
61
+ /**
62
+ * Sets the foreign-key action used when the referenced row is deleted.
63
+ * @param action Delete action to apply.
64
+ * @returns The column builder.
65
+ */
66
+ onDelete(action: ForeignKeyAction): ColumnBuilder<output>;
67
+ /**
68
+ * Sets the foreign-key action used when the referenced row is updated.
69
+ * @param action Update action to apply.
70
+ * @returns The column builder.
71
+ */
72
+ onUpdate(action: ForeignKeyAction): ColumnBuilder<output>;
73
+ /**
74
+ * Adds a check constraint for the column.
75
+ * @param expression SQL check expression.
76
+ * @param name Constraint name.
77
+ * @returns The column builder.
78
+ */
79
+ check(expression: string, name: string): ColumnBuilder<output>;
80
+ /**
81
+ * Adds a database comment for the column.
82
+ * @param text Comment text.
83
+ * @returns The column builder.
84
+ */
85
+ comment(text: string): ColumnBuilder<output>;
86
+ /**
87
+ * Marks the column as computed from a SQL expression.
88
+ * @param expression SQL expression for the computed value.
89
+ * @param options Computed-column options.
90
+ * @param options.stored Whether the computed column should be stored instead of virtual.
91
+ * @returns The column builder.
92
+ */
93
+ computed(expression: string, options?: {
94
+ stored?: boolean;
95
+ }): ColumnBuilder<output>;
96
+ /**
97
+ * Marks the column as unsigned when the dialect supports it.
98
+ * @returns The column builder.
99
+ */
100
+ unsigned(): ColumnBuilder<output>;
101
+ /**
102
+ * Marks the column as auto-incrementing when the dialect supports it.
103
+ * @returns The column builder.
104
+ */
105
+ autoIncrement(): ColumnBuilder<output>;
106
+ /**
107
+ * Configures an identity column strategy when the dialect supports it.
108
+ * @param options Identity sequence options.
109
+ * @returns The column builder.
110
+ */
111
+ identity(options?: IdentityOptions): ColumnBuilder<output>;
112
+ /**
113
+ * Sets the collation for the column.
114
+ * @param name Collation name.
115
+ * @returns The column builder.
116
+ */
117
+ collate(name: string): ColumnBuilder<output>;
118
+ /**
119
+ * Sets the character set for the column.
120
+ * @param name Character set name.
121
+ * @returns The column builder.
122
+ */
123
+ charset(name: string): ColumnBuilder<output>;
124
+ /**
125
+ * Sets the column length.
126
+ * @param value Maximum length value.
127
+ * @returns The column builder.
128
+ */
129
+ length(value: number): ColumnBuilder<output>;
130
+ /**
131
+ * Sets numeric precision and optional scale for the column.
132
+ * @param value Precision value.
133
+ * @param scale Optional scale value.
134
+ * @returns The column builder.
135
+ */
136
+ precision(value: number, scale?: number): ColumnBuilder<output>;
137
+ /**
138
+ * Sets numeric scale for the column.
139
+ * @param value Scale value.
140
+ * @returns The column builder.
141
+ */
142
+ scale(value: number): ColumnBuilder<output>;
143
+ /**
144
+ * Enables or disables timezone support for time-based columns.
145
+ * @param enabled Whether timezone support should be enabled.
146
+ * @returns The column builder.
147
+ */
148
+ timezone(enabled?: boolean): ColumnBuilder<output>;
149
+ /**
150
+ * Builds the immutable column definition.
151
+ * @returns A normalized column definition.
152
+ */
153
+ build(): ColumnDefinition;
154
+ }
155
+ /** Resolves the runtime output type from a column builder. */
156
+ export type ColumnOutput<column extends ColumnBuilder<any>> = column extends ColumnBuilder<infer output> ? output : never;
157
+ /** Input type accepted when writing values for a column builder. */
158
+ export type ColumnInput<column extends ColumnBuilder<any>> = ColumnOutput<column>;
159
+ /**
160
+ * Public constructor namespace for column builders.
161
+ */
162
+ export type ColumnNamespace = {
163
+ varchar(length: number): ColumnBuilder<string>;
164
+ text(): ColumnBuilder<string>;
165
+ integer(): ColumnBuilder<number>;
166
+ bigint(): ColumnBuilder;
167
+ decimal(precision: number, scale: number): ColumnBuilder<number>;
168
+ boolean(): ColumnBuilder<boolean>;
169
+ uuid(): ColumnBuilder<string>;
170
+ date(): ColumnBuilder;
171
+ time(options?: {
172
+ precision?: number;
173
+ withTimezone?: boolean;
174
+ }): ColumnBuilder;
175
+ timestamp(options?: {
176
+ precision?: number;
177
+ withTimezone?: boolean;
178
+ }): ColumnBuilder;
179
+ json(): ColumnBuilder;
180
+ binary(length?: number): ColumnBuilder;
181
+ enum<values extends readonly string[]>(values: values): ColumnBuilder<values[number]>;
182
+ };
183
+ /**
184
+ * Chainable column builder namespace.
185
+ * @example
186
+ * ```ts
187
+ * import { column as c } from 'remix/data-table'
188
+ *
189
+ * let email = c.varchar(255).notNull().unique('users_email_uq')
190
+ * ```
191
+ */
192
+ export declare const column: ColumnNamespace;
193
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/lib/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGvF;;GAEG;AACH,qBAAa,aAAa,CAAC,MAAM,GAAG,OAAO;;IAGzC,YAAY,UAAU,EAAE,gBAAgB,EAEvC;IAED;;;OAGG;IACH,QAAQ,IAAI,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC,CAGvC;IAED;;;OAGG;IACH,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAG9C;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAM7C;IAED;;;OAGG;IACH,UAAU,IAAI,aAAa,CAAC,MAAM,CAAC,CAKlC;IAED;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAMpD;IAED;;;OAGG;IACH,UAAU,IAAI,aAAa,CAAC,MAAM,CAAC,CAGlC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAG3C;IAED;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC9D;;;;;;OAMG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAmB1F;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,aAAa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AG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;CACtF,CAAA;AAQD;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,EAAE,eAkDpB,CAAA"}
@@ -0,0 +1,302 @@
1
+ import { toTableRef } from "./migrations/helpers.js";
2
+ /**
3
+ * Chainable builder used to describe physical column definitions.
4
+ */
5
+ export class ColumnBuilder {
6
+ #definition;
7
+ constructor(definition) {
8
+ this.#definition = definition;
9
+ }
10
+ /**
11
+ * Marks the column as nullable.
12
+ * @returns The column builder with `null` added to its output type.
13
+ */
14
+ nullable() {
15
+ this.#definition.nullable = true;
16
+ return this;
17
+ }
18
+ /**
19
+ * Marks the column as non-nullable.
20
+ * @returns The column builder with `null` removed from its output type.
21
+ */
22
+ notNull() {
23
+ this.#definition.nullable = false;
24
+ return this;
25
+ }
26
+ /**
27
+ * Sets a literal default value for the column.
28
+ * @param value Default value to apply when the column is omitted.
29
+ * @returns The column builder.
30
+ */
31
+ default(value) {
32
+ this.#definition.default = {
33
+ kind: 'literal',
34
+ value,
35
+ };
36
+ return this;
37
+ }
38
+ /**
39
+ * Sets the column default to the current timestamp at write time.
40
+ * @returns The column builder.
41
+ */
42
+ defaultNow() {
43
+ this.#definition.default = {
44
+ kind: 'now',
45
+ };
46
+ return this;
47
+ }
48
+ /**
49
+ * Sets a raw SQL expression as the column default.
50
+ * @param expression SQL expression used as the default value.
51
+ * @returns The column builder.
52
+ */
53
+ defaultSql(expression) {
54
+ this.#definition.default = {
55
+ kind: 'sql',
56
+ expression,
57
+ };
58
+ return this;
59
+ }
60
+ /**
61
+ * Marks the column as part of the primary key.
62
+ * @returns The column builder.
63
+ */
64
+ primaryKey() {
65
+ this.#definition.primaryKey = true;
66
+ return this;
67
+ }
68
+ /**
69
+ * Marks the column as unique.
70
+ * @param name Optional constraint name.
71
+ * @returns The column builder.
72
+ */
73
+ unique(name) {
74
+ this.#definition.unique = name ? { name } : true;
75
+ return this;
76
+ }
77
+ references(table, columnsOrName, maybeName) {
78
+ let columns = maybeName === undefined ? 'id' : columnsOrName;
79
+ let name = maybeName === undefined ? String(columnsOrName) : maybeName;
80
+ this.#definition.references = {
81
+ table: toTableRef(table),
82
+ columns: Array.isArray(columns) ? [...columns] : [columns],
83
+ onDelete: this.#definition.references?.onDelete,
84
+ onUpdate: this.#definition.references?.onUpdate,
85
+ name,
86
+ };
87
+ return this;
88
+ }
89
+ /**
90
+ * Sets the foreign-key action used when the referenced row is deleted.
91
+ * @param action Delete action to apply.
92
+ * @returns The column builder.
93
+ */
94
+ onDelete(action) {
95
+ if (!this.#definition.references) {
96
+ throw new Error('onDelete() requires references() to be set first');
97
+ }
98
+ this.#definition.references.onDelete = action;
99
+ return this;
100
+ }
101
+ /**
102
+ * Sets the foreign-key action used when the referenced row is updated.
103
+ * @param action Update action to apply.
104
+ * @returns The column builder.
105
+ */
106
+ onUpdate(action) {
107
+ if (!this.#definition.references) {
108
+ throw new Error('onUpdate() requires references() to be set first');
109
+ }
110
+ this.#definition.references.onUpdate = action;
111
+ return this;
112
+ }
113
+ /**
114
+ * Adds a check constraint for the column.
115
+ * @param expression SQL check expression.
116
+ * @param name Constraint name.
117
+ * @returns The column builder.
118
+ */
119
+ check(expression, name) {
120
+ let checks = this.#definition.checks ?? [];
121
+ checks.push({ expression, name });
122
+ this.#definition.checks = checks;
123
+ return this;
124
+ }
125
+ /**
126
+ * Adds a database comment for the column.
127
+ * @param text Comment text.
128
+ * @returns The column builder.
129
+ */
130
+ comment(text) {
131
+ this.#definition.comment = text;
132
+ return this;
133
+ }
134
+ /**
135
+ * Marks the column as computed from a SQL expression.
136
+ * @param expression SQL expression for the computed value.
137
+ * @param options Computed-column options.
138
+ * @param options.stored Whether the computed column should be stored instead of virtual.
139
+ * @returns The column builder.
140
+ */
141
+ computed(expression, options) {
142
+ this.#definition.computed = {
143
+ expression,
144
+ stored: options?.stored ?? true,
145
+ };
146
+ return this;
147
+ }
148
+ /**
149
+ * Marks the column as unsigned when the dialect supports it.
150
+ * @returns The column builder.
151
+ */
152
+ unsigned() {
153
+ this.#definition.unsigned = true;
154
+ return this;
155
+ }
156
+ /**
157
+ * Marks the column as auto-incrementing when the dialect supports it.
158
+ * @returns The column builder.
159
+ */
160
+ autoIncrement() {
161
+ this.#definition.autoIncrement = true;
162
+ return this;
163
+ }
164
+ /**
165
+ * Configures an identity column strategy when the dialect supports it.
166
+ * @param options Identity sequence options.
167
+ * @returns The column builder.
168
+ */
169
+ identity(options) {
170
+ this.#definition.identity = options ?? {};
171
+ return this;
172
+ }
173
+ /**
174
+ * Sets the collation for the column.
175
+ * @param name Collation name.
176
+ * @returns The column builder.
177
+ */
178
+ collate(name) {
179
+ this.#definition.collate = name;
180
+ return this;
181
+ }
182
+ /**
183
+ * Sets the character set for the column.
184
+ * @param name Character set name.
185
+ * @returns The column builder.
186
+ */
187
+ charset(name) {
188
+ this.#definition.charset = name;
189
+ return this;
190
+ }
191
+ /**
192
+ * Sets the column length.
193
+ * @param value Maximum length value.
194
+ * @returns The column builder.
195
+ */
196
+ length(value) {
197
+ this.#definition.length = value;
198
+ return this;
199
+ }
200
+ /**
201
+ * Sets numeric precision and optional scale for the column.
202
+ * @param value Precision value.
203
+ * @param scale Optional scale value.
204
+ * @returns The column builder.
205
+ */
206
+ precision(value, scale) {
207
+ this.#definition.precision = value;
208
+ if (scale !== undefined) {
209
+ this.#definition.scale = scale;
210
+ }
211
+ return this;
212
+ }
213
+ /**
214
+ * Sets numeric scale for the column.
215
+ * @param value Scale value.
216
+ * @returns The column builder.
217
+ */
218
+ scale(value) {
219
+ this.#definition.scale = value;
220
+ return this;
221
+ }
222
+ /**
223
+ * Enables or disables timezone support for time-based columns.
224
+ * @param enabled Whether timezone support should be enabled.
225
+ * @returns The column builder.
226
+ */
227
+ timezone(enabled = true) {
228
+ this.#definition.withTimezone = enabled;
229
+ return this;
230
+ }
231
+ /**
232
+ * Builds the immutable column definition.
233
+ * @returns A normalized column definition.
234
+ */
235
+ build() {
236
+ return {
237
+ ...this.#definition,
238
+ checks: this.#definition.checks ? [...this.#definition.checks] : undefined,
239
+ };
240
+ }
241
+ }
242
+ function createColumnBuilder(type) {
243
+ return new ColumnBuilder({ type });
244
+ }
245
+ /**
246
+ * Chainable column builder namespace.
247
+ * @example
248
+ * ```ts
249
+ * import { column as c } from 'remix/data-table'
250
+ *
251
+ * let email = c.varchar(255).notNull().unique('users_email_uq')
252
+ * ```
253
+ */
254
+ export const column = {
255
+ varchar(length) {
256
+ return new ColumnBuilder({ type: 'varchar', length });
257
+ },
258
+ text() {
259
+ return createColumnBuilder('text');
260
+ },
261
+ integer() {
262
+ return createColumnBuilder('integer');
263
+ },
264
+ bigint() {
265
+ return createColumnBuilder('bigint');
266
+ },
267
+ decimal(precision, scale) {
268
+ return new ColumnBuilder({ type: 'decimal', precision, scale });
269
+ },
270
+ boolean() {
271
+ return createColumnBuilder('boolean');
272
+ },
273
+ uuid() {
274
+ return createColumnBuilder('uuid');
275
+ },
276
+ date() {
277
+ return createColumnBuilder('date');
278
+ },
279
+ time(options) {
280
+ return new ColumnBuilder({
281
+ type: 'time',
282
+ precision: options?.precision,
283
+ withTimezone: options?.withTimezone,
284
+ });
285
+ },
286
+ timestamp(options) {
287
+ return new ColumnBuilder({
288
+ type: 'timestamp',
289
+ precision: options?.precision,
290
+ withTimezone: options?.withTimezone,
291
+ });
292
+ },
293
+ json() {
294
+ return createColumnBuilder('json');
295
+ },
296
+ binary(length) {
297
+ return new ColumnBuilder({ type: 'binary', length });
298
+ },
299
+ enum(values) {
300
+ return new ColumnBuilder({ type: 'enum', enumValues: [...values] });
301
+ },
302
+ };
@@ -0,0 +1,10 @@
1
+ import type { DataManipulationOperation, DataManipulationResult, DatabaseAdapter } from '../adapter.ts';
2
+ import type { Database } from '../database.ts';
3
+ export declare const executeOperation: unique symbol;
4
+ export type QueryExecutionContext = {
5
+ adapter: DatabaseAdapter;
6
+ now(): unknown;
7
+ transaction<result>(callback: (database: Database) => Promise<result>): Promise<result>;
8
+ [executeOperation](operation: DataManipulationOperation): Promise<DataManipulationResult>;
9
+ };
10
+ //# sourceMappingURL=execution-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../../src/lib/database/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACtB,eAAe,EAChB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,eAAO,MAAM,gBAAgB,eAA6B,CAAA;AAE1D,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,eAAe,CAAA;IACxB,GAAG,IAAI,OAAO,CAAA;IACd,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACvF,CAAC,gBAAgB,CAAC,CAAC,SAAS,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;CAC1F,CAAA"}
@@ -0,0 +1 @@
1
+ export const executeOperation = Symbol('executeOperation');
@@ -0,0 +1,26 @@
1
+ import type { OrderByInput, OrderByTuple, QueryTableInput, SingleTableWhere, TableColumnName, WriteResult, WriteRowsResult } from '../database.ts';
2
+ import type { Predicate } from '../operators.ts';
3
+ import type { AnyTable, PrimaryKeyInput, TableName, TablePrimaryKey, TableRow } from '../table.ts';
4
+ import type { QueryExecutionContext } from './execution-context.ts';
5
+ export declare function asQueryTableInput<table extends AnyTable>(table: table): QueryTableInput<TableName<table>, TableRow<table>, TablePrimaryKey<table>>;
6
+ export declare function getPrimaryKeyWhere<table extends AnyTable>(table: table, value: PrimaryKeyInput<table>): SingleTableWhere<table>;
7
+ export declare function getPrimaryKeyWhereFromRow<table extends AnyTable>(table: table, row: Record<string, unknown>): SingleTableWhere<table>;
8
+ export declare function resolveCreateRowWhere<table extends AnyTable>(table: table, values: Partial<TableRow<table>>, insertId: unknown): SingleTableWhere<table>;
9
+ export declare function normalizeOrderByInput<table extends AnyTable>(input: OrderByInput<table> | undefined): OrderByTuple<table>[];
10
+ export declare function toWriteResult(result: WriteResult | WriteRowsResult<unknown>): WriteResult;
11
+ export declare function hasScopedWriteModifiers(state: {
12
+ orderBy: unknown[];
13
+ limit?: number;
14
+ offset?: number;
15
+ }): boolean;
16
+ export declare function loadPrimaryKeyRowsForScope<table extends AnyTable>(database: QueryExecutionContext, table: table, state: {
17
+ where: Predicate<string>[];
18
+ orderBy: Array<{
19
+ column: string;
20
+ direction: 'asc' | 'desc';
21
+ }>;
22
+ limit?: number;
23
+ offset?: number;
24
+ }): Promise<Record<string, unknown>[]>;
25
+ export declare function buildPrimaryKeyPredicate<table extends AnyTable>(table: table, keyObjects: Record<string, unknown>[]): Predicate<TableColumnName<table>> | undefined;
26
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/database/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EAIZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGlG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAGnE,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,QAAQ,EACtD,KAAK,EAAE,KAAK,GACX,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAM5E;AAED,wBA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C,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GACA,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAuCpC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,QAAQ,EAC7D,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACpC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAyB/C"}
@@ -0,0 +1,116 @@
1
+ import { DataTableQueryError } from "../errors.js";
2
+ import { and, eq, inList, or } from "../operators.js";
3
+ import { query as createQuery } from "../query.js";
4
+ import { getPrimaryKeyObject, getTableName, getTablePrimaryKey } from "../table.js";
5
+ import { loadRowsWithRelationsForQuery } from "./query-execution.js";
6
+ export function asQueryTableInput(table) {
7
+ return table;
8
+ }
9
+ export function getPrimaryKeyWhere(table, value) {
10
+ return getPrimaryKeyObject(table, value);
11
+ }
12
+ export function getPrimaryKeyWhereFromRow(table, row) {
13
+ let where = {};
14
+ for (let key of getTablePrimaryKey(table)) {
15
+ where[key] = row[key];
16
+ }
17
+ return where;
18
+ }
19
+ export function resolveCreateRowWhere(table, values, insertId) {
20
+ let primaryKey = getTablePrimaryKey(table);
21
+ if (primaryKey.length === 1) {
22
+ let key = primaryKey[0];
23
+ if (Object.prototype.hasOwnProperty.call(values, key)) {
24
+ return {
25
+ [key]: values[key],
26
+ };
27
+ }
28
+ if (insertId !== undefined) {
29
+ return {
30
+ [key]: insertId,
31
+ };
32
+ }
33
+ }
34
+ let where = {};
35
+ for (let key of primaryKey) {
36
+ if (!Object.prototype.hasOwnProperty.call(values, key)) {
37
+ throw new DataTableQueryError('create({ returnRow: true }) requires primary key values for table "' +
38
+ getTableName(table) +
39
+ '" when adapter does not support RETURNING');
40
+ }
41
+ where[key] = values[key];
42
+ }
43
+ return where;
44
+ }
45
+ export function normalizeOrderByInput(input) {
46
+ if (!input) {
47
+ return [];
48
+ }
49
+ if (input.length === 0) {
50
+ return [];
51
+ }
52
+ if (Array.isArray(input[0])) {
53
+ return input;
54
+ }
55
+ return [input];
56
+ }
57
+ export function toWriteResult(result) {
58
+ return {
59
+ affectedRows: result.affectedRows,
60
+ insertId: result.insertId,
61
+ };
62
+ }
63
+ export function hasScopedWriteModifiers(state) {
64
+ return state.orderBy.length > 0 || state.limit !== undefined || state.offset !== undefined;
65
+ }
66
+ export async function loadPrimaryKeyRowsForScope(database, table, state) {
67
+ let query = createQuery(table);
68
+ for (let predicate of state.where) {
69
+ query = query.where(predicate);
70
+ }
71
+ for (let clause of state.orderBy) {
72
+ query = query.orderBy(clause.column, clause.direction);
73
+ }
74
+ if (state.limit !== undefined) {
75
+ query = query.limit(state.limit);
76
+ }
77
+ if (state.offset !== undefined) {
78
+ query = query.offset(state.offset);
79
+ }
80
+ let rows = await loadRowsWithRelationsForQuery(database, query.select(...getTablePrimaryKey(table)));
81
+ let primaryKeys = getTablePrimaryKey(table);
82
+ return rows.map((row) => {
83
+ let keyObject = {};
84
+ for (let key of rowKeys(row, primaryKeys)) {
85
+ keyObject[key] = row[key];
86
+ }
87
+ return keyObject;
88
+ });
89
+ }
90
+ export function buildPrimaryKeyPredicate(table, keyObjects) {
91
+ let primaryKey = getTablePrimaryKey(table);
92
+ if (keyObjects.length === 0) {
93
+ return undefined;
94
+ }
95
+ if (primaryKey.length === 1) {
96
+ let key = primaryKey[0];
97
+ return inList(key, keyObjects.map((objectValue) => objectValue[key]));
98
+ }
99
+ let predicates = keyObjects.map((objectValue) => {
100
+ let comparisons = primaryKey.map((key) => {
101
+ let typedKey = key;
102
+ return eq(typedKey, objectValue[typedKey]);
103
+ });
104
+ return and(...comparisons);
105
+ });
106
+ return or(...predicates);
107
+ }
108
+ function rowKeys(row, keys) {
109
+ let output = [];
110
+ for (let key of keys) {
111
+ if (Object.prototype.hasOwnProperty.call(row, key)) {
112
+ output.push(key);
113
+ }
114
+ }
115
+ return output;
116
+ }
@@ -0,0 +1,7 @@
1
+ import type { AnyQuery, QueryExecutionResult, QueryState } from '../query.ts';
2
+ import type { AnyTable } from '../table.ts';
3
+ import { type QueryExecutionContext } from './execution-context.ts';
4
+ export declare function executeQuery<input extends AnyQuery>(database: QueryExecutionContext, input: input): Promise<QueryExecutionResult<input>>;
5
+ export declare function loadRowsWithRelationsForQuery(database: QueryExecutionContext, input: AnyQuery): Promise<Record<string, unknown>[]>;
6
+ export declare function loadRowsWithRelationsForState(database: QueryExecutionContext, table: AnyTable, state: QueryState): Promise<Record<string, unknown>[]>;
7
+ //# sourceMappingURL=query-execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-execution.d.ts","sourceRoot":"","sources":["../../../src/lib/database/query-execution.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG3C,OAAO,EAAoB,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAmBrF,wBAAsB,YAAY,CAAC,KAAK,SAAS,QAAQ,EACvD,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CA0EtC;AAED,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,QAAQ,GACd,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAGpC;AAED,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,QAAQ,EACf,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAUpC"}