@simplysm/orm-common 13.0.83 → 13.0.85
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/ddl/initialize.d.ts +2 -2
- package/dist/ddl/initialize.js +1 -1
- package/dist/ddl/initialize.js.map +1 -1
- package/dist/ddl/table-ddl.d.ts +1 -1
- package/dist/exec/queryable.d.ts +115 -115
- package/dist/exec/queryable.js +68 -68
- package/dist/exec/queryable.js.map +1 -1
- package/dist/expr/expr.d.ts +248 -248
- package/dist/expr/expr.js +250 -250
- package/dist/query-builder/base/expr-renderer-base.d.ts +7 -7
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts +3 -3
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mssql/mssql-expr-renderer.js +5 -5
- package/dist/query-builder/mssql/mssql-query-builder.d.ts +2 -2
- package/dist/query-builder/mssql/mssql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/mssql/mssql-query-builder.js +7 -7
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts +2 -2
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mysql/mysql-expr-renderer.js +4 -4
- package/dist/query-builder/mysql/mysql-query-builder.d.ts +10 -10
- package/dist/query-builder/mysql/mysql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/mysql/mysql-query-builder.js +4 -4
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts +2 -2
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/postgresql/postgresql-expr-renderer.js +4 -4
- package/dist/query-builder/postgresql/postgresql-query-builder.d.ts +8 -8
- package/dist/query-builder/postgresql/postgresql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/postgresql/postgresql-query-builder.js +7 -7
- package/dist/query-builder/query-builder.d.ts +1 -1
- package/dist/schema/factory/column-builder.d.ts +46 -46
- package/dist/schema/factory/column-builder.js +25 -25
- package/dist/schema/factory/index-builder.d.ts +22 -22
- package/dist/schema/factory/index-builder.js +14 -14
- package/dist/schema/factory/relation-builder.d.ts +93 -93
- package/dist/schema/factory/relation-builder.d.ts.map +1 -1
- package/dist/schema/factory/relation-builder.js +37 -37
- package/dist/schema/procedure-builder.d.ts +38 -38
- package/dist/schema/procedure-builder.d.ts.map +1 -1
- package/dist/schema/procedure-builder.js +26 -26
- package/dist/schema/table-builder.d.ts +38 -38
- package/dist/schema/table-builder.d.ts.map +1 -1
- package/dist/schema/table-builder.js +29 -29
- package/dist/schema/view-builder.d.ts +26 -26
- package/dist/schema/view-builder.d.ts.map +1 -1
- package/dist/schema/view-builder.js +18 -18
- package/dist/types/db.d.ts +40 -40
- package/dist/types/expr.d.ts +75 -75
- package/dist/types/expr.d.ts.map +1 -1
- package/dist/types/query-def.d.ts +32 -32
- package/dist/types/query-def.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/ddl/initialize.ts +16 -16
- package/src/ddl/table-ddl.ts +1 -1
- package/src/exec/queryable.ts +163 -163
- package/src/expr/expr.ts +257 -257
- package/src/query-builder/base/expr-renderer-base.ts +8 -8
- package/src/query-builder/mssql/mssql-expr-renderer.ts +20 -20
- package/src/query-builder/mssql/mssql-query-builder.ts +28 -28
- package/src/query-builder/mysql/mysql-expr-renderer.ts +22 -22
- package/src/query-builder/mysql/mysql-query-builder.ts +65 -65
- package/src/query-builder/postgresql/postgresql-expr-renderer.ts +15 -15
- package/src/query-builder/postgresql/postgresql-query-builder.ts +43 -43
- package/src/query-builder/query-builder.ts +1 -1
- package/src/schema/factory/column-builder.ts +48 -48
- package/src/schema/factory/index-builder.ts +22 -22
- package/src/schema/factory/relation-builder.ts +95 -95
- package/src/schema/procedure-builder.ts +38 -38
- package/src/schema/table-builder.ts +38 -38
- package/src/schema/view-builder.ts +28 -28
- package/src/types/db.ts +41 -41
- package/src/types/expr.ts +79 -79
- package/src/types/query-def.ts +37 -37
- package/tests/ddl/basic.expected.ts +8 -8
|
@@ -2,13 +2,13 @@ import { type InferColumns } from "./column-builder";
|
|
|
2
2
|
import type { TableBuilder } from "../table-builder";
|
|
3
3
|
import type { ViewBuilder } from "../view-builder";
|
|
4
4
|
/**
|
|
5
|
-
* Foreign Key
|
|
5
|
+
* Foreign Key relation builder (N:1)
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Define FK relation from current Table to target Table
|
|
8
|
+
* Creates actual FK constraint in the DB
|
|
9
9
|
*
|
|
10
|
-
* @template TOwner -
|
|
11
|
-
* @template TTargetFn -
|
|
10
|
+
* @template TOwner - Owner Table builder type
|
|
11
|
+
* @template TTargetFn - Target Table builder factory type
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
@@ -24,8 +24,8 @@ import type { ViewBuilder } from "../view-builder";
|
|
|
24
24
|
* }));
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
-
* @see {@link ForeignKeyTargetBuilder}
|
|
28
|
-
* @see {@link RelationKeyBuilder} DB FK
|
|
27
|
+
* @see {@link ForeignKeyTargetBuilder} Reverse-reference builder
|
|
28
|
+
* @see {@link RelationKeyBuilder} Relation without DB FK
|
|
29
29
|
*/
|
|
30
30
|
export declare class ForeignKeyBuilder<TOwner extends TableBuilder<any, any>, TTargetFn extends () => TableBuilder<any, any>> {
|
|
31
31
|
readonly meta: {
|
|
@@ -36,10 +36,10 @@ export declare class ForeignKeyBuilder<TOwner extends TableBuilder<any, any>, TT
|
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* @param meta - FK Metadata
|
|
39
|
-
* @param meta.ownerFn -
|
|
40
|
-
* @param meta.columns - FK column
|
|
41
|
-
* @param meta.targetFn -
|
|
42
|
-
* @param meta.description -
|
|
39
|
+
* @param meta.ownerFn - Owner Table factory
|
|
40
|
+
* @param meta.columns - FK column name array
|
|
41
|
+
* @param meta.targetFn - Target Table factory
|
|
42
|
+
* @param meta.description - Relation description
|
|
43
43
|
*/
|
|
44
44
|
constructor(meta: {
|
|
45
45
|
ownerFn: () => TOwner;
|
|
@@ -48,21 +48,21 @@ export declare class ForeignKeyBuilder<TOwner extends TableBuilder<any, any>, TT
|
|
|
48
48
|
description?: string;
|
|
49
49
|
});
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Set relation description
|
|
52
52
|
*
|
|
53
|
-
* @param desc -
|
|
54
|
-
* @returns
|
|
53
|
+
* @param desc - Relation description
|
|
54
|
+
* @returns New ForeignKeyBuilder instance
|
|
55
55
|
*/
|
|
56
56
|
description(desc: string): ForeignKeyBuilder<TOwner, TTargetFn>;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Foreign Key
|
|
59
|
+
* Foreign Key reverse-reference builder (1:N)
|
|
60
60
|
*
|
|
61
|
-
*
|
|
62
|
-
* include()
|
|
61
|
+
* Define reverse-reference for FK from another Table referencing current Table
|
|
62
|
+
* Loaded as array on include() (single object when single() is called)
|
|
63
63
|
*
|
|
64
|
-
* @template TTargetTableFn -
|
|
65
|
-
* @template TIsSingle -
|
|
64
|
+
* @template TTargetTableFn - Referencing Table builder factory type
|
|
65
|
+
* @template TIsSingle - Whether it is a single object
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* ```typescript
|
|
@@ -76,7 +76,7 @@ export declare class ForeignKeyBuilder<TOwner extends TableBuilder<any, any>, TT
|
|
|
76
76
|
* // 1:N relationship - User ← Post.author
|
|
77
77
|
* posts: r.foreignKeyTarget(() => Post, "author"),
|
|
78
78
|
*
|
|
79
|
-
* // 1:1
|
|
79
|
+
* // 1:1 relation (single object)
|
|
80
80
|
* profile: r.foreignKeyTarget(() => Profile, "user").single(),
|
|
81
81
|
* }));
|
|
82
82
|
* ```
|
|
@@ -91,11 +91,11 @@ export declare class ForeignKeyTargetBuilder<TTargetTableFn extends () => TableB
|
|
|
91
91
|
isSingle?: TIsSingle;
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
|
-
* @param meta - FK
|
|
95
|
-
* @param meta.targetTableFn -
|
|
96
|
-
* @param meta.relationName -
|
|
97
|
-
* @param meta.description -
|
|
98
|
-
* @param meta.isSingle -
|
|
94
|
+
* @param meta - FK reverse-reference Metadata
|
|
95
|
+
* @param meta.targetTableFn - Referencing Table factory
|
|
96
|
+
* @param meta.relationName - FK relation name of the referencing Table
|
|
97
|
+
* @param meta.description - Relation description
|
|
98
|
+
* @param meta.isSingle - Whether it is a single object
|
|
99
99
|
*/
|
|
100
100
|
constructor(meta: {
|
|
101
101
|
targetTableFn: TTargetTableFn;
|
|
@@ -104,18 +104,18 @@ export declare class ForeignKeyTargetBuilder<TTargetTableFn extends () => TableB
|
|
|
104
104
|
isSingle?: TIsSingle;
|
|
105
105
|
});
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Set relation description
|
|
108
108
|
*
|
|
109
|
-
* @param desc -
|
|
110
|
-
* @returns
|
|
109
|
+
* @param desc - Relation description
|
|
110
|
+
* @returns New ForeignKeyTargetBuilder instance
|
|
111
111
|
*/
|
|
112
112
|
description(desc: string): ForeignKeyTargetBuilder<TTargetTableFn, TIsSingle>;
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* Set as single object relation (1:1)
|
|
115
115
|
*
|
|
116
|
-
*
|
|
116
|
+
* Default is array (1:N), single object when single() is called
|
|
117
117
|
*
|
|
118
|
-
* @returns
|
|
118
|
+
* @returns New ForeignKeyTargetBuilder instance (isSingle=true)
|
|
119
119
|
*
|
|
120
120
|
* @example
|
|
121
121
|
* ```typescript
|
|
@@ -125,25 +125,25 @@ export declare class ForeignKeyTargetBuilder<TTargetTableFn extends () => TableB
|
|
|
125
125
|
single(): ForeignKeyTargetBuilder<TTargetTableFn, true>;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
128
|
+
* Logical relation builder (N:1) - No DB FK creation
|
|
129
129
|
*
|
|
130
|
-
* ForeignKeyBuilder
|
|
131
|
-
*
|
|
130
|
+
* Same as ForeignKeyBuilder but does not create FK constraints in the DB
|
|
131
|
+
* Can also be used in Views
|
|
132
132
|
*
|
|
133
|
-
* @template TOwner -
|
|
134
|
-
* @template TTargetFn -
|
|
133
|
+
* @template TOwner - Owner Table/View builder type
|
|
134
|
+
* @template TTargetFn - Target Table/View builder factory type
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
137
137
|
* ```typescript
|
|
138
|
-
* // View
|
|
138
|
+
* // Relation definition from View to Table
|
|
139
139
|
* const UserSummary = View("UserSummary")
|
|
140
140
|
* .query((db: MyDb) => db.user().select(...))
|
|
141
141
|
* .relations((r) => ({
|
|
142
|
-
* // View → Table (FK
|
|
142
|
+
* // View → Table (no FK creation)
|
|
143
143
|
* company: r.relationKey(["companyId"], () => Company),
|
|
144
144
|
* }));
|
|
145
145
|
*
|
|
146
|
-
* //
|
|
146
|
+
* // Relation definition from Table without FK
|
|
147
147
|
* const Report = Table("Report")
|
|
148
148
|
* .columns((c) => ({ userId: c.bigint() }))
|
|
149
149
|
* .relations((r) => ({
|
|
@@ -151,7 +151,7 @@ export declare class ForeignKeyTargetBuilder<TTargetTableFn extends () => TableB
|
|
|
151
151
|
* }));
|
|
152
152
|
* ```
|
|
153
153
|
*
|
|
154
|
-
* @see {@link ForeignKeyBuilder} DB FK
|
|
154
|
+
* @see {@link ForeignKeyBuilder} DB FK creation version
|
|
155
155
|
*/
|
|
156
156
|
export declare class RelationKeyBuilder<TOwner extends TableBuilder<any, any> | ViewBuilder<any, any, any>, TTargetFn extends () => TableBuilder<any, any> | ViewBuilder<any, any, any>> {
|
|
157
157
|
readonly meta: {
|
|
@@ -161,11 +161,11 @@ export declare class RelationKeyBuilder<TOwner extends TableBuilder<any, any> |
|
|
|
161
161
|
description?: string;
|
|
162
162
|
};
|
|
163
163
|
/**
|
|
164
|
-
* @param meta -
|
|
165
|
-
* @param meta.ownerFn -
|
|
166
|
-
* @param meta.columns -
|
|
167
|
-
* @param meta.targetFn -
|
|
168
|
-
* @param meta.description -
|
|
164
|
+
* @param meta - Relation Metadata
|
|
165
|
+
* @param meta.ownerFn - Owner Table/View factory
|
|
166
|
+
* @param meta.columns - Relation column name array
|
|
167
|
+
* @param meta.targetFn - Target Table/View factory
|
|
168
|
+
* @param meta.description - Relation description
|
|
169
169
|
*/
|
|
170
170
|
constructor(meta: {
|
|
171
171
|
ownerFn: () => TOwner;
|
|
@@ -174,33 +174,33 @@ export declare class RelationKeyBuilder<TOwner extends TableBuilder<any, any> |
|
|
|
174
174
|
description?: string;
|
|
175
175
|
});
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
177
|
+
* Set relation description
|
|
178
178
|
*
|
|
179
|
-
* @param desc -
|
|
180
|
-
* @returns
|
|
179
|
+
* @param desc - Relation description
|
|
180
|
+
* @returns New RelationKeyBuilder instance
|
|
181
181
|
*/
|
|
182
182
|
description(desc: string): RelationKeyBuilder<TOwner, TTargetFn>;
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
*
|
|
185
|
+
* Logical relation reverse-reference builder (1:N) - No DB FK creation
|
|
186
186
|
*
|
|
187
|
-
* ForeignKeyTargetBuilder
|
|
188
|
-
*
|
|
187
|
+
* Same as ForeignKeyTargetBuilder but does not create FK constraints in the DB
|
|
188
|
+
* Can also be used in Views
|
|
189
189
|
*
|
|
190
|
-
* @template TTargetTableFn -
|
|
191
|
-
* @template TIsSingle -
|
|
190
|
+
* @template TTargetTableFn - Referencing Table/View builder factory type
|
|
191
|
+
* @template TIsSingle - Whether it is a single object
|
|
192
192
|
*
|
|
193
193
|
* @example
|
|
194
194
|
* ```typescript
|
|
195
195
|
* const Company = Table("Company")
|
|
196
196
|
* .columns((c) => ({ id: c.bigint() }))
|
|
197
197
|
* .relations((r) => ({
|
|
198
|
-
* //
|
|
198
|
+
* // Reverse-reference (no FK creation)
|
|
199
199
|
* employees: r.relationKeyTarget(() => UserSummary, "company"),
|
|
200
200
|
* }));
|
|
201
201
|
* ```
|
|
202
202
|
*
|
|
203
|
-
* @see {@link ForeignKeyTargetBuilder} DB FK
|
|
203
|
+
* @see {@link ForeignKeyTargetBuilder} DB FK creation version
|
|
204
204
|
*/
|
|
205
205
|
export declare class RelationKeyTargetBuilder<TTargetTableFn extends () => TableBuilder<any, any> | ViewBuilder<any, any, any>, TIsSingle extends boolean> {
|
|
206
206
|
readonly meta: {
|
|
@@ -210,11 +210,11 @@ export declare class RelationKeyTargetBuilder<TTargetTableFn extends () => Table
|
|
|
210
210
|
isSingle?: TIsSingle;
|
|
211
211
|
};
|
|
212
212
|
/**
|
|
213
|
-
* @param meta -
|
|
214
|
-
* @param meta.targetTableFn -
|
|
215
|
-
* @param meta.relationName -
|
|
216
|
-
* @param meta.description -
|
|
217
|
-
* @param meta.isSingle -
|
|
213
|
+
* @param meta - Relation reverse-reference Metadata
|
|
214
|
+
* @param meta.targetTableFn - Referencing Table/View factory
|
|
215
|
+
* @param meta.relationName - Relation name of the referencing Table/View
|
|
216
|
+
* @param meta.description - Relation description
|
|
217
|
+
* @param meta.isSingle - Whether it is a single object
|
|
218
218
|
*/
|
|
219
219
|
constructor(meta: {
|
|
220
220
|
targetTableFn: TTargetTableFn;
|
|
@@ -223,59 +223,59 @@ export declare class RelationKeyTargetBuilder<TTargetTableFn extends () => Table
|
|
|
223
223
|
isSingle?: TIsSingle;
|
|
224
224
|
});
|
|
225
225
|
/**
|
|
226
|
-
*
|
|
226
|
+
* Set relation description
|
|
227
227
|
*
|
|
228
|
-
* @param desc -
|
|
229
|
-
* @returns
|
|
228
|
+
* @param desc - Relation description
|
|
229
|
+
* @returns New RelationKeyTargetBuilder instance
|
|
230
230
|
*/
|
|
231
231
|
description(desc: string): RelationKeyTargetBuilder<TTargetTableFn, TIsSingle>;
|
|
232
232
|
/**
|
|
233
|
-
*
|
|
233
|
+
* Set as single object relation (1:1)
|
|
234
234
|
*
|
|
235
|
-
*
|
|
235
|
+
* Default is array (1:N), single object when single() is called
|
|
236
236
|
*
|
|
237
|
-
* @returns
|
|
237
|
+
* @returns New RelationKeyTargetBuilder instance (isSingle=true)
|
|
238
238
|
*/
|
|
239
239
|
single(): RelationKeyTargetBuilder<TTargetTableFn, true>;
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
|
-
* FK
|
|
242
|
+
* FK relation factory type (table only)
|
|
243
243
|
*
|
|
244
|
-
* @template TOwner -
|
|
244
|
+
* @template TOwner - Owner Table builder type
|
|
245
245
|
* @template TColumnKey - Column key type
|
|
246
246
|
*/
|
|
247
247
|
type RelationFkFactory<TOwner extends TableBuilder<any, any>, TColumnKey extends string> = {
|
|
248
248
|
/** N:1 FK relationship definition (DB FK Create) */
|
|
249
249
|
foreignKey<TTargetFn extends () => TableBuilder<any, any>>(columns: TColumnKey[], targetFn: TTargetFn): ForeignKeyBuilder<TOwner, TTargetFn>;
|
|
250
|
-
/** 1:N FK
|
|
250
|
+
/** 1:N FK reverse-reference definition */
|
|
251
251
|
foreignKeyTarget<TTargetTableFn extends () => TableBuilder<any, any>>(targetTableFn: TTargetTableFn, relationName: string): ForeignKeyTargetBuilder<TTargetTableFn, false>;
|
|
252
252
|
};
|
|
253
253
|
/**
|
|
254
|
-
*
|
|
254
|
+
* Logical relation factory type (shared for table/View)
|
|
255
255
|
*
|
|
256
|
-
* @template TOwner -
|
|
256
|
+
* @template TOwner - Owner Table/View builder type
|
|
257
257
|
* @template TColumnKey - Column key type
|
|
258
258
|
*/
|
|
259
259
|
type RelationRkFactory<TOwner extends TableBuilder<any, any> | ViewBuilder<any, any, any>, TColumnKey extends string> = {
|
|
260
|
-
/** N:1
|
|
260
|
+
/** N:1 logical relation definition (no DB FK creation) */
|
|
261
261
|
relationKey<TTargetFn extends () => TableBuilder<any, any> | ViewBuilder<any, any, any>>(columns: TColumnKey[], targetFn: TTargetFn): RelationKeyBuilder<TOwner, TTargetFn>;
|
|
262
|
-
/** 1:N
|
|
262
|
+
/** 1:N logical reverse-reference definition */
|
|
263
263
|
relationKeyTarget<TTargetTableFn extends () => TableBuilder<any, any> | ViewBuilder<any, any, any>>(targetTableFn: TTargetTableFn, relationName: string): RelationKeyTargetBuilder<TTargetTableFn, false>;
|
|
264
264
|
};
|
|
265
265
|
/**
|
|
266
|
-
*
|
|
266
|
+
* Relation builder factory creation
|
|
267
267
|
*
|
|
268
|
-
* TableBuilder.relations()
|
|
269
|
-
* Table
|
|
268
|
+
* Used in TableBuilder.relations() and ViewBuilder.relations()
|
|
269
|
+
* Table can use both FK + RelationKey, View can only use RelationKey
|
|
270
270
|
*
|
|
271
|
-
* @template TOwner -
|
|
271
|
+
* @template TOwner - Owner Table/View builder type
|
|
272
272
|
* @template TColumnKey - Column key type
|
|
273
|
-
* @param ownerFn -
|
|
274
|
-
* @returns
|
|
273
|
+
* @param ownerFn - Owner Table/View factory function
|
|
274
|
+
* @returns Relation builder factory
|
|
275
275
|
*
|
|
276
276
|
* @example
|
|
277
277
|
* ```typescript
|
|
278
|
-
* // Table - FK
|
|
278
|
+
* // Table - both FK and RelationKey available
|
|
279
279
|
* const Post = Table("Post")
|
|
280
280
|
* .columns((c) => ({
|
|
281
281
|
* id: c.bigint(),
|
|
@@ -285,11 +285,11 @@ type RelationRkFactory<TOwner extends TableBuilder<any, any> | ViewBuilder<any,
|
|
|
285
285
|
* author: r.foreignKey(["authorId"], () => User), // FK Generate
|
|
286
286
|
* }));
|
|
287
287
|
*
|
|
288
|
-
* // View - RelationKey
|
|
288
|
+
* // View - only RelationKey available
|
|
289
289
|
* const UserSummary = View("UserSummary")
|
|
290
290
|
* .query(...)
|
|
291
291
|
* .relations((r) => ({
|
|
292
|
-
* posts: r.relationKeyTarget(() => Post, "author"), // FK
|
|
292
|
+
* posts: r.relationKeyTarget(() => Post, "author"), // No FK creation
|
|
293
293
|
* }));
|
|
294
294
|
* ```
|
|
295
295
|
*/
|
|
@@ -297,32 +297,32 @@ export declare function createRelationFactory<TOwner extends TableBuilder<any, a
|
|
|
297
297
|
/**
|
|
298
298
|
* relationship builder record type
|
|
299
299
|
*
|
|
300
|
-
* TableBuilder.relations()
|
|
300
|
+
* Return type of TableBuilder.relations() and ViewBuilder.relations()
|
|
301
301
|
*/
|
|
302
302
|
export type RelationBuilderRecord = Record<string, ForeignKeyBuilder<any, any> | ForeignKeyTargetBuilder<any, any> | RelationKeyBuilder<any, any> | RelationKeyTargetBuilder<any, any>>;
|
|
303
303
|
/**
|
|
304
|
-
*
|
|
304
|
+
* Extract target type from FK/RelationKey (single object)
|
|
305
305
|
*
|
|
306
|
-
* N:1
|
|
306
|
+
* Target type of N:1 relation
|
|
307
307
|
*
|
|
308
|
-
* @template T - FK
|
|
308
|
+
* @template T - FK or RelationKey builder type
|
|
309
309
|
*/
|
|
310
310
|
export type ExtractRelationTarget<TRelation> = TRelation extends ForeignKeyBuilder<any, infer TTargetFn> | RelationKeyBuilder<any, infer TTargetFn> ? ReturnType<TTargetFn> extends TableBuilder<infer TCols, infer TRels> ? InferColumns<TCols> & InferDeepRelations<TRels> : ReturnType<TTargetFn> extends ViewBuilder<any, infer TData, infer TRels> ? TData & InferDeepRelations<TRels> : never : never;
|
|
311
311
|
/**
|
|
312
|
-
*
|
|
312
|
+
* Extract target type from FKTarget/RelationKeyTarget (array or single object)
|
|
313
313
|
*
|
|
314
|
-
* 1:N
|
|
315
|
-
* TTargetTableFn: () => Post
|
|
314
|
+
* Target type of 1:N relation (single object when single() is called)
|
|
315
|
+
* TTargetTableFn: () => Post form for lazy evaluation to prevent circular references
|
|
316
316
|
*
|
|
317
|
-
* @template T - FKTarget
|
|
317
|
+
* @template T - FKTarget or RelationKeyTarget builder type
|
|
318
318
|
*/
|
|
319
319
|
export type ExtractRelationTargetResult<TRelation> = TRelation extends ForeignKeyTargetBuilder<infer TTargetTableFn, infer TIsSingle> | RelationKeyTargetBuilder<infer TTargetTableFn, infer TIsSingle> ? ReturnType<TTargetTableFn> extends TableBuilder<infer TCols, infer TRels> ? TIsSingle extends true ? InferColumns<TCols> & InferDeepRelations<TRels> : (InferColumns<TCols> & InferDeepRelations<TRels>)[] : ReturnType<TTargetTableFn> extends ViewBuilder<any, infer TData, infer TRels> ? TIsSingle extends true ? TData & InferDeepRelations<TRels> : (TData & InferDeepRelations<TRels>)[] : never : never;
|
|
320
320
|
/**
|
|
321
|
-
*
|
|
321
|
+
* Deep relation Type inference from relation definitions
|
|
322
322
|
*
|
|
323
|
-
*
|
|
323
|
+
* Makes all relations optional so accessing without include() results in undefined
|
|
324
324
|
*
|
|
325
|
-
* @template TRelations -
|
|
325
|
+
* @template TRelations - Relation builder record type
|
|
326
326
|
*
|
|
327
327
|
* @example
|
|
328
328
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation-builder.d.ts","sourceRoot":"","sources":["..\\..\\..\\src\\schema\\factory\\relation-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAMnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,iBAAiB,CAC5B,MAAM,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EACrC,SAAS,SAAS,MAAM,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC;IAU5C,QAAQ,CAAC,IAAI,EAAE;QACb,OAAO,EAAE,MAAM,MAAM,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,QAAQ,EAAE,SAAS,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB;IAbH;;;;;;OAMG;gBAEQ,IAAI,EAAE;QACb,OAAO,EAAE,MAAM,MAAM,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,QAAQ,EAAE,SAAS,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB;IAGH;;;;;OAKG;IAC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,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,GACvC,KAAK,GACT,KAAK,CAAC;AAEV;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,kBAAkB,CAAC,UAAU,SAAS,qBAAqB,IAAI;KACxE,CAAC,IAAI,MAAM,UAAU,CAAC,CAAC,EACpB,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACpC,2BAA2B,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CAC/C,CAAC"}
|
|
@@ -2,19 +2,19 @@ import {} from "./column-builder.js";
|
|
|
2
2
|
class ForeignKeyBuilder {
|
|
3
3
|
/**
|
|
4
4
|
* @param meta - FK Metadata
|
|
5
|
-
* @param meta.ownerFn -
|
|
6
|
-
* @param meta.columns - FK column
|
|
7
|
-
* @param meta.targetFn -
|
|
8
|
-
* @param meta.description -
|
|
5
|
+
* @param meta.ownerFn - Owner Table factory
|
|
6
|
+
* @param meta.columns - FK column name array
|
|
7
|
+
* @param meta.targetFn - Target Table factory
|
|
8
|
+
* @param meta.description - Relation description
|
|
9
9
|
*/
|
|
10
10
|
constructor(meta) {
|
|
11
11
|
this.meta = meta;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Set relation description
|
|
15
15
|
*
|
|
16
|
-
* @param desc -
|
|
17
|
-
* @returns
|
|
16
|
+
* @param desc - Relation description
|
|
17
|
+
* @returns New ForeignKeyBuilder instance
|
|
18
18
|
*/
|
|
19
19
|
description(desc) {
|
|
20
20
|
return new ForeignKeyBuilder({ ...this.meta, description: desc });
|
|
@@ -22,30 +22,30 @@ class ForeignKeyBuilder {
|
|
|
22
22
|
}
|
|
23
23
|
class ForeignKeyTargetBuilder {
|
|
24
24
|
/**
|
|
25
|
-
* @param meta - FK
|
|
26
|
-
* @param meta.targetTableFn -
|
|
27
|
-
* @param meta.relationName -
|
|
28
|
-
* @param meta.description -
|
|
29
|
-
* @param meta.isSingle -
|
|
25
|
+
* @param meta - FK reverse-reference Metadata
|
|
26
|
+
* @param meta.targetTableFn - Referencing Table factory
|
|
27
|
+
* @param meta.relationName - FK relation name of the referencing Table
|
|
28
|
+
* @param meta.description - Relation description
|
|
29
|
+
* @param meta.isSingle - Whether it is a single object
|
|
30
30
|
*/
|
|
31
31
|
constructor(meta) {
|
|
32
32
|
this.meta = meta;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Set relation description
|
|
36
36
|
*
|
|
37
|
-
* @param desc -
|
|
38
|
-
* @returns
|
|
37
|
+
* @param desc - Relation description
|
|
38
|
+
* @returns New ForeignKeyTargetBuilder instance
|
|
39
39
|
*/
|
|
40
40
|
description(desc) {
|
|
41
41
|
return new ForeignKeyTargetBuilder({ ...this.meta, description: desc });
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Set as single object relation (1:1)
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* Default is array (1:N), single object when single() is called
|
|
47
47
|
*
|
|
48
|
-
* @returns
|
|
48
|
+
* @returns New ForeignKeyTargetBuilder instance (isSingle=true)
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
51
|
* ```typescript
|
|
@@ -58,20 +58,20 @@ class ForeignKeyTargetBuilder {
|
|
|
58
58
|
}
|
|
59
59
|
class RelationKeyBuilder {
|
|
60
60
|
/**
|
|
61
|
-
* @param meta -
|
|
62
|
-
* @param meta.ownerFn -
|
|
63
|
-
* @param meta.columns -
|
|
64
|
-
* @param meta.targetFn -
|
|
65
|
-
* @param meta.description -
|
|
61
|
+
* @param meta - Relation Metadata
|
|
62
|
+
* @param meta.ownerFn - Owner Table/View factory
|
|
63
|
+
* @param meta.columns - Relation column name array
|
|
64
|
+
* @param meta.targetFn - Target Table/View factory
|
|
65
|
+
* @param meta.description - Relation description
|
|
66
66
|
*/
|
|
67
67
|
constructor(meta) {
|
|
68
68
|
this.meta = meta;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Set relation description
|
|
72
72
|
*
|
|
73
|
-
* @param desc -
|
|
74
|
-
* @returns
|
|
73
|
+
* @param desc - Relation description
|
|
74
|
+
* @returns New RelationKeyBuilder instance
|
|
75
75
|
*/
|
|
76
76
|
description(desc) {
|
|
77
77
|
return new RelationKeyBuilder({ ...this.meta, description: desc });
|
|
@@ -79,30 +79,30 @@ class RelationKeyBuilder {
|
|
|
79
79
|
}
|
|
80
80
|
class RelationKeyTargetBuilder {
|
|
81
81
|
/**
|
|
82
|
-
* @param meta -
|
|
83
|
-
* @param meta.targetTableFn -
|
|
84
|
-
* @param meta.relationName -
|
|
85
|
-
* @param meta.description -
|
|
86
|
-
* @param meta.isSingle -
|
|
82
|
+
* @param meta - Relation reverse-reference Metadata
|
|
83
|
+
* @param meta.targetTableFn - Referencing Table/View factory
|
|
84
|
+
* @param meta.relationName - Relation name of the referencing Table/View
|
|
85
|
+
* @param meta.description - Relation description
|
|
86
|
+
* @param meta.isSingle - Whether it is a single object
|
|
87
87
|
*/
|
|
88
88
|
constructor(meta) {
|
|
89
89
|
this.meta = meta;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Set relation description
|
|
93
93
|
*
|
|
94
|
-
* @param desc -
|
|
95
|
-
* @returns
|
|
94
|
+
* @param desc - Relation description
|
|
95
|
+
* @returns New RelationKeyTargetBuilder instance
|
|
96
96
|
*/
|
|
97
97
|
description(desc) {
|
|
98
98
|
return new RelationKeyTargetBuilder({ ...this.meta, description: desc });
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Set as single object relation (1:1)
|
|
102
102
|
*
|
|
103
|
-
*
|
|
103
|
+
* Default is array (1:N), single object when single() is called
|
|
104
104
|
*
|
|
105
|
-
* @returns
|
|
105
|
+
* @returns New RelationKeyTargetBuilder instance (isSingle=true)
|
|
106
106
|
*/
|
|
107
107
|
single() {
|
|
108
108
|
return new RelationKeyTargetBuilder({ ...this.meta, isSingle: true });
|