@simplysm/orm-common 14.0.100 → 14.0.102
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/db-context.d.ts +0 -17
- package/dist/db-context.d.ts.map +1 -1
- package/dist/db-context.js +0 -17
- package/dist/db-context.js.map +1 -1
- package/dist/errors/db-transaction-error.d.ts +0 -15
- package/dist/errors/db-transaction-error.d.ts.map +1 -1
- package/dist/errors/db-transaction-error.js +0 -15
- package/dist/errors/db-transaction-error.js.map +1 -1
- package/dist/exec/executable.d.ts +0 -24
- package/dist/exec/executable.d.ts.map +1 -1
- package/dist/exec/executable.js +0 -24
- package/dist/exec/executable.js.map +1 -1
- package/dist/exec/queryable.d.ts +0 -300
- package/dist/exec/queryable.d.ts.map +1 -1
- package/dist/exec/queryable.js +0 -213
- package/dist/exec/queryable.js.map +1 -1
- package/dist/expr/expr.d.ts +0 -689
- package/dist/expr/expr.d.ts.map +1 -1
- package/dist/expr/expr.js +0 -689
- package/dist/expr/expr.js.map +1 -1
- package/dist/schema/factory/column-builder.d.ts +0 -86
- package/dist/schema/factory/column-builder.d.ts.map +1 -1
- package/dist/schema/factory/column-builder.js +0 -74
- package/dist/schema/factory/column-builder.js.map +1 -1
- package/dist/schema/factory/index-builder.d.ts +0 -60
- package/dist/schema/factory/index-builder.d.ts.map +1 -1
- package/dist/schema/factory/index-builder.js +0 -60
- package/dist/schema/factory/index-builder.js.map +1 -1
- package/dist/schema/factory/relation-builder.d.ts +0 -83
- package/dist/schema/factory/relation-builder.d.ts.map +1 -1
- package/dist/schema/factory/relation-builder.js +0 -77
- package/dist/schema/factory/relation-builder.js.map +1 -1
- package/dist/schema/procedure-builder.d.ts +0 -87
- package/dist/schema/procedure-builder.d.ts.map +1 -1
- package/dist/schema/procedure-builder.js +0 -87
- package/dist/schema/procedure-builder.js.map +1 -1
- package/dist/schema/table-builder.d.ts +0 -127
- package/dist/schema/table-builder.d.ts.map +1 -1
- package/dist/schema/table-builder.js +0 -127
- package/dist/schema/table-builder.js.map +1 -1
- package/dist/schema/view-builder.d.ts +0 -76
- package/dist/schema/view-builder.d.ts.map +1 -1
- package/dist/schema/view-builder.js +0 -76
- package/dist/schema/view-builder.js.map +1 -1
- package/dist/types/column.d.ts +0 -38
- package/dist/types/column.d.ts.map +1 -1
- package/dist/types/column.js +0 -13
- package/dist/types/column.js.map +1 -1
- package/dist/types/db.d.ts +0 -54
- package/dist/types/db.d.ts.map +1 -1
- package/dist/types/db.js +0 -8
- package/dist/types/db.js.map +1 -1
- package/dist/utils/result-parser.d.ts +0 -21
- package/dist/utils/result-parser.d.ts.map +1 -1
- package/dist/utils/result-parser.js +0 -24
- package/dist/utils/result-parser.js.map +1 -1
- package/package.json +2 -2
- package/src/db-context.ts +0 -17
- package/src/errors/db-transaction-error.ts +0 -15
- package/src/exec/executable.ts +0 -24
- package/src/exec/queryable.ts +0 -300
- package/src/expr/expr.ts +0 -689
- package/src/schema/factory/column-builder.ts +0 -86
- package/src/schema/factory/index-builder.ts +0 -60
- package/src/schema/factory/relation-builder.ts +0 -83
- package/src/schema/procedure-builder.ts +0 -87
- package/src/schema/table-builder.ts +0 -127
- package/src/schema/view-builder.ts +0 -76
- package/src/types/column.ts +0 -38
- package/src/types/db.ts +0 -54
- package/src/utils/result-parser.ts +0 -24
|
@@ -16,18 +16,6 @@ import type { DataRecord } from "../../types/db";
|
|
|
16
16
|
* @template TValue - Column 값 타입
|
|
17
17
|
* @template TMeta - Column 메타데이터 타입
|
|
18
18
|
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* Table("User")
|
|
22
|
-
* .columns((c) => ({
|
|
23
|
-
* id: c.bigint().autoIncrement(), // bigint, 자동 증가
|
|
24
|
-
* name: c.varchar(100), // varchar(100), 필수
|
|
25
|
-
* email: c.varchar(200).nullable(), // varchar(200), nullable
|
|
26
|
-
* status: c.varchar(20).default("active"), // varchar(20), 기본값
|
|
27
|
-
* createdAt: c.datetime().description("created datetime"),
|
|
28
|
-
* }));
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
19
|
* @see {@link createColumnFactory} column factory
|
|
32
20
|
* @see {@link TableBuilder} Table builder
|
|
33
21
|
*/
|
|
@@ -43,11 +31,6 @@ export class ColumnBuilder<TValue extends ColumnPrimitive, TMeta extends ColumnM
|
|
|
43
31
|
* INSERT 시 자동 증가. INSERT 타입 추론에서 선택적(optional)으로 처리됨
|
|
44
32
|
*
|
|
45
33
|
* @returns 새 ColumnBuilder 인스턴스
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* id: c.bigint().autoIncrement()
|
|
50
|
-
* ```
|
|
51
34
|
*/
|
|
52
35
|
autoIncrement(): ColumnBuilder<TValue, Omit<TMeta, "autoIncrement"> & { autoIncrement: true }> {
|
|
53
36
|
return new ColumnBuilder({ ...this.meta, autoIncrement: true });
|
|
@@ -59,11 +42,6 @@ export class ColumnBuilder<TValue extends ColumnPrimitive, TMeta extends ColumnM
|
|
|
59
42
|
* NULL 허용. 값 타입에 undefined가 추가됨
|
|
60
43
|
*
|
|
61
44
|
* @returns 새 ColumnBuilder 인스턴스
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* email: c.varchar(200).nullable() // string | undefined
|
|
66
|
-
* ```
|
|
67
45
|
*/
|
|
68
46
|
nullable(): ColumnBuilder<TValue | undefined, Omit<TMeta, "nullable"> & { nullable: true }> {
|
|
69
47
|
return new ColumnBuilder({ ...this.meta, nullable: true });
|
|
@@ -76,12 +54,6 @@ export class ColumnBuilder<TValue extends ColumnPrimitive, TMeta extends ColumnM
|
|
|
76
54
|
*
|
|
77
55
|
* @param value - 기본값
|
|
78
56
|
* @returns 새 ColumnBuilder 인스턴스
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* status: c.varchar(20).default("active")
|
|
83
|
-
* createdAt: c.datetime().default("CURRENT_TIMESTAMP")
|
|
84
|
-
* ```
|
|
85
57
|
*/
|
|
86
58
|
default(
|
|
87
59
|
value: TValue,
|
|
@@ -94,11 +66,6 @@ export class ColumnBuilder<TValue extends ColumnPrimitive, TMeta extends ColumnM
|
|
|
94
66
|
*
|
|
95
67
|
* @param desc - Column 설명 (DDL Comment로 사용됨)
|
|
96
68
|
* @returns 새 ColumnBuilder 인스턴스
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* createdAt: c.datetime().description("record creation datetime")
|
|
101
|
-
* ```
|
|
102
69
|
*/
|
|
103
70
|
description(desc: string): ColumnBuilder<TValue, TMeta & { description: string }> {
|
|
104
71
|
return new ColumnBuilder({ ...this.meta, description: desc });
|
|
@@ -117,32 +84,6 @@ export class ColumnBuilder<TValue extends ColumnPrimitive, TMeta extends ColumnM
|
|
|
117
84
|
*
|
|
118
85
|
* @returns 각 Column 타입별 builder 생성 메서드를 포함하는 객체
|
|
119
86
|
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* Table("User")
|
|
123
|
-
* .columns((c) => ({
|
|
124
|
-
* // 숫자 타입
|
|
125
|
-
* id: c.bigint().autoIncrement(),
|
|
126
|
-
* count: c.int(),
|
|
127
|
-
* price: c.decimal(10, 2),
|
|
128
|
-
*
|
|
129
|
-
* // 문자열 타입
|
|
130
|
-
* name: c.varchar(100),
|
|
131
|
-
* code: c.char(10),
|
|
132
|
-
* content: c.text(),
|
|
133
|
-
*
|
|
134
|
-
* // 날짜/시간 타입
|
|
135
|
-
* createdAt: c.datetime(),
|
|
136
|
-
* birthDate: c.date(),
|
|
137
|
-
* startTime: c.time(),
|
|
138
|
-
*
|
|
139
|
-
* // 기타 타입
|
|
140
|
-
* isActive: c.boolean(),
|
|
141
|
-
* data: c.binary(),
|
|
142
|
-
* uuid: c.uuid(),
|
|
143
|
-
* }));
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
87
|
* @see {@link ColumnBuilder} Column builder 클래스
|
|
147
88
|
*/
|
|
148
89
|
export function createColumnFactory() {
|
|
@@ -189,11 +130,6 @@ export function createColumnFactory() {
|
|
|
189
130
|
* @param precision - 전체 자릿수
|
|
190
131
|
* @param scale - 소수점 이하 자릿수 (선택)
|
|
191
132
|
* @returns ColumnBuilder 인스턴스
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* price: c.decimal(10, 2) // DECIMAL(10, 2)
|
|
196
|
-
* ```
|
|
197
133
|
*/
|
|
198
134
|
decimal(
|
|
199
135
|
precision: number,
|
|
@@ -210,11 +146,6 @@ export function createColumnFactory() {
|
|
|
210
146
|
*
|
|
211
147
|
* @param length - 최대 길이
|
|
212
148
|
* @returns ColumnBuilder 인스턴스
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```typescript
|
|
216
|
-
* name: c.varchar(100) // VARCHAR(100)
|
|
217
|
-
* ```
|
|
218
149
|
*/
|
|
219
150
|
varchar(
|
|
220
151
|
length: number,
|
|
@@ -227,11 +158,6 @@ export function createColumnFactory() {
|
|
|
227
158
|
*
|
|
228
159
|
* @param length - 고정 길이
|
|
229
160
|
* @returns ColumnBuilder 인스턴스
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```typescript
|
|
233
|
-
* countryCode: c.char(2) // CHAR(2)
|
|
234
|
-
* ```
|
|
235
161
|
*/
|
|
236
162
|
char(
|
|
237
163
|
length: number,
|
|
@@ -329,12 +255,6 @@ export type ColumnBuilderRecord = Record<string, ColumnBuilder<ColumnPrimitive,
|
|
|
329
255
|
* Column builder 레코드에서 실제 값 타입을 추론
|
|
330
256
|
*
|
|
331
257
|
* @template T - Column builder 레코드 타입
|
|
332
|
-
*
|
|
333
|
-
* @example
|
|
334
|
-
* ```typescript
|
|
335
|
-
* type UserColumns = InferColumns<typeof User.$columns>;
|
|
336
|
-
* // { id: number; name: string; email: string | undefined; }
|
|
337
|
-
* ```
|
|
338
258
|
*/
|
|
339
259
|
export type InferColumns<TBuilders extends ColumnBuilderRecord> = {
|
|
340
260
|
[K in keyof TBuilders]: TBuilders[K] extends ColumnBuilder<infer V, any> ? V : never;
|
|
@@ -386,12 +306,6 @@ export type OptionalInsertKeys<TBuilders extends ColumnBuilderRecord> = Exclude<
|
|
|
386
306
|
* 필수 column은 필수, 선택적 column은 Partial
|
|
387
307
|
*
|
|
388
308
|
* @template T - Column builder 레코드 타입
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* type UserInsert = InferInsertColumns<typeof User.$columns>;
|
|
393
|
-
* // { name: string; } & { id?: number; email?: string; status?: string; }
|
|
394
|
-
* ```
|
|
395
309
|
*/
|
|
396
310
|
export type InferInsertColumns<TBuilders extends ColumnBuilderRecord> = Pick<
|
|
397
311
|
InferColumns<TBuilders>,
|
|
@@ -10,27 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @template TKeys - Index column key 배열 타입
|
|
12
12
|
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* Table("User")
|
|
16
|
-
* .columns((c) => ({
|
|
17
|
-
* id: c.bigint(),
|
|
18
|
-
* email: c.varchar(200),
|
|
19
|
-
* name: c.varchar(100),
|
|
20
|
-
* createdAt: c.datetime(),
|
|
21
|
-
* }))
|
|
22
|
-
* .indexes((i) => [
|
|
23
|
-
* // 유니크 index
|
|
24
|
-
* i.index("email").unique(),
|
|
25
|
-
*
|
|
26
|
-
* // 복합 index + 정렬 순서
|
|
27
|
-
* i.index("name", "createdAt").orderBy("ASC", "DESC"),
|
|
28
|
-
*
|
|
29
|
-
* // 커스텀 이름
|
|
30
|
-
* i.index("createdAt").name("IX_User_CreatedAt"),
|
|
31
|
-
* ]);
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
13
|
* @see {@link createIndexFactory} Index factory
|
|
35
14
|
* @see {@link TableBuilder} Table builder
|
|
36
15
|
*/
|
|
@@ -58,11 +37,6 @@ export class IndexBuilder<TKeys extends string[]> {
|
|
|
58
37
|
*
|
|
59
38
|
* @param name - Index 이름
|
|
60
39
|
* @returns 새 IndexBuilder 인스턴스
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* i.index("email").name("IX_User_Email")
|
|
65
|
-
* ```
|
|
66
40
|
*/
|
|
67
41
|
name(name: string): IndexBuilder<TKeys> {
|
|
68
42
|
return new IndexBuilder({ ...this.meta, name });
|
|
@@ -72,11 +46,6 @@ export class IndexBuilder<TKeys extends string[]> {
|
|
|
72
46
|
* 유니크 index 설정
|
|
73
47
|
*
|
|
74
48
|
* @returns 새 IndexBuilder 인스턴스
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* i.index("email").unique()
|
|
79
|
-
* ```
|
|
80
49
|
*/
|
|
81
50
|
unique(): IndexBuilder<TKeys> {
|
|
82
51
|
return new IndexBuilder({ ...this.meta, unique: true });
|
|
@@ -89,15 +58,6 @@ export class IndexBuilder<TKeys extends string[]> {
|
|
|
89
58
|
*
|
|
90
59
|
* @param orderBy - column별 정렬 순서 (column 수와 일치해야 함)
|
|
91
60
|
* @returns 새 IndexBuilder 인스턴스
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* // 단일 column
|
|
96
|
-
* i.index("createdAt").orderBy("DESC")
|
|
97
|
-
*
|
|
98
|
-
* // 복합 column
|
|
99
|
-
* i.index("status", "createdAt").orderBy("ASC", "DESC")
|
|
100
|
-
* ```
|
|
101
61
|
*/
|
|
102
62
|
orderBy(...orderBy: { [K in keyof TKeys]: "ASC" | "DESC" }): IndexBuilder<TKeys> {
|
|
103
63
|
return new IndexBuilder({ ...this.meta, orderBy });
|
|
@@ -126,20 +86,6 @@ export class IndexBuilder<TKeys extends string[]> {
|
|
|
126
86
|
* @template TColumnKey - Table column key 타입
|
|
127
87
|
* @returns Index 생성 메서드를 포함하는 객체
|
|
128
88
|
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* Table("User")
|
|
132
|
-
* .columns((c) => ({
|
|
133
|
-
* id: c.bigint(),
|
|
134
|
-
* email: c.varchar(200),
|
|
135
|
-
* name: c.varchar(100),
|
|
136
|
-
* }))
|
|
137
|
-
* .indexes((i) => [
|
|
138
|
-
* i.index("email").unique(),
|
|
139
|
-
* i.index("name"),
|
|
140
|
-
* ]);
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
89
|
* @see {@link IndexBuilder} Index builder 클래스
|
|
144
90
|
*/
|
|
145
91
|
export function createIndexFactory<TColumnKey extends string>() {
|
|
@@ -150,12 +96,6 @@ export function createIndexFactory<TColumnKey extends string>() {
|
|
|
150
96
|
* @template TKeys - Index column key 배열 타입
|
|
151
97
|
* @param columns - Index column 이름들
|
|
152
98
|
* @returns IndexBuilder 인스턴스
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* i.index("email") // 단일 column
|
|
157
|
-
* i.index("name", "email") // 복합 column
|
|
158
|
-
* ```
|
|
159
99
|
*/
|
|
160
100
|
index<TKeys extends TColumnKey[]>(...columns: [...TKeys]): IndexBuilder<TKeys> {
|
|
161
101
|
return new IndexBuilder({ columns });
|
|
@@ -18,20 +18,6 @@ import type { ViewBuilder } from "../view-builder";
|
|
|
18
18
|
* @template TOwner - 소유 Table builder 타입
|
|
19
19
|
* @template TTargetFn - 대상 Table builder factory 타입
|
|
20
20
|
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const Post = Table("Post")
|
|
24
|
-
* .columns((c) => ({
|
|
25
|
-
* id: c.bigint().autoIncrement(),
|
|
26
|
-
* authorId: c.bigint(), // FK column
|
|
27
|
-
* }))
|
|
28
|
-
* .primaryKey("id")
|
|
29
|
-
* .relations((r) => ({
|
|
30
|
-
* // N:1 relationship - Post → User
|
|
31
|
-
* author: r.foreignKey(["authorId"], () => User, { description: "작성자" }),
|
|
32
|
-
* }));
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
21
|
* @see {@link ForeignKeyTargetBuilder} 역참조 builder
|
|
36
22
|
* @see {@link RelationKeyBuilder} DB FK 없는 관계
|
|
37
23
|
*/
|
|
@@ -68,26 +54,6 @@ export class ForeignKeyBuilder<
|
|
|
68
54
|
* @template TTargetTableFn - 참조하는 Table builder factory 타입
|
|
69
55
|
* @template TIsSingle - 단일 객체 여부
|
|
70
56
|
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const User = Table("User")
|
|
74
|
-
* .columns((c) => ({
|
|
75
|
-
* id: c.bigint().autoIncrement(),
|
|
76
|
-
* name: c.varchar(100),
|
|
77
|
-
* }))
|
|
78
|
-
* .primaryKey("id")
|
|
79
|
-
* .relations((r) => ({
|
|
80
|
-
* // 1:N relationship - User ← Post.author
|
|
81
|
-
* posts: r.foreignKeyTarget(() => Post, "author"),
|
|
82
|
-
*
|
|
83
|
-
* // 1:1 relation (single object)
|
|
84
|
-
* profile: r.foreignKeyTarget(() => Profile, "user", { single: true }),
|
|
85
|
-
*
|
|
86
|
-
* // with description
|
|
87
|
-
* comments: r.foreignKeyTarget(() => Comment, "user", { description: "댓글목록" }),
|
|
88
|
-
* }));
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
57
|
* @see {@link ForeignKeyBuilder} FK builder
|
|
92
58
|
*/
|
|
93
59
|
export class ForeignKeyTargetBuilder<
|
|
@@ -126,17 +92,6 @@ export class ForeignKeyTargetBuilder<
|
|
|
126
92
|
* @template TOwner - 소유 Table/View builder 타입
|
|
127
93
|
* @template TTargetFn - 대상 Table/View builder factory 타입
|
|
128
94
|
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* // View에서 Table로의 관계 정의
|
|
132
|
-
* const UserSummary = View("UserSummary")
|
|
133
|
-
* .query((db: MyDb) => db.user().select(...))
|
|
134
|
-
* .relations((r) => ({
|
|
135
|
-
* // View → Table (FK 미생성)
|
|
136
|
-
* company: r.relationKey(["companyId"], () => Company, { description: "소속회사" }),
|
|
137
|
-
* }));
|
|
138
|
-
* ```
|
|
139
|
-
*
|
|
140
95
|
* @see {@link ForeignKeyBuilder} DB FK 생성 버전
|
|
141
96
|
*/
|
|
142
97
|
export class RelationKeyBuilder<
|
|
@@ -171,18 +126,6 @@ export class RelationKeyBuilder<
|
|
|
171
126
|
* @template TTargetTableFn - 참조하는 Table/View builder factory 타입
|
|
172
127
|
* @template TIsSingle - 단일 객체 여부
|
|
173
128
|
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* const Company = Table("Company")
|
|
177
|
-
* .columns((c) => ({ id: c.bigint() }))
|
|
178
|
-
* .relations((r) => ({
|
|
179
|
-
* // 역참조 (FK 미생성)
|
|
180
|
-
* employees: r.relationKeyTarget(() => UserSummary, "company"),
|
|
181
|
-
* // 단일 객체 + 설명
|
|
182
|
-
* ceo: r.relationKeyTarget(() => UserSummary, "company", { single: true, description: "대표" }),
|
|
183
|
-
* }));
|
|
184
|
-
* ```
|
|
185
|
-
*
|
|
186
129
|
* @see {@link ForeignKeyTargetBuilder} DB FK 생성 버전
|
|
187
130
|
*/
|
|
188
131
|
export class RelationKeyTargetBuilder<
|
|
@@ -275,26 +218,6 @@ type RelationRkFactory<
|
|
|
275
218
|
* @template TColumnKey - Column key 타입
|
|
276
219
|
* @param ownerFn - 소유 Table/View factory 함수
|
|
277
220
|
* @returns 관계 builder factory
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* // Table - FK와 RelationKey 모두 사용 가능
|
|
282
|
-
* const Post = Table("Post")
|
|
283
|
-
* .columns((c) => ({
|
|
284
|
-
* id: c.bigint(),
|
|
285
|
-
* authorId: c.bigint(),
|
|
286
|
-
* }))
|
|
287
|
-
* .relations((r) => ({
|
|
288
|
-
* author: r.foreignKey(["authorId"], () => User), // FK 생성
|
|
289
|
-
* }));
|
|
290
|
-
*
|
|
291
|
-
* // View - RelationKey만 사용 가능
|
|
292
|
-
* const UserSummary = View("UserSummary")
|
|
293
|
-
* .query(...)
|
|
294
|
-
* .relations((r) => ({
|
|
295
|
-
* posts: r.relationKeyTarget(() => Post, "author"), // FK 미생성
|
|
296
|
-
* }));
|
|
297
|
-
* ```
|
|
298
221
|
*/
|
|
299
222
|
export function createRelationFactory<
|
|
300
223
|
TOwner extends TableBuilder<any, any, any> | ViewBuilder<any, any, any>,
|
|
@@ -415,12 +338,6 @@ export type ExtractRelationTargetResult<TRelation, TVisited extends string = nev
|
|
|
415
338
|
* include() 없이 접근 시 undefined가 되도록 모든 관계를 optional로 설정
|
|
416
339
|
*
|
|
417
340
|
* @template TRelations - 관계 builder 레코드 타입
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```typescript
|
|
421
|
-
* type UserRelations = InferDeepRelations<typeof User.$relations>;
|
|
422
|
-
* // { posts?: Post[]; profile?: Profile; }
|
|
423
|
-
* ```
|
|
424
341
|
*/
|
|
425
342
|
export type InferDeepRelations<TRelations extends RelationBuilderRecord, TVisited extends string = never> = {
|
|
426
343
|
[K in keyof TRelations]?:
|
|
@@ -13,30 +13,6 @@ import { type ColumnBuilderRecord, createColumnFactory } from "./factory/column-
|
|
|
13
13
|
* @template TParams - 파라미터 Column 정의 타입
|
|
14
14
|
* @template TReturns - 반환 Column 정의 타입
|
|
15
15
|
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Procedure definition
|
|
19
|
-
* const GetUserById = Procedure("GetUserById")
|
|
20
|
-
* .database("mydb")
|
|
21
|
-
* .params((c) => ({
|
|
22
|
-
* userId: c.bigint(),
|
|
23
|
-
* }))
|
|
24
|
-
* .returns((c) => ({
|
|
25
|
-
* id: c.bigint(),
|
|
26
|
-
* name: c.varchar(100),
|
|
27
|
-
* email: c.varchar(200),
|
|
28
|
-
* }))
|
|
29
|
-
* .body("SELECT id, name, email FROM User WHERE id = userId");
|
|
30
|
-
*
|
|
31
|
-
* // Used in DbContext
|
|
32
|
-
* class MyDb extends DbContext {
|
|
33
|
-
* readonly getUserById = executable(this, GetUserById);
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* // Invocation
|
|
37
|
-
* const users = await db.getUserById({ userId: 1n }).execute();
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
16
|
* @see {@link Procedure} factory 함수
|
|
41
17
|
* @see {@link executable} Executable 생성
|
|
42
18
|
*/
|
|
@@ -86,11 +62,6 @@ export class ProcedureBuilder<
|
|
|
86
62
|
*
|
|
87
63
|
* @param db - Database 이름
|
|
88
64
|
* @returns 새 ProcedureBuilder 인스턴스
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const GetUser = Procedure("GetUser").database("mydb");
|
|
93
|
-
* ```
|
|
94
65
|
*/
|
|
95
66
|
database(db: string): ProcedureBuilder<TParams, TReturns> {
|
|
96
67
|
return new ProcedureBuilder({ ...this.meta, database: db });
|
|
@@ -117,15 +88,6 @@ export class ProcedureBuilder<
|
|
|
117
88
|
* @template T - 새 파라미터 정의 타입
|
|
118
89
|
* @param fn - Column factory를 받아 파라미터 정의를 반환하는 함수
|
|
119
90
|
* @returns 새 ProcedureBuilder 인스턴스
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
* const GetUserById = Procedure("GetUserById")
|
|
124
|
-
* .params((c) => ({
|
|
125
|
-
* userId: c.bigint(),
|
|
126
|
-
* includeDeleted: c.boolean().default(false),
|
|
127
|
-
* }));
|
|
128
|
-
* ```
|
|
129
91
|
*/
|
|
130
92
|
params<T extends ColumnBuilderRecord>(
|
|
131
93
|
fn: (c: ReturnType<typeof createColumnFactory>) => T,
|
|
@@ -141,17 +103,6 @@ export class ProcedureBuilder<
|
|
|
141
103
|
* @template T - 새 반환 타입 정의
|
|
142
104
|
* @param fn - Column factory를 받아 column 정의를 반환하는 함수
|
|
143
105
|
* @returns 새 ProcedureBuilder 인스턴스
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* const GetUserById = Procedure("GetUserById")
|
|
148
|
-
* .params((c) => ({ userId: c.bigint() }))
|
|
149
|
-
* .returns((c) => ({
|
|
150
|
-
* id: c.bigint(),
|
|
151
|
-
* name: c.varchar(100),
|
|
152
|
-
* email: c.varchar(200).nullable(),
|
|
153
|
-
* }));
|
|
154
|
-
* ```
|
|
155
106
|
*/
|
|
156
107
|
returns<T extends ColumnBuilderRecord>(
|
|
157
108
|
fn: (c: ReturnType<typeof createColumnFactory>) => T,
|
|
@@ -169,19 +120,6 @@ export class ProcedureBuilder<
|
|
|
169
120
|
*
|
|
170
121
|
* @param sql - Procedure 본문 SQL
|
|
171
122
|
* @returns 새 ProcedureBuilder 인스턴스
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* // MySQL/PostgreSQL
|
|
176
|
-
* const GetUser = Procedure("GetUser")
|
|
177
|
-
* .params((c) => ({ userId: c.bigint() }))
|
|
178
|
-
* .body("SELECT * FROM User WHERE id = userId");
|
|
179
|
-
*
|
|
180
|
-
* // MSSQL
|
|
181
|
-
* const GetUser = Procedure("GetUser")
|
|
182
|
-
* .params((c) => ({ userId: c.bigint() }))
|
|
183
|
-
* .body("SELECT * FROM [User] WHERE id = @userId");
|
|
184
|
-
* ```
|
|
185
123
|
*/
|
|
186
124
|
body(sql: string): ProcedureBuilder<TParams, TReturns> {
|
|
187
125
|
return new ProcedureBuilder({ ...this.meta, query: sql });
|
|
@@ -200,31 +138,6 @@ export class ProcedureBuilder<
|
|
|
200
138
|
* @param name - Procedure 이름
|
|
201
139
|
* @returns ProcedureBuilder 인스턴스
|
|
202
140
|
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```typescript
|
|
205
|
-
* // Basic usage
|
|
206
|
-
* const GetUserById = Procedure("GetUserById")
|
|
207
|
-
* .database("mydb")
|
|
208
|
-
* .params((c) => ({
|
|
209
|
-
* userId: c.bigint(),
|
|
210
|
-
* }))
|
|
211
|
-
* .returns((c) => ({
|
|
212
|
-
* id: c.bigint(),
|
|
213
|
-
* name: c.varchar(100),
|
|
214
|
-
* email: c.varchar(200),
|
|
215
|
-
* }))
|
|
216
|
-
* .body("SELECT id, name, email FROM User WHERE id = userId");
|
|
217
|
-
*
|
|
218
|
-
* // 파라미터 없는 Procedure
|
|
219
|
-
* const GetAllActiveUsers = Procedure("GetAllActiveUsers")
|
|
220
|
-
* .database("mydb")
|
|
221
|
-
* .returns((c) => ({
|
|
222
|
-
* id: c.bigint(),
|
|
223
|
-
* name: c.varchar(100),
|
|
224
|
-
* }))
|
|
225
|
-
* .body("SELECT id, name FROM User WHERE status = 'active'");
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
141
|
* @see {@link ProcedureBuilder} builder 클래스
|
|
229
142
|
*/
|
|
230
143
|
export function Procedure(name: string): ProcedureBuilder<never, never> {
|
|
@@ -25,26 +25,6 @@ import {
|
|
|
25
25
|
* @template TColumns - Column 정의 레코드 타입
|
|
26
26
|
* @template TRelations - 관계 정의 레코드 타입
|
|
27
27
|
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* // Table definition
|
|
31
|
-
* const User = Table("User")
|
|
32
|
-
* .database("mydb")
|
|
33
|
-
* .columns((c) => ({
|
|
34
|
-
* id: c.bigint().autoIncrement(),
|
|
35
|
-
* name: c.varchar(100),
|
|
36
|
-
* email: c.varchar(200).nullable(),
|
|
37
|
-
* status: c.varchar(20).default("active"),
|
|
38
|
-
* }))
|
|
39
|
-
* .primaryKey("id")
|
|
40
|
-
* .indexes((i) => [i.index("email").unique()]);
|
|
41
|
-
*
|
|
42
|
-
* // Used in DbContext
|
|
43
|
-
* class MyDb extends DbContext {
|
|
44
|
-
* readonly user = queryable(this, User);
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
28
|
* @see {@link Table} factory 함수
|
|
49
29
|
* @see {@link queryable} Queryable 생성
|
|
50
30
|
*/
|
|
@@ -107,11 +87,6 @@ export class TableBuilder<
|
|
|
107
87
|
*
|
|
108
88
|
* @param db - Database 이름
|
|
109
89
|
* @returns 새 TableBuilder 인스턴스
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const User = Table("User").database("mydb");
|
|
114
|
-
* ```
|
|
115
90
|
*/
|
|
116
91
|
database(db: string): TableBuilder<TName, TColumns, TRelations> {
|
|
117
92
|
return new TableBuilder({ ...this.meta, database: db });
|
|
@@ -124,13 +99,6 @@ export class TableBuilder<
|
|
|
124
99
|
*
|
|
125
100
|
* @param schema - Schema 이름 (MSSQL: dbo, PostgreSQL: public)
|
|
126
101
|
* @returns 새 TableBuilder 인스턴스
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* const User = Table("User")
|
|
131
|
-
* .database("mydb")
|
|
132
|
-
* .schema("custom_schema");
|
|
133
|
-
* ```
|
|
134
102
|
*/
|
|
135
103
|
schema(schema: string): TableBuilder<TName, TColumns, TRelations> {
|
|
136
104
|
return new TableBuilder({ ...this.meta, schema });
|
|
@@ -144,17 +112,6 @@ export class TableBuilder<
|
|
|
144
112
|
* @template TNewColumnDefs - 새 Column 정의 타입
|
|
145
113
|
* @param fn - Column factory를 받아 column 정의를 반환하는 함수
|
|
146
114
|
* @returns 새 TableBuilder 인스턴스
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* const User = Table("User")
|
|
151
|
-
* .columns((c) => ({
|
|
152
|
-
* id: c.bigint().autoIncrement(),
|
|
153
|
-
* name: c.varchar(100),
|
|
154
|
-
* email: c.varchar(200).nullable(),
|
|
155
|
-
* createdAt: c.datetime().default("CURRENT_TIMESTAMP"),
|
|
156
|
-
* }));
|
|
157
|
-
* ```
|
|
158
115
|
*/
|
|
159
116
|
columns<TNewColumnDefs extends ColumnBuilderRecord>(
|
|
160
117
|
fn: (c: ReturnType<typeof createColumnFactory>) => TNewColumnDefs,
|
|
@@ -170,22 +127,6 @@ export class TableBuilder<
|
|
|
170
127
|
*
|
|
171
128
|
* @param columns - PK를 구성하는 column 이름 (복합 PK 지원)
|
|
172
129
|
* @returns 새 TableBuilder 인스턴스
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* // 단일 PK
|
|
177
|
-
* const User = Table("User")
|
|
178
|
-
* .columns((c) => ({ id: c.bigint() }))
|
|
179
|
-
* .primaryKey("id");
|
|
180
|
-
*
|
|
181
|
-
* // 복합 PK
|
|
182
|
-
* const UserRole = Table("UserRole")
|
|
183
|
-
* .columns((c) => ({
|
|
184
|
-
* userId: c.bigint(),
|
|
185
|
-
* roleId: c.bigint(),
|
|
186
|
-
* }))
|
|
187
|
-
* .primaryKey("userId", "roleId");
|
|
188
|
-
* ```
|
|
189
130
|
*/
|
|
190
131
|
primaryKey(...columns: (keyof TColumns & string)[]): TableBuilder<TName, TColumns, TRelations> {
|
|
191
132
|
return new TableBuilder({
|
|
@@ -199,20 +140,6 @@ export class TableBuilder<
|
|
|
199
140
|
*
|
|
200
141
|
* @param fn - Index factory를 받아 index 배열을 반환하는 함수
|
|
201
142
|
* @returns 새 TableBuilder 인스턴스
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```typescript
|
|
205
|
-
* const User = Table("User")
|
|
206
|
-
* .columns((c) => ({
|
|
207
|
-
* id: c.bigint(),
|
|
208
|
-
* email: c.varchar(200),
|
|
209
|
-
* name: c.varchar(100),
|
|
210
|
-
* }))
|
|
211
|
-
* .indexes((i) => [
|
|
212
|
-
* i.index("email").unique(),
|
|
213
|
-
* i.index("name").orderBy("ASC"),
|
|
214
|
-
* ]);
|
|
215
|
-
* ```
|
|
216
143
|
*/
|
|
217
144
|
indexes(
|
|
218
145
|
fn: (
|
|
@@ -234,32 +161,6 @@ export class TableBuilder<
|
|
|
234
161
|
* @param fn - 관계 factory를 받아 관계 정의를 반환하는 함수
|
|
235
162
|
* @returns 새 TableBuilder 인스턴스
|
|
236
163
|
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```typescript
|
|
239
|
-
* const Post = Table("Post")
|
|
240
|
-
* .columns((c) => ({
|
|
241
|
-
* id: c.bigint().autoIncrement(),
|
|
242
|
-
* authorId: c.bigint(),
|
|
243
|
-
* title: c.varchar(200),
|
|
244
|
-
* }))
|
|
245
|
-
* .primaryKey("id")
|
|
246
|
-
* .relations((r) => ({
|
|
247
|
-
* // FK relation (N:1)
|
|
248
|
-
* author: r.foreignKey(["authorId"], () => User),
|
|
249
|
-
* }));
|
|
250
|
-
*
|
|
251
|
-
* const User = Table("User")
|
|
252
|
-
* .columns((c) => ({
|
|
253
|
-
* id: c.bigint().autoIncrement(),
|
|
254
|
-
* name: c.varchar(100),
|
|
255
|
-
* }))
|
|
256
|
-
* .primaryKey("id")
|
|
257
|
-
* .relations((r) => ({
|
|
258
|
-
* // Reverse-reference (1:N)
|
|
259
|
-
* posts: r.foreignKeyTarget(() => Post, "author"),
|
|
260
|
-
* }));
|
|
261
|
-
* ```
|
|
262
|
-
*
|
|
263
164
|
* @see {@link ForeignKeyBuilder} FK builder
|
|
264
165
|
* @see {@link ForeignKeyTargetBuilder} FK reverse-reference builder
|
|
265
166
|
*/
|
|
@@ -285,34 +186,6 @@ export class TableBuilder<
|
|
|
285
186
|
* @param name - Table 이름
|
|
286
187
|
* @returns TableBuilder 인스턴스
|
|
287
188
|
*
|
|
288
|
-
* @example
|
|
289
|
-
* ```typescript
|
|
290
|
-
* // Basic usage
|
|
291
|
-
* const User = Table("User")
|
|
292
|
-
* .database("mydb")
|
|
293
|
-
* .columns((c) => ({
|
|
294
|
-
* id: c.bigint().autoIncrement(),
|
|
295
|
-
* name: c.varchar(100),
|
|
296
|
-
* email: c.varchar(200).nullable(),
|
|
297
|
-
* }))
|
|
298
|
-
* .primaryKey("id")
|
|
299
|
-
* .indexes((i) => [i.index("email").unique()]);
|
|
300
|
-
*
|
|
301
|
-
* // With relations
|
|
302
|
-
* const Post = Table("Post")
|
|
303
|
-
* .database("mydb")
|
|
304
|
-
* .columns((c) => ({
|
|
305
|
-
* id: c.bigint().autoIncrement(),
|
|
306
|
-
* authorId: c.bigint(),
|
|
307
|
-
* title: c.varchar(200),
|
|
308
|
-
* content: c.text(),
|
|
309
|
-
* }))
|
|
310
|
-
* .primaryKey("id")
|
|
311
|
-
* .relations((r) => ({
|
|
312
|
-
* author: r.foreignKey(["authorId"], () => User),
|
|
313
|
-
* }));
|
|
314
|
-
* ```
|
|
315
|
-
*
|
|
316
189
|
* @see {@link TableBuilder} builder 클래스
|
|
317
190
|
*/
|
|
318
191
|
export function Table<TName extends string>(name: TName) {
|