metal-orm 1.0.45 → 1.0.46
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/dist/index.cjs +72 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -4
- package/dist/index.d.ts +72 -4
- package/dist/index.js +69 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ast/adapters.ts +2 -1
- package/src/core/ddl/dialects/base-schema-dialect.ts +2 -1
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +10 -23
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +10 -24
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +10 -23
- package/src/core/ddl/dialects/render-reference.test.ts +2 -1
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -23
- package/src/core/ddl/introspect/catalogs/postgres.ts +2 -1
- package/src/core/ddl/introspect/mssql.ts +17 -1
- package/src/core/ddl/introspect/postgres.ts +2 -1
- package/src/core/ddl/introspect/sqlite.ts +2 -1
- package/src/core/ddl/schema-dialect.ts +2 -1
- package/src/core/ddl/schema-diff.ts +2 -1
- package/src/core/ddl/schema-generator.ts +2 -1
- package/src/core/ddl/schema-types.ts +2 -1
- package/src/core/ddl/sql-writing.ts +2 -1
- package/src/core/functions/datetime.ts +2 -1
- package/src/core/functions/numeric.ts +2 -1
- package/src/core/functions/text.ts +2 -1
- package/src/decorators/{column.ts → column-decorator.ts} +4 -1
- package/src/decorators/index.ts +1 -1
- package/src/index.ts +2 -1
- package/src/orm/entity-metadata.ts +2 -1
- package/src/orm/lazy-batch.ts +2 -1
- package/src/orm/orm-session.ts +2 -1
- package/src/query-builder/column-selector.ts +2 -1
- package/src/query-builder/delete.ts +2 -1
- package/src/query-builder/insert.ts +2 -1
- package/src/query-builder/query-ast-service.ts +2 -1
- package/src/query-builder/relation-projection-helper.ts +2 -1
- package/src/query-builder/relation-service.ts +2 -1
- package/src/query-builder/select/predicate-facet.ts +2 -1
- package/src/query-builder/select/projection-facet.ts +2 -1
- package/src/query-builder/select-helpers.ts +2 -1
- package/src/query-builder/select.ts +2 -1
- package/src/query-builder/update.ts +2 -1
- package/src/schema/{column.ts → column-types.ts} +317 -290
- package/src/schema/table-guards.ts +1 -1
- package/src/schema/table.ts +1 -1
- package/src/schema/types.ts +10 -8
|
@@ -1,290 +1,317 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* @returns ColumnDef with
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Creates a
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Creates a
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Creates a
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Marks a column as
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Canonical, dialect-agnostic column data types.
|
|
3
|
+
* Keep this intentionally small; dialect-specific names should be expressed via `dialectTypes`.
|
|
4
|
+
*/
|
|
5
|
+
export const STANDARD_COLUMN_TYPES = [
|
|
6
|
+
'INT',
|
|
7
|
+
'INTEGER',
|
|
8
|
+
'BIGINT',
|
|
9
|
+
'VARCHAR',
|
|
10
|
+
'TEXT',
|
|
11
|
+
'JSON',
|
|
12
|
+
'ENUM',
|
|
13
|
+
'DECIMAL',
|
|
14
|
+
'FLOAT',
|
|
15
|
+
'DOUBLE',
|
|
16
|
+
'UUID',
|
|
17
|
+
'BINARY',
|
|
18
|
+
'VARBINARY',
|
|
19
|
+
'BLOB',
|
|
20
|
+
'DATE',
|
|
21
|
+
'DATETIME',
|
|
22
|
+
'TIMESTAMP',
|
|
23
|
+
'TIMESTAMPTZ',
|
|
24
|
+
'BOOLEAN'
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
/** Known logical types the ORM understands. */
|
|
28
|
+
export type StandardColumnType = (typeof STANDARD_COLUMN_TYPES)[number];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Column type value.
|
|
32
|
+
* We allow arbitrary strings so new/dialect-specific types don't require touching this module.
|
|
33
|
+
*/
|
|
34
|
+
export type ColumnType = StandardColumnType | (string & {});
|
|
35
|
+
|
|
36
|
+
const STANDARD_TYPE_SET = new Set<string>(STANDARD_COLUMN_TYPES.map(t => t.toLowerCase()));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Normalizes a column type to its canonical lowercase form when it's one of the known logical types.
|
|
40
|
+
* Unknown/custom types are returned untouched to avoid clobbering dialect-specific casing.
|
|
41
|
+
*/
|
|
42
|
+
export const normalizeColumnType = (type: ColumnType): ColumnType => {
|
|
43
|
+
if (typeof type !== 'string') return type;
|
|
44
|
+
const lower = type.toLowerCase();
|
|
45
|
+
return STANDARD_TYPE_SET.has(lower) ? lower : type;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Renders a raw SQL type name with optional parameters.
|
|
50
|
+
*/
|
|
51
|
+
export const renderTypeWithArgs = (sqlType: string, args?: unknown[]): string => {
|
|
52
|
+
if (!args || args.length === 0) return sqlType;
|
|
53
|
+
return `${sqlType}(${args.join(', ')})`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type ReferentialAction =
|
|
57
|
+
| 'NO ACTION'
|
|
58
|
+
| 'RESTRICT'
|
|
59
|
+
| 'CASCADE'
|
|
60
|
+
| 'SET NULL'
|
|
61
|
+
| 'SET DEFAULT';
|
|
62
|
+
|
|
63
|
+
export interface RawDefaultValue {
|
|
64
|
+
raw: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type DefaultValue = unknown | RawDefaultValue;
|
|
68
|
+
|
|
69
|
+
export interface ForeignKeyReference {
|
|
70
|
+
/** Target table name */
|
|
71
|
+
table: string;
|
|
72
|
+
/** Target column name */
|
|
73
|
+
column: string;
|
|
74
|
+
/** Optional constraint name */
|
|
75
|
+
name?: string;
|
|
76
|
+
/** ON DELETE action */
|
|
77
|
+
onDelete?: ReferentialAction;
|
|
78
|
+
/** ON UPDATE action */
|
|
79
|
+
onUpdate?: ReferentialAction;
|
|
80
|
+
/** Whether the constraint is deferrable (Postgres) */
|
|
81
|
+
deferrable?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Definition of a database column
|
|
86
|
+
*/
|
|
87
|
+
export interface ColumnDef<T extends ColumnType = ColumnType, TRuntime = unknown> {
|
|
88
|
+
/** Column name (filled at runtime by defineTable) */
|
|
89
|
+
name: string;
|
|
90
|
+
/** Data type of the column */
|
|
91
|
+
type: T;
|
|
92
|
+
/** Optional explicit SQL type per dialect (e.g., { postgres: 'bytea' }) */
|
|
93
|
+
dialectTypes?: Partial<Record<string, string>>;
|
|
94
|
+
/** Optional override for the inferred TypeScript type */
|
|
95
|
+
tsType?: TRuntime;
|
|
96
|
+
/** Whether this column is a primary key */
|
|
97
|
+
primary?: boolean;
|
|
98
|
+
/** Whether this column cannot be null */
|
|
99
|
+
notNull?: boolean;
|
|
100
|
+
/** Whether this column must be unique (or name of the unique constraint) */
|
|
101
|
+
unique?: boolean | string;
|
|
102
|
+
/** Default value for the column */
|
|
103
|
+
default?: DefaultValue;
|
|
104
|
+
/** Whether the column auto-increments / identity */
|
|
105
|
+
autoIncrement?: boolean;
|
|
106
|
+
/** Identity strategy where supported */
|
|
107
|
+
generated?: 'always' | 'byDefault';
|
|
108
|
+
/** Inline check constraint expression */
|
|
109
|
+
check?: string;
|
|
110
|
+
/** Foreign key reference */
|
|
111
|
+
references?: ForeignKeyReference;
|
|
112
|
+
/** Column comment/description */
|
|
113
|
+
comment?: string;
|
|
114
|
+
/** Additional arguments for the column type (e.g., VARCHAR length) */
|
|
115
|
+
args?: unknown[];
|
|
116
|
+
/** Table name this column belongs to (filled at runtime by defineTable) */
|
|
117
|
+
table?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Factory for creating column definitions with common data types
|
|
122
|
+
*/
|
|
123
|
+
export const col = {
|
|
124
|
+
/**
|
|
125
|
+
* Creates an integer column definition
|
|
126
|
+
* @returns ColumnDef with INT type
|
|
127
|
+
*/
|
|
128
|
+
int: (): ColumnDef<'INT'> => ({ name: '', type: 'INT' }),
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Creates a big integer column definition
|
|
132
|
+
*/
|
|
133
|
+
bigint: (): ColumnDef<'BIGINT'> => ({ name: '', type: 'BIGINT' }),
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Creates a variable character column definition
|
|
137
|
+
* @param length - Maximum length of the string
|
|
138
|
+
* @returns ColumnDef with VARCHAR type
|
|
139
|
+
*/
|
|
140
|
+
varchar: (length: number): ColumnDef<'VARCHAR'> => ({ name: '', type: 'VARCHAR', args: [length] }),
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Creates a fixed precision decimal column definition
|
|
144
|
+
*/
|
|
145
|
+
decimal: (precision: number, scale = 0): ColumnDef<'DECIMAL'> => ({
|
|
146
|
+
name: '',
|
|
147
|
+
type: 'DECIMAL',
|
|
148
|
+
args: [precision, scale]
|
|
149
|
+
}),
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Creates a floating point column definition
|
|
153
|
+
*/
|
|
154
|
+
float: (precision?: number): ColumnDef<'FLOAT'> => ({
|
|
155
|
+
name: '',
|
|
156
|
+
type: 'FLOAT',
|
|
157
|
+
args: precision !== undefined ? [precision] : undefined
|
|
158
|
+
}),
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a UUID column definition
|
|
162
|
+
*/
|
|
163
|
+
uuid: (): ColumnDef<'UUID'> => ({ name: '', type: 'UUID' }),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Creates a binary large object column definition
|
|
167
|
+
*/
|
|
168
|
+
blob: (): ColumnDef<'BLOB'> => ({ name: '', type: 'BLOB' }),
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Creates a fixed-length binary column definition
|
|
172
|
+
*/
|
|
173
|
+
binary: (length?: number): ColumnDef<'BINARY'> => ({
|
|
174
|
+
name: '',
|
|
175
|
+
type: 'BINARY',
|
|
176
|
+
args: length !== undefined ? [length] : undefined
|
|
177
|
+
}),
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates a variable-length binary column definition
|
|
181
|
+
*/
|
|
182
|
+
varbinary: (length?: number): ColumnDef<'VARBINARY'> => ({
|
|
183
|
+
name: '',
|
|
184
|
+
type: 'VARBINARY',
|
|
185
|
+
args: length !== undefined ? [length] : undefined
|
|
186
|
+
}),
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Creates a Postgres bytea column definition
|
|
190
|
+
*/
|
|
191
|
+
bytea: (): ColumnDef<'BYTEA'> => ({
|
|
192
|
+
name: '',
|
|
193
|
+
type: 'BYTEA'
|
|
194
|
+
}),
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Creates a timestamp column definition
|
|
198
|
+
*/
|
|
199
|
+
timestamp: <TRuntime = string>(): ColumnDef<'TIMESTAMP', TRuntime> => ({ name: '', type: 'TIMESTAMP' }),
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Creates a timestamptz column definition
|
|
203
|
+
*/
|
|
204
|
+
timestamptz: <TRuntime = string>(): ColumnDef<'TIMESTAMPTZ', TRuntime> => ({ name: '', type: 'TIMESTAMPTZ' }),
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Creates a date column definition
|
|
208
|
+
*/
|
|
209
|
+
date: <TRuntime = string>(): ColumnDef<'DATE', TRuntime> => ({ name: '', type: 'DATE' }),
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates a datetime column definition
|
|
213
|
+
*/
|
|
214
|
+
datetime: <TRuntime = string>(): ColumnDef<'DATETIME', TRuntime> => ({ name: '', type: 'DATETIME' }),
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Creates a JSON column definition
|
|
218
|
+
* @returns ColumnDef with JSON type
|
|
219
|
+
*/
|
|
220
|
+
json: (): ColumnDef<'JSON'> => ({ name: '', type: 'JSON' }),
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Creates a boolean column definition
|
|
224
|
+
* @returns ColumnDef with BOOLEAN type
|
|
225
|
+
*/
|
|
226
|
+
boolean: (): ColumnDef<'BOOLEAN'> => ({ name: '', type: 'BOOLEAN' }),
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Creates an enum column definition
|
|
230
|
+
* @param values - Enum values
|
|
231
|
+
*/
|
|
232
|
+
enum: (values: string[]): ColumnDef<'ENUM'> => ({ name: '', type: 'ENUM', args: values }),
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Creates a column definition with a custom SQL type.
|
|
236
|
+
* Useful for dialect-specific types without polluting the standard set.
|
|
237
|
+
*/
|
|
238
|
+
custom: (type: string, opts: { dialect?: string; args?: unknown[]; tsType?: unknown } = {}): ColumnDef => ({
|
|
239
|
+
name: '',
|
|
240
|
+
type,
|
|
241
|
+
args: opts.args,
|
|
242
|
+
tsType: opts.tsType,
|
|
243
|
+
dialectTypes: opts.dialect ? { [opts.dialect]: type } : undefined
|
|
244
|
+
}),
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Marks a column definition as a primary key
|
|
248
|
+
* @param def - Column definition to modify
|
|
249
|
+
* @returns Modified ColumnDef with primary: true
|
|
250
|
+
*/
|
|
251
|
+
primaryKey: <T extends ColumnType>(def: ColumnDef<T>): ColumnDef<T> =>
|
|
252
|
+
({ ...def, primary: true }),
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Marks a column as NOT NULL
|
|
256
|
+
*/
|
|
257
|
+
notNull: <T extends ColumnType>(def: ColumnDef<T>): ColumnDef<T> =>
|
|
258
|
+
({ ...def, notNull: true }),
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Marks a column as UNIQUE
|
|
262
|
+
*/
|
|
263
|
+
unique: <T extends ColumnType>(def: ColumnDef<T>, name?: string): ColumnDef<T> =>
|
|
264
|
+
({
|
|
265
|
+
...def,
|
|
266
|
+
unique: name ?? true
|
|
267
|
+
}),
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sets a default value for the column
|
|
271
|
+
*/
|
|
272
|
+
default: <T extends ColumnType>(def: ColumnDef<T>, value: unknown): ColumnDef<T> =>
|
|
273
|
+
({
|
|
274
|
+
...def,
|
|
275
|
+
default: value
|
|
276
|
+
}),
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Sets a raw SQL default value for the column
|
|
280
|
+
*/
|
|
281
|
+
defaultRaw: <T extends ColumnType>(def: ColumnDef<T>, expression: string): ColumnDef<T> =>
|
|
282
|
+
({
|
|
283
|
+
...def,
|
|
284
|
+
default: { raw: expression }
|
|
285
|
+
}),
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Marks a column as auto-increment / identity
|
|
289
|
+
*/
|
|
290
|
+
autoIncrement: <T extends ColumnType>(
|
|
291
|
+
def: ColumnDef<T>,
|
|
292
|
+
strategy: ColumnDef['generated'] = 'byDefault'
|
|
293
|
+
): ColumnDef<T> =>
|
|
294
|
+
({
|
|
295
|
+
...def,
|
|
296
|
+
autoIncrement: true,
|
|
297
|
+
generated: strategy
|
|
298
|
+
}),
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Adds a foreign key reference
|
|
302
|
+
*/
|
|
303
|
+
references: <T extends ColumnType>(def: ColumnDef<T>, ref: ForeignKeyReference): ColumnDef<T> =>
|
|
304
|
+
({
|
|
305
|
+
...def,
|
|
306
|
+
references: ref
|
|
307
|
+
}),
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Adds a check constraint to the column
|
|
311
|
+
*/
|
|
312
|
+
check: <T extends ColumnType>(def: ColumnDef<T>, expression: string): ColumnDef<T> =>
|
|
313
|
+
({
|
|
314
|
+
...def,
|
|
315
|
+
check: expression
|
|
316
|
+
})
|
|
317
|
+
};
|
package/src/schema/table.ts
CHANGED