@simplysm/orm-common 13.0.83 → 13.0.84
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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type ColumnBuilderRecord, createColumnFactory } from "./factory/column-builder";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Stored Procedure definition builder
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* DbContext
|
|
5
|
+
* Define Procedure parameters, return type, and body via Fluent API
|
|
6
|
+
* Use with DbContext's executable() for type-safe Procedure invocation
|
|
7
7
|
*
|
|
8
|
-
* @template TParams -
|
|
9
|
-
* @template TReturns -
|
|
8
|
+
* @template TParams - Parameter Column definition type
|
|
9
|
+
* @template TReturns - Return Column definition type
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -23,12 +23,12 @@ import { type ColumnBuilderRecord, createColumnFactory } from "./factory/column-
|
|
|
23
23
|
* }))
|
|
24
24
|
* .body("SELECT id, name, email FROM User WHERE id = userId");
|
|
25
25
|
*
|
|
26
|
-
* //
|
|
26
|
+
* // Used in DbContext
|
|
27
27
|
* class MyDb extends DbContext {
|
|
28
28
|
* readonly getUserById = executable(this, GetUserById);
|
|
29
29
|
* }
|
|
30
30
|
*
|
|
31
|
-
* //
|
|
31
|
+
* // Invocation
|
|
32
32
|
* const users = await db.getUserById({ userId: 1n }).execute();
|
|
33
33
|
* ```
|
|
34
34
|
*
|
|
@@ -45,19 +45,19 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
45
45
|
returns?: TReturns;
|
|
46
46
|
query?: string;
|
|
47
47
|
};
|
|
48
|
-
/**
|
|
48
|
+
/** Parameter definition (type for inference) */
|
|
49
49
|
readonly $params: TParams;
|
|
50
50
|
/** return type definition (type for inference) */
|
|
51
51
|
readonly $returns: TReturns;
|
|
52
52
|
/**
|
|
53
53
|
* @param meta - Procedure Metadata
|
|
54
|
-
* @param meta.name - Procedure
|
|
55
|
-
* @param meta.description - Procedure description (
|
|
56
|
-
* @param meta.database - Database
|
|
57
|
-
* @param meta.schema - Schema
|
|
58
|
-
* @param meta.params -
|
|
59
|
-
* @param meta.returns -
|
|
60
|
-
* @param meta.query - Procedure
|
|
54
|
+
* @param meta.name - Procedure name
|
|
55
|
+
* @param meta.description - Procedure description (comment)
|
|
56
|
+
* @param meta.database - Database name
|
|
57
|
+
* @param meta.schema - Schema name (MSSQL/PostgreSQL)
|
|
58
|
+
* @param meta.params - Parameter definition
|
|
59
|
+
* @param meta.returns - Return type definition
|
|
60
|
+
* @param meta.query - Procedure body SQL
|
|
61
61
|
*/
|
|
62
62
|
constructor(meta: {
|
|
63
63
|
name: string;
|
|
@@ -71,14 +71,14 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
71
71
|
/**
|
|
72
72
|
* Procedure set description
|
|
73
73
|
*
|
|
74
|
-
* @param desc - Procedure description (DDL Comment
|
|
74
|
+
* @param desc - Procedure description (used as DDL Comment)
|
|
75
75
|
* @returns new ProcedureBuilder instance
|
|
76
76
|
*/
|
|
77
77
|
description(desc: string): ProcedureBuilder<TParams, TReturns>;
|
|
78
78
|
/**
|
|
79
79
|
* Database set name
|
|
80
80
|
*
|
|
81
|
-
* @param db - Database
|
|
81
|
+
* @param db - Database name
|
|
82
82
|
* @returns new ProcedureBuilder instance
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
@@ -92,18 +92,18 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
92
92
|
*
|
|
93
93
|
* MSSQL, PostgreSQLused in
|
|
94
94
|
*
|
|
95
|
-
* @param schema - Schema
|
|
95
|
+
* @param schema - Schema name (MSSQL: dbo, PostgreSQL: public)
|
|
96
96
|
* @returns new ProcedureBuilder instance
|
|
97
97
|
*/
|
|
98
98
|
schema(schema: string): ProcedureBuilder<TParams, TReturns>;
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* Parameter definition
|
|
101
101
|
*
|
|
102
|
-
* Procedure
|
|
103
|
-
* DBMS
|
|
102
|
+
* Define Procedure input parameters
|
|
103
|
+
* Note DBMS-specific parameter syntax differences (MSSQL: @param, MySQL/PostgreSQL: param)
|
|
104
104
|
*
|
|
105
|
-
* @template T -
|
|
106
|
-
* @param fn - Column factory
|
|
105
|
+
* @template T - New parameter definition type
|
|
106
|
+
* @param fn - Function that receives a Column factory and returns parameter definitions
|
|
107
107
|
* @returns new ProcedureBuilder instance
|
|
108
108
|
*
|
|
109
109
|
* @example
|
|
@@ -117,12 +117,12 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
117
117
|
*/
|
|
118
118
|
params<T extends ColumnBuilderRecord>(fn: (c: ReturnType<typeof createColumnFactory>) => T): ProcedureBuilder<T, TReturns>;
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
120
|
+
* Return type definition
|
|
121
121
|
*
|
|
122
|
-
* Procedure return result
|
|
122
|
+
* Define Procedure return result columns
|
|
123
123
|
*
|
|
124
|
-
* @template T -
|
|
125
|
-
* @param fn - Column factory
|
|
124
|
+
* @template T - New return type definition
|
|
125
|
+
* @param fn - Function that receives a Column factory and returns Column definitions
|
|
126
126
|
* @returns new ProcedureBuilder instance
|
|
127
127
|
*
|
|
128
128
|
* @example
|
|
@@ -138,14 +138,14 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
138
138
|
*/
|
|
139
139
|
returns<T extends ColumnBuilderRecord>(fn: (c: ReturnType<typeof createColumnFactory>) => T): ProcedureBuilder<TParams, T>;
|
|
140
140
|
/**
|
|
141
|
-
* Procedure
|
|
141
|
+
* Set Procedure body SQL
|
|
142
142
|
*
|
|
143
|
-
* DBMS
|
|
144
|
-
* - MySQL:
|
|
145
|
-
* - MSSQL: @
|
|
146
|
-
* - PostgreSQL: RETURN QUERY
|
|
143
|
+
* Note DBMS-specific SQL syntax differences:
|
|
144
|
+
* - MySQL: parameter name as-is (userId)
|
|
145
|
+
* - MSSQL: @ prefix (@userId)
|
|
146
|
+
* - PostgreSQL: RETURN QUERY required
|
|
147
147
|
*
|
|
148
|
-
* @param sql - Procedure
|
|
148
|
+
* @param sql - Procedure body SQL
|
|
149
149
|
* @returns new ProcedureBuilder instance
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
@@ -164,16 +164,16 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
164
164
|
body(sql: string): ProcedureBuilder<TParams, TReturns>;
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
-
* Procedure builder
|
|
167
|
+
* Procedure builder factory function
|
|
168
168
|
*
|
|
169
|
-
* ProcedureBuilder
|
|
169
|
+
* Creates a ProcedureBuilder for defining stored Procedure schema via Fluent API
|
|
170
170
|
*
|
|
171
|
-
* @param name - Procedure
|
|
171
|
+
* @param name - Procedure name
|
|
172
172
|
* @returns ProcedureBuilder instance
|
|
173
173
|
*
|
|
174
174
|
* @example
|
|
175
175
|
* ```typescript
|
|
176
|
-
* // Basic
|
|
176
|
+
* // Basic usage
|
|
177
177
|
* const GetUserById = Procedure("GetUserById")
|
|
178
178
|
* .database("mydb")
|
|
179
179
|
* .params((c) => ({
|
|
@@ -186,7 +186,7 @@ export declare class ProcedureBuilder<TParams extends ColumnBuilderRecord, TRetu
|
|
|
186
186
|
* }))
|
|
187
187
|
* .body("SELECT id, name, email FROM User WHERE id = userId");
|
|
188
188
|
*
|
|
189
|
-
* //
|
|
189
|
+
* // Procedure without parameters
|
|
190
190
|
* const GetAllActiveUsers = Procedure("GetAllActiveUsers")
|
|
191
191
|
* .database("mydb")
|
|
192
192
|
* .returns((c) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure-builder.d.ts","sourceRoot":"","sources":["..\\..\\src\\schema\\procedure-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAMzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
4
4
|
* @param meta - Procedure Metadata
|
|
5
|
-
* @param meta.name - Procedure
|
|
6
|
-
* @param meta.description - Procedure description (
|
|
7
|
-
* @param meta.database - Database
|
|
8
|
-
* @param meta.schema - Schema
|
|
9
|
-
* @param meta.params -
|
|
10
|
-
* @param meta.returns -
|
|
11
|
-
* @param meta.query - Procedure
|
|
5
|
+
* @param meta.name - Procedure name
|
|
6
|
+
* @param meta.description - Procedure description (comment)
|
|
7
|
+
* @param meta.database - Database name
|
|
8
|
+
* @param meta.schema - Schema name (MSSQL/PostgreSQL)
|
|
9
|
+
* @param meta.params - Parameter definition
|
|
10
|
+
* @param meta.returns - Return type definition
|
|
11
|
+
* @param meta.query - Procedure body SQL
|
|
12
12
|
*/
|
|
13
13
|
constructor(meta) {
|
|
14
14
|
this.meta = meta;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/** Parameter definition (type for inference) */
|
|
17
17
|
$params;
|
|
18
18
|
/** return type definition (type for inference) */
|
|
19
19
|
$returns;
|
|
20
20
|
/**
|
|
21
21
|
* Procedure set description
|
|
22
22
|
*
|
|
23
|
-
* @param desc - Procedure description (DDL Comment
|
|
23
|
+
* @param desc - Procedure description (used as DDL Comment)
|
|
24
24
|
* @returns new ProcedureBuilder instance
|
|
25
25
|
*/
|
|
26
26
|
description(desc) {
|
|
@@ -29,7 +29,7 @@ class ProcedureBuilder {
|
|
|
29
29
|
/**
|
|
30
30
|
* Database set name
|
|
31
31
|
*
|
|
32
|
-
* @param db - Database
|
|
32
|
+
* @param db - Database name
|
|
33
33
|
* @returns new ProcedureBuilder instance
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
@@ -45,20 +45,20 @@ class ProcedureBuilder {
|
|
|
45
45
|
*
|
|
46
46
|
* MSSQL, PostgreSQLused in
|
|
47
47
|
*
|
|
48
|
-
* @param schema - Schema
|
|
48
|
+
* @param schema - Schema name (MSSQL: dbo, PostgreSQL: public)
|
|
49
49
|
* @returns new ProcedureBuilder instance
|
|
50
50
|
*/
|
|
51
51
|
schema(schema) {
|
|
52
52
|
return new ProcedureBuilder({ ...this.meta, schema });
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Parameter definition
|
|
56
56
|
*
|
|
57
|
-
* Procedure
|
|
58
|
-
* DBMS
|
|
57
|
+
* Define Procedure input parameters
|
|
58
|
+
* Note DBMS-specific parameter syntax differences (MSSQL: @param, MySQL/PostgreSQL: param)
|
|
59
59
|
*
|
|
60
|
-
* @template T -
|
|
61
|
-
* @param fn - Column factory
|
|
60
|
+
* @template T - New parameter definition type
|
|
61
|
+
* @param fn - Function that receives a Column factory and returns parameter definitions
|
|
62
62
|
* @returns new ProcedureBuilder instance
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
@@ -74,12 +74,12 @@ class ProcedureBuilder {
|
|
|
74
74
|
return new ProcedureBuilder({ ...this.meta, params: fn(createColumnFactory()) });
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Return type definition
|
|
78
78
|
*
|
|
79
|
-
* Procedure return result
|
|
79
|
+
* Define Procedure return result columns
|
|
80
80
|
*
|
|
81
|
-
* @template T -
|
|
82
|
-
* @param fn - Column factory
|
|
81
|
+
* @template T - New return type definition
|
|
82
|
+
* @param fn - Function that receives a Column factory and returns Column definitions
|
|
83
83
|
* @returns new ProcedureBuilder instance
|
|
84
84
|
*
|
|
85
85
|
* @example
|
|
@@ -97,14 +97,14 @@ class ProcedureBuilder {
|
|
|
97
97
|
return new ProcedureBuilder({ ...this.meta, returns: fn(createColumnFactory()) });
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Procedure
|
|
100
|
+
* Set Procedure body SQL
|
|
101
101
|
*
|
|
102
|
-
* DBMS
|
|
103
|
-
* - MySQL:
|
|
104
|
-
* - MSSQL: @
|
|
105
|
-
* - PostgreSQL: RETURN QUERY
|
|
102
|
+
* Note DBMS-specific SQL syntax differences:
|
|
103
|
+
* - MySQL: parameter name as-is (userId)
|
|
104
|
+
* - MSSQL: @ prefix (@userId)
|
|
105
|
+
* - PostgreSQL: RETURN QUERY required
|
|
106
106
|
*
|
|
107
|
-
* @param sql - Procedure
|
|
107
|
+
* @param sql - Procedure body SQL
|
|
108
108
|
* @returns new ProcedureBuilder instance
|
|
109
109
|
*
|
|
110
110
|
* @example
|
|
@@ -4,11 +4,11 @@ import { createRelationFactory, type InferDeepRelations, type RelationBuilderRec
|
|
|
4
4
|
/**
|
|
5
5
|
* Database Table definition builder
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* DbContext
|
|
7
|
+
* Define Table columns, PK, indexes, and relations via Fluent API
|
|
8
|
+
* Use with DbContext's queryable() for type-safe query composition
|
|
9
9
|
*
|
|
10
10
|
* @template TColumns - Column definition record type
|
|
11
|
-
* @template TRelations -
|
|
11
|
+
* @template TRelations - Relation definition record type
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
@@ -24,7 +24,7 @@ import { createRelationFactory, type InferDeepRelations, type RelationBuilderRec
|
|
|
24
24
|
* .primaryKey("id")
|
|
25
25
|
* .indexes((i) => [i.index("email").unique()]);
|
|
26
26
|
*
|
|
27
|
-
* //
|
|
27
|
+
* // Used in DbContext
|
|
28
28
|
* class MyDb extends DbContext {
|
|
29
29
|
* readonly user = queryable(this, User);
|
|
30
30
|
* }
|
|
@@ -46,25 +46,25 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
46
46
|
};
|
|
47
47
|
/** Column definition (type for inference) */
|
|
48
48
|
readonly $columns: TColumns;
|
|
49
|
-
/**
|
|
49
|
+
/** Relation definition (type for inference) */
|
|
50
50
|
readonly $relations: TRelations;
|
|
51
|
-
/**
|
|
51
|
+
/** Full Type inference (column + relation) */
|
|
52
52
|
readonly $inferSelect: InferColumns<TColumns> & InferDeepRelations<TRelations>;
|
|
53
|
-
/**
|
|
53
|
+
/** Column-only Type inference */
|
|
54
54
|
readonly $inferColumns: InferColumns<TColumns>;
|
|
55
|
-
/** INSERT
|
|
55
|
+
/** INSERT Type inference (autoIncrement excluded, nullable/default are optional) */
|
|
56
56
|
readonly $inferInsert: InferInsertColumns<TColumns>;
|
|
57
|
-
/** UPDATE
|
|
57
|
+
/** UPDATE Type inference (all fields optional) */
|
|
58
58
|
readonly $inferUpdate: InferUpdateColumns<TColumns>;
|
|
59
59
|
/**
|
|
60
60
|
* @param meta - Table Metadata
|
|
61
|
-
* @param meta.name - Table
|
|
62
|
-
* @param meta.description - Table description (
|
|
63
|
-
* @param meta.database - Database
|
|
64
|
-
* @param meta.schema - Schema
|
|
61
|
+
* @param meta.name - Table name
|
|
62
|
+
* @param meta.description - Table description (comment)
|
|
63
|
+
* @param meta.database - Database name
|
|
64
|
+
* @param meta.schema - Schema name (MSSQL/PostgreSQL)
|
|
65
65
|
* @param meta.columns - Column definition
|
|
66
66
|
* @param meta.primaryKey - PK column array
|
|
67
|
-
* @param meta.relations -
|
|
67
|
+
* @param meta.relations - Relation definition
|
|
68
68
|
* @param meta.indexes - Index definition
|
|
69
69
|
*/
|
|
70
70
|
constructor(meta: {
|
|
@@ -80,14 +80,14 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
80
80
|
/**
|
|
81
81
|
* Table set description
|
|
82
82
|
*
|
|
83
|
-
* @param desc - Table description (DDL Comment
|
|
83
|
+
* @param desc - Table description (used as DDL Comment)
|
|
84
84
|
* @returns new TableBuilder instance
|
|
85
85
|
*/
|
|
86
86
|
description(desc: string): TableBuilder<TColumns, TRelations>;
|
|
87
87
|
/**
|
|
88
88
|
* Database set name
|
|
89
89
|
*
|
|
90
|
-
* @param db - Database
|
|
90
|
+
* @param db - Database name
|
|
91
91
|
* @returns new TableBuilder instance
|
|
92
92
|
*
|
|
93
93
|
* @example
|
|
@@ -99,9 +99,9 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
99
99
|
/**
|
|
100
100
|
* schema set name
|
|
101
101
|
*
|
|
102
|
-
* MSSQL,
|
|
102
|
+
* Used in MSSQL, PostgreSQL
|
|
103
103
|
*
|
|
104
|
-
* @param schema - Schema
|
|
104
|
+
* @param schema - Schema name (MSSQL: dbo, PostgreSQL: public)
|
|
105
105
|
* @returns new TableBuilder instance
|
|
106
106
|
*
|
|
107
107
|
* @example
|
|
@@ -115,10 +115,10 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
115
115
|
/**
|
|
116
116
|
* Column definition
|
|
117
117
|
*
|
|
118
|
-
*
|
|
118
|
+
* Type-safe Column definition through column factory
|
|
119
119
|
*
|
|
120
|
-
* @template TNewColumnDefs -
|
|
121
|
-
* @param fn - Column factory
|
|
120
|
+
* @template TNewColumnDefs - New Column definition type
|
|
121
|
+
* @param fn - Function that receives a Column factory and returns Column definitions
|
|
122
122
|
* @returns new TableBuilder instance
|
|
123
123
|
*
|
|
124
124
|
* @example
|
|
@@ -134,19 +134,19 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
134
134
|
*/
|
|
135
135
|
columns<TNewColumnDefs extends ColumnBuilderRecord>(fn: (c: ReturnType<typeof createColumnFactory>) => TNewColumnDefs): TableBuilder<TNewColumnDefs, TRelations>;
|
|
136
136
|
/**
|
|
137
|
-
* Primary Key
|
|
137
|
+
* Primary Key configuration
|
|
138
138
|
*
|
|
139
|
-
* @param columns -
|
|
139
|
+
* @param columns - Column names composing the PK (composite PK supported)
|
|
140
140
|
* @returns new TableBuilder instance
|
|
141
141
|
*
|
|
142
142
|
* @example
|
|
143
143
|
* ```typescript
|
|
144
|
-
* //
|
|
144
|
+
* // Single PK
|
|
145
145
|
* const User = Table("User")
|
|
146
146
|
* .columns((c) => ({ id: c.bigint() }))
|
|
147
147
|
* .primaryKey("id");
|
|
148
148
|
*
|
|
149
|
-
* //
|
|
149
|
+
* // Composite PK
|
|
150
150
|
* const UserRole = Table("UserRole")
|
|
151
151
|
* .columns((c) => ({
|
|
152
152
|
* userId: c.bigint(),
|
|
@@ -159,7 +159,7 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
159
159
|
/**
|
|
160
160
|
* Index definition
|
|
161
161
|
*
|
|
162
|
-
* @param fn - Index factory
|
|
162
|
+
* @param fn - Function that receives an Index factory and returns an Index array
|
|
163
163
|
* @returns new TableBuilder instance
|
|
164
164
|
*
|
|
165
165
|
* @example
|
|
@@ -178,12 +178,12 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
178
178
|
*/
|
|
179
179
|
indexes(fn: (i: ReturnType<typeof createIndexFactory<keyof TColumns & string>>) => IndexBuilder<string[]>[]): TableBuilder<TColumns, TRelations>;
|
|
180
180
|
/**
|
|
181
|
-
*
|
|
181
|
+
* Relation definition
|
|
182
182
|
*
|
|
183
|
-
* FK,
|
|
183
|
+
* Set up FK, reverse-references, and other inter-Table relations
|
|
184
184
|
*
|
|
185
|
-
* @template T -
|
|
186
|
-
* @param fn -
|
|
185
|
+
* @template T - Relation definition type
|
|
186
|
+
* @param fn - Function that receives a relation factory and returns relation definitions
|
|
187
187
|
* @returns new TableBuilder instance
|
|
188
188
|
*
|
|
189
189
|
* @example
|
|
@@ -196,7 +196,7 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
196
196
|
* }))
|
|
197
197
|
* .primaryKey("id")
|
|
198
198
|
* .relations((r) => ({
|
|
199
|
-
* // FK
|
|
199
|
+
* // FK relation (N:1)
|
|
200
200
|
* author: r.foreignKey(["authorId"], () => User),
|
|
201
201
|
* }));
|
|
202
202
|
*
|
|
@@ -207,27 +207,27 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
207
207
|
* }))
|
|
208
208
|
* .primaryKey("id")
|
|
209
209
|
* .relations((r) => ({
|
|
210
|
-
* //
|
|
210
|
+
* // Reverse-reference (1:N)
|
|
211
211
|
* posts: r.foreignKeyTarget(() => Post, "author"),
|
|
212
212
|
* }));
|
|
213
213
|
* ```
|
|
214
214
|
*
|
|
215
215
|
* @see {@link ForeignKeyBuilder} FK builder
|
|
216
|
-
* @see {@link ForeignKeyTargetBuilder} FK
|
|
216
|
+
* @see {@link ForeignKeyTargetBuilder} FK reverse-reference builder
|
|
217
217
|
*/
|
|
218
218
|
relations<T extends RelationBuilderRecord>(fn: (r: ReturnType<typeof createRelationFactory<this, keyof TColumns & string>>) => T): TableBuilder<TColumns, T>;
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
|
-
* Table builder
|
|
221
|
+
* Table builder factory function
|
|
222
222
|
*
|
|
223
|
-
* TableBuilder
|
|
223
|
+
* Creates a TableBuilder for defining Table schema via Fluent API
|
|
224
224
|
*
|
|
225
|
-
* @param name - Table
|
|
225
|
+
* @param name - Table name
|
|
226
226
|
* @returns TableBuilder instance
|
|
227
227
|
*
|
|
228
228
|
* @example
|
|
229
229
|
* ```typescript
|
|
230
|
-
* // Basic
|
|
230
|
+
* // Basic usage
|
|
231
231
|
* const User = Table("User")
|
|
232
232
|
* .database("mydb")
|
|
233
233
|
* .columns((c) => ({
|
|
@@ -238,7 +238,7 @@ export declare class TableBuilder<TColumns extends ColumnBuilderRecord, TRelatio
|
|
|
238
238
|
* .primaryKey("id")
|
|
239
239
|
* .indexes((i) => [i.index("email").unique()]);
|
|
240
240
|
*
|
|
241
|
-
* //
|
|
241
|
+
* // With relations
|
|
242
242
|
* const Post = Table("Post")
|
|
243
243
|
* .database("mydb")
|
|
244
244
|
* .columns((c) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-builder.d.ts","sourceRoot":"","sources":["..\\..\\src\\schema\\table-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,E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|
10
10
|
* @param meta - Table Metadata
|
|
11
|
-
* @param meta.name - Table
|
|
12
|
-
* @param meta.description - Table description (
|
|
13
|
-
* @param meta.database - Database
|
|
14
|
-
* @param meta.schema - Schema
|
|
11
|
+
* @param meta.name - Table name
|
|
12
|
+
* @param meta.description - Table description (comment)
|
|
13
|
+
* @param meta.database - Database name
|
|
14
|
+
* @param meta.schema - Schema name (MSSQL/PostgreSQL)
|
|
15
15
|
* @param meta.columns - Column definition
|
|
16
16
|
* @param meta.primaryKey - PK column array
|
|
17
|
-
* @param meta.relations -
|
|
17
|
+
* @param meta.relations - Relation definition
|
|
18
18
|
* @param meta.indexes - Index definition
|
|
19
19
|
*/
|
|
20
20
|
constructor(meta) {
|
|
@@ -22,20 +22,20 @@ class TableBuilder {
|
|
|
22
22
|
}
|
|
23
23
|
/** Column definition (type for inference) */
|
|
24
24
|
$columns;
|
|
25
|
-
/**
|
|
25
|
+
/** Relation definition (type for inference) */
|
|
26
26
|
$relations;
|
|
27
|
-
/**
|
|
27
|
+
/** Full Type inference (column + relation) */
|
|
28
28
|
$inferSelect;
|
|
29
|
-
/**
|
|
29
|
+
/** Column-only Type inference */
|
|
30
30
|
$inferColumns;
|
|
31
|
-
/** INSERT
|
|
31
|
+
/** INSERT Type inference (autoIncrement excluded, nullable/default are optional) */
|
|
32
32
|
$inferInsert;
|
|
33
|
-
/** UPDATE
|
|
33
|
+
/** UPDATE Type inference (all fields optional) */
|
|
34
34
|
$inferUpdate;
|
|
35
35
|
/**
|
|
36
36
|
* Table set description
|
|
37
37
|
*
|
|
38
|
-
* @param desc - Table description (DDL Comment
|
|
38
|
+
* @param desc - Table description (used as DDL Comment)
|
|
39
39
|
* @returns new TableBuilder instance
|
|
40
40
|
*/
|
|
41
41
|
description(desc) {
|
|
@@ -44,7 +44,7 @@ class TableBuilder {
|
|
|
44
44
|
/**
|
|
45
45
|
* Database set name
|
|
46
46
|
*
|
|
47
|
-
* @param db - Database
|
|
47
|
+
* @param db - Database name
|
|
48
48
|
* @returns new TableBuilder instance
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
@@ -58,9 +58,9 @@ class TableBuilder {
|
|
|
58
58
|
/**
|
|
59
59
|
* schema set name
|
|
60
60
|
*
|
|
61
|
-
* MSSQL,
|
|
61
|
+
* Used in MSSQL, PostgreSQL
|
|
62
62
|
*
|
|
63
|
-
* @param schema - Schema
|
|
63
|
+
* @param schema - Schema name (MSSQL: dbo, PostgreSQL: public)
|
|
64
64
|
* @returns new TableBuilder instance
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
@@ -76,10 +76,10 @@ class TableBuilder {
|
|
|
76
76
|
/**
|
|
77
77
|
* Column definition
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* Type-safe Column definition through column factory
|
|
80
80
|
*
|
|
81
|
-
* @template TNewColumnDefs -
|
|
82
|
-
* @param fn - Column factory
|
|
81
|
+
* @template TNewColumnDefs - New Column definition type
|
|
82
|
+
* @param fn - Function that receives a Column factory and returns Column definitions
|
|
83
83
|
* @returns new TableBuilder instance
|
|
84
84
|
*
|
|
85
85
|
* @example
|
|
@@ -100,19 +100,19 @@ class TableBuilder {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
* Primary Key
|
|
103
|
+
* Primary Key configuration
|
|
104
104
|
*
|
|
105
|
-
* @param columns -
|
|
105
|
+
* @param columns - Column names composing the PK (composite PK supported)
|
|
106
106
|
* @returns new TableBuilder instance
|
|
107
107
|
*
|
|
108
108
|
* @example
|
|
109
109
|
* ```typescript
|
|
110
|
-
* //
|
|
110
|
+
* // Single PK
|
|
111
111
|
* const User = Table("User")
|
|
112
112
|
* .columns((c) => ({ id: c.bigint() }))
|
|
113
113
|
* .primaryKey("id");
|
|
114
114
|
*
|
|
115
|
-
* //
|
|
115
|
+
* // Composite PK
|
|
116
116
|
* const UserRole = Table("UserRole")
|
|
117
117
|
* .columns((c) => ({
|
|
118
118
|
* userId: c.bigint(),
|
|
@@ -130,7 +130,7 @@ class TableBuilder {
|
|
|
130
130
|
/**
|
|
131
131
|
* Index definition
|
|
132
132
|
*
|
|
133
|
-
* @param fn - Index factory
|
|
133
|
+
* @param fn - Function that receives an Index factory and returns an Index array
|
|
134
134
|
* @returns new TableBuilder instance
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
@@ -154,12 +154,12 @@ class TableBuilder {
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Relation definition
|
|
158
158
|
*
|
|
159
|
-
* FK,
|
|
159
|
+
* Set up FK, reverse-references, and other inter-Table relations
|
|
160
160
|
*
|
|
161
|
-
* @template T -
|
|
162
|
-
* @param fn -
|
|
161
|
+
* @template T - Relation definition type
|
|
162
|
+
* @param fn - Function that receives a relation factory and returns relation definitions
|
|
163
163
|
* @returns new TableBuilder instance
|
|
164
164
|
*
|
|
165
165
|
* @example
|
|
@@ -172,7 +172,7 @@ class TableBuilder {
|
|
|
172
172
|
* }))
|
|
173
173
|
* .primaryKey("id")
|
|
174
174
|
* .relations((r) => ({
|
|
175
|
-
* // FK
|
|
175
|
+
* // FK relation (N:1)
|
|
176
176
|
* author: r.foreignKey(["authorId"], () => User),
|
|
177
177
|
* }));
|
|
178
178
|
*
|
|
@@ -183,13 +183,13 @@ class TableBuilder {
|
|
|
183
183
|
* }))
|
|
184
184
|
* .primaryKey("id")
|
|
185
185
|
* .relations((r) => ({
|
|
186
|
-
* //
|
|
186
|
+
* // Reverse-reference (1:N)
|
|
187
187
|
* posts: r.foreignKeyTarget(() => Post, "author"),
|
|
188
188
|
* }));
|
|
189
189
|
* ```
|
|
190
190
|
*
|
|
191
191
|
* @see {@link ForeignKeyBuilder} FK builder
|
|
192
|
-
* @see {@link ForeignKeyTargetBuilder} FK
|
|
192
|
+
* @see {@link ForeignKeyTargetBuilder} FK reverse-reference builder
|
|
193
193
|
*/
|
|
194
194
|
relations(fn) {
|
|
195
195
|
return new TableBuilder({
|