@simplysm/orm-common 14.0.99 → 14.0.101
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
|
@@ -21,29 +21,6 @@ import {
|
|
|
21
21
|
* @template TData - View 데이터 레코드 타입
|
|
22
22
|
* @template TRelations - 관계 정의 레코드 타입
|
|
23
23
|
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // View definition
|
|
27
|
-
* const UserSummary = View("UserSummary")
|
|
28
|
-
* .database("mydb")
|
|
29
|
-
* .query((db: MyDb) =>
|
|
30
|
-
* db.user()
|
|
31
|
-
* .select(u => ({
|
|
32
|
-
* id: u.id,
|
|
33
|
-
* name: u.name,
|
|
34
|
-
* postCount: expr.subquery(
|
|
35
|
-
* db.post().where(p => [expr.eq(p.authorId, u.id)]),
|
|
36
|
-
* q => expr.count(q.id)
|
|
37
|
-
* ),
|
|
38
|
-
* }))
|
|
39
|
-
* );
|
|
40
|
-
*
|
|
41
|
-
* // Used in DbContext
|
|
42
|
-
* class MyDb extends DbContext {
|
|
43
|
-
* readonly userSummary = queryable(this, UserSummary);
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
24
|
* @see {@link View} factory 함수
|
|
48
25
|
* @see {@link queryable} Queryable 생성
|
|
49
26
|
*/
|
|
@@ -92,11 +69,6 @@ export class ViewBuilder<
|
|
|
92
69
|
*
|
|
93
70
|
* @param db - Database 이름
|
|
94
71
|
* @returns 새 ViewBuilder 인스턴스
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const UserSummary = View("UserSummary").database("mydb");
|
|
99
|
-
* ```
|
|
100
72
|
*/
|
|
101
73
|
database(db: string): ViewBuilder<TDbContext, TData, TRelations> {
|
|
102
74
|
return new ViewBuilder({ ...this.meta, database: db });
|
|
@@ -123,21 +95,6 @@ export class ViewBuilder<
|
|
|
123
95
|
* @template TDb - DbContext 타입
|
|
124
96
|
* @param viewFn - DbContext를 받아 Queryable을 반환하는 함수
|
|
125
97
|
* @returns 새 ViewBuilder 인스턴스
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```typescript
|
|
129
|
-
* const ActiveUsers = View("ActiveUsers")
|
|
130
|
-
* .database("mydb")
|
|
131
|
-
* .query((db: MyDb) =>
|
|
132
|
-
* db.user()
|
|
133
|
-
* .where(u => [expr.eq(u.status, "active")])
|
|
134
|
-
* .select(u => ({
|
|
135
|
-
* id: u.id,
|
|
136
|
-
* name: u.name,
|
|
137
|
-
* email: u.email,
|
|
138
|
-
* }))
|
|
139
|
-
* );
|
|
140
|
-
* ```
|
|
141
98
|
*/
|
|
142
99
|
query<TViewData extends DataRecord, TDb extends DbContextBase>(
|
|
143
100
|
viewFn: (db: TDb) => Queryable<TViewData, any>,
|
|
@@ -154,15 +111,6 @@ export class ViewBuilder<
|
|
|
154
111
|
* @param fn - 관계 factory를 받아 관계 정의를 반환하는 함수
|
|
155
112
|
* @returns 새 ViewBuilder 인스턴스
|
|
156
113
|
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```typescript
|
|
159
|
-
* const UserSummary = View("UserSummary")
|
|
160
|
-
* .query((db: MyDb) => db.user().select(...))
|
|
161
|
-
* .relations((r) => ({
|
|
162
|
-
* posts: r.foreignKeyTarget(Post, "author"),
|
|
163
|
-
* }));
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
114
|
* @see {@link ForeignKeyBuilder} FK builder
|
|
167
115
|
* @see {@link ForeignKeyTargetBuilder} FK reverse-reference builder
|
|
168
116
|
*/
|
|
@@ -188,30 +136,6 @@ export class ViewBuilder<
|
|
|
188
136
|
* @param name - View 이름
|
|
189
137
|
* @returns ViewBuilder 인스턴스
|
|
190
138
|
*
|
|
191
|
-
* @example
|
|
192
|
-
* ```typescript
|
|
193
|
-
* // Basic usage
|
|
194
|
-
* const ActiveUsers = View("ActiveUsers")
|
|
195
|
-
* .database("mydb")
|
|
196
|
-
* .query((db: MyDb) =>
|
|
197
|
-
* db.user()
|
|
198
|
-
* .where(u => [expr.eq(u.status, "active")])
|
|
199
|
-
* .select(u => ({ id: u.id, name: u.name }))
|
|
200
|
-
* );
|
|
201
|
-
*
|
|
202
|
-
* // 집계 View
|
|
203
|
-
* const UserStats = View("UserStats")
|
|
204
|
-
* .database("mydb")
|
|
205
|
-
* .query((db: MyDb) =>
|
|
206
|
-
* db.user()
|
|
207
|
-
* .groupBy(u => ({ status: u.status }))
|
|
208
|
-
* .select(u => ({
|
|
209
|
-
* status: u.status,
|
|
210
|
-
* count: expr.count(u.id),
|
|
211
|
-
* }))
|
|
212
|
-
* );
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
139
|
* @see {@link ViewBuilder} builder 클래스
|
|
216
140
|
*/
|
|
217
141
|
export function View(name: string) {
|
package/src/types/column.ts
CHANGED
|
@@ -22,13 +22,6 @@ import { DateOnly, DateTime, Time, Uuid, type Bytes } from "@simplysm/core-commo
|
|
|
22
22
|
* - `date`: DATE
|
|
23
23
|
* - `time`: TIME
|
|
24
24
|
* - `uuid`: BINARY(16)/UNIQUEIDENTIFIER/UUID
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const intType: DataType = { type: "int" };
|
|
29
|
-
* const decimalType: DataType = { type: "decimal", precision: 10, scale: 2 };
|
|
30
|
-
* const varcharType: DataType = { type: "varchar", length: 100 };
|
|
31
|
-
* ```
|
|
32
25
|
*/
|
|
33
26
|
export type DataType =
|
|
34
27
|
| { type: "int" }
|
|
@@ -54,12 +47,6 @@ export type DataType =
|
|
|
54
47
|
* Column 원시 타입 매핑
|
|
55
48
|
*
|
|
56
49
|
* TypeScript 타입 이름 (문자열) → 실제 TypeScript 타입 매핑
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* type StringType = ColumnPrimitiveMap["string"]; // string
|
|
61
|
-
* type DateTimeType = ColumnPrimitiveMap["DateTime"]; // DateTime
|
|
62
|
-
* ```
|
|
63
50
|
*/
|
|
64
51
|
export type ColumnPrimitiveMap = {
|
|
65
52
|
string: string;
|
|
@@ -74,12 +61,6 @@ export type ColumnPrimitiveMap = {
|
|
|
74
61
|
|
|
75
62
|
/**
|
|
76
63
|
* Column 원시 타입 이름 (문자열)
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const typeStr: ColumnPrimitiveStr = "string"; // OK
|
|
81
|
-
* const typeStr2: ColumnPrimitiveStr = "invalid"; // Error
|
|
82
|
-
* ```
|
|
83
64
|
*/
|
|
84
65
|
export type ColumnPrimitiveStr = keyof ColumnPrimitiveMap;
|
|
85
66
|
|
|
@@ -96,12 +77,6 @@ export type ColumnPrimitive = ColumnPrimitiveMap[ColumnPrimitiveStr] | undefined
|
|
|
96
77
|
|
|
97
78
|
/**
|
|
98
79
|
* SQL DataType → TypeScript 타입 이름 매핑
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const tsType = dataTypeStrToColumnPrimitiveStr["int"]; // "number"
|
|
103
|
-
* const tsType2 = dataTypeStrToColumnPrimitiveStr["datetime"]; // "DateTime"
|
|
104
|
-
* ```
|
|
105
80
|
*/
|
|
106
81
|
export const dataTypeStrToColumnPrimitiveStr = {
|
|
107
82
|
int: "number" as const,
|
|
@@ -124,12 +99,6 @@ export const dataTypeStrToColumnPrimitiveStr = {
|
|
|
124
99
|
* DataType으로부터 TypeScript 타입 추론
|
|
125
100
|
*
|
|
126
101
|
* @template T - DataType
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* type IntType = InferColumnPrimitiveFromDataType<{ type: "int" }>; // number
|
|
131
|
-
* type VarcharType = InferColumnPrimitiveFromDataType<{ type: "varchar"; length: 100 }>; // string
|
|
132
|
-
* ```
|
|
133
102
|
*/
|
|
134
103
|
export type InferColumnPrimitiveFromDataType<TDataType extends DataType> =
|
|
135
104
|
ColumnPrimitiveMap[(typeof dataTypeStrToColumnPrimitiveStr)[TDataType["type"]]];
|
|
@@ -140,13 +109,6 @@ export type InferColumnPrimitiveFromDataType<TDataType extends DataType> =
|
|
|
140
109
|
* @param value - Column 값
|
|
141
110
|
* @returns ColumnPrimitiveStr 타입 이름
|
|
142
111
|
* @throws 값 타입이 알 수 없을 때 Error
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* inferColumnPrimitiveStr("hello"); // "string"
|
|
147
|
-
* inferColumnPrimitiveStr(123); // "number"
|
|
148
|
-
* inferColumnPrimitiveStr(new DateTime()); // "DateTime"
|
|
149
|
-
* ```
|
|
150
112
|
*/
|
|
151
113
|
export function inferColumnPrimitiveStr(value: ColumnPrimitive): ColumnPrimitiveStr {
|
|
152
114
|
if (typeof value === "string") return "string";
|
package/src/types/db.ts
CHANGED
|
@@ -19,14 +19,6 @@ export type Dialect = "mysql" | "mssql" | "postgresql";
|
|
|
19
19
|
* 지원하는 모든 Database dialect 목록
|
|
20
20
|
*
|
|
21
21
|
* 테스트에서 dialect별 검증에 사용
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* it.each(dialects)("[%s] SQL Validation", (dialect) => {
|
|
26
|
-
* const builder = createQueryBuilder(dialect);
|
|
27
|
-
* expect(builder.build(def)).toMatchSql(expected[dialect]);
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
22
|
*/
|
|
31
23
|
export const dialects: Dialect[] = ["mysql", "mssql", "postgresql"];
|
|
32
24
|
|
|
@@ -70,20 +62,6 @@ export type IsolationLevel =
|
|
|
70
62
|
* Query 결과 데이터 레코드 타입
|
|
71
63
|
*
|
|
72
64
|
* 재귀적 구조로 중첩 관계(include) 결과를 표현
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // 단순 레코드
|
|
77
|
-
* type User = { id: number; name: string; }
|
|
78
|
-
*
|
|
79
|
-
* // 중첩 관계 include
|
|
80
|
-
* type UserWithPosts = {
|
|
81
|
-
* id: number;
|
|
82
|
-
* name: string;
|
|
83
|
-
* posts: { id: number; title: string; }[] // 1:N 관계
|
|
84
|
-
* company: { id: number; name: string; } // N:1 관계
|
|
85
|
-
* }
|
|
86
|
-
* ```
|
|
87
65
|
*/
|
|
88
66
|
export type DataRecord = {
|
|
89
67
|
[key: string]: ColumnPrimitive | DataRecord | DataRecord[];
|
|
@@ -99,17 +77,6 @@ export type DataRecord = {
|
|
|
99
77
|
* 실제 DB 연결과 query 실행을 담당
|
|
100
78
|
* NodeDbContextExecutor(서버) 또는 SdOrmServiceClientDbContextExecutor(클라이언트)로 구현
|
|
101
79
|
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* // 서버 측 구현 예시
|
|
105
|
-
* class NodeDbContextExecutor implements IDbContextExecutor {
|
|
106
|
-
* async connect(): Promise<void> {
|
|
107
|
-
* await this.connection.connect();
|
|
108
|
-
* }
|
|
109
|
-
* // ...
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
80
|
* @see {@link DbContext} DbContext에서 사용
|
|
114
81
|
*/
|
|
115
82
|
export interface DbContextExecutor {
|
|
@@ -179,27 +146,6 @@ export interface ResultMeta {
|
|
|
179
146
|
* @property name - 고유 Migration 이름 (타임스탬프 권장)
|
|
180
147
|
* @property up - Migration 실행 함수
|
|
181
148
|
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```typescript
|
|
184
|
-
* const migrations: Migration[] = [
|
|
185
|
-
* {
|
|
186
|
-
* name: "20260105_001_create_user_table",
|
|
187
|
-
* up: async (db) => {
|
|
188
|
-
* await db.createTable(User);
|
|
189
|
-
* },
|
|
190
|
-
* },
|
|
191
|
-
* {
|
|
192
|
-
* name: "20260105_002_add_email_column",
|
|
193
|
-
* up: async (db) => {
|
|
194
|
-
* await db.addColumn(User, "email", {
|
|
195
|
-
* type: "varchar",
|
|
196
|
-
* length: 200,
|
|
197
|
-
* });
|
|
198
|
-
* },
|
|
199
|
-
* },
|
|
200
|
-
* ];
|
|
201
|
-
* ```
|
|
202
|
-
*
|
|
203
149
|
* @see {@link DbContext.initialize} migration 실행
|
|
204
150
|
*/
|
|
205
151
|
export interface Migration {
|
|
@@ -82,9 +82,6 @@ function buildColumnInfos(columns: Record<string, ColumnPrimitiveStr>): ColumnIn
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* 플랫 레코드를 중첩 객체로 변환
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* { "posts.id": 1, "posts.title": "Hi" } → { posts: { id: 1, title: "Hi" } }
|
|
88
85
|
*/
|
|
89
86
|
function flatToNested(
|
|
90
87
|
record: Record<string, unknown>,
|
|
@@ -186,27 +183,6 @@ const yieldToEventLoop: () => Promise<void> =
|
|
|
186
183
|
* - async 전용: 대규모 처리 시 외부 인터럽트 허용을 위해 동기 버전 미제공
|
|
187
184
|
* - 브라우저/Node 호환: setTimeout(resolve, 0)으로 양보
|
|
188
185
|
* - 빈 결과 처리: 입력 배열이 비어있거나 파싱 후 모든 레코드가 빈 객체이면 undefined 반환
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* // 1. 단순 타입 파싱
|
|
193
|
-
* const raw = [{ id: "1", createdAt: "2026-01-07T10:00:00.000Z" }];
|
|
194
|
-
* const meta = { columns: { id: "number", createdAt: "DateTime" }, joins: {} };
|
|
195
|
-
* const result = await parseQueryResult(raw, meta);
|
|
196
|
-
* // [{ id: 1, createdAt: DateTime(...) }]
|
|
197
|
-
*
|
|
198
|
-
* // 2. JOIN 결과 중첩
|
|
199
|
-
* const raw = [
|
|
200
|
-
* { id: 1, name: "User1", "posts.id": 10, "posts.title": "Post1" },
|
|
201
|
-
* { id: 1, name: "User1", "posts.id": 11, "posts.title": "Post2" },
|
|
202
|
-
* ];
|
|
203
|
-
* const meta = {
|
|
204
|
-
* columns: { id: "number", name: "string", "posts.id": "number", "posts.title": "string" },
|
|
205
|
-
* joins: { posts: { isSingle: false } }
|
|
206
|
-
* };
|
|
207
|
-
* const result = await parseQueryResult(raw, meta);
|
|
208
|
-
* // [{ id: 1, name: "User1", posts: [{ id: 10, title: "Post1" }, { id: 11, title: "Post2" }] }]
|
|
209
|
-
* ```
|
|
210
186
|
*/
|
|
211
187
|
export async function parseQueryResult<TRecord>(
|
|
212
188
|
rawResults: Record<string, unknown>[],
|