@simplysm/orm-node 13.0.69 → 13.0.70

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.
@@ -7,13 +7,13 @@ import { DB_CONN_ERRORS, type DbConn, type DbConnConfig } from "./types/db-conn"
7
7
  const logger = consola.withTag("pooled-db-conn");
8
8
 
9
9
  /**
10
- * 커넥션 풀에서 관리되는 DB 연결 래퍼
10
+ * DB connection wrapper managed by connection pool
11
11
  *
12
- * generic-pool 라이브러리를 사용하여 커넥션 풀링을 지원한다.
13
- * 실제 물리 연결은 풀에서 획득하고 반환한다.
12
+ * Supports connection pooling using the generic-pool library.
13
+ * Acquires and returns actual physical connections from/to the pool.
14
14
  */
15
15
  export class PooledDbConn extends EventEmitter<{ close: void }> implements DbConn {
16
- // 풀에서 빌려온 실제 물리 커넥션
16
+ // Actual physical connection borrowed from pool
17
17
  private _rawConn?: DbConn;
18
18
 
19
19
  constructor(
@@ -40,16 +40,16 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
40
40
  }
41
41
 
42
42
  /**
43
- * 풀에서 DB 연결을 획득한다.
43
+ * Acquire DB connection from pool
44
44
  *
45
- * @throws {SdError} 이미 연결된 상태일 때
45
+ * @throws {SdError} When already connected
46
46
  */
47
47
  async connect(): Promise<void> {
48
48
  if (this._rawConn != null) {
49
49
  throw new SdError(DB_CONN_ERRORS.ALREADY_CONNECTED);
50
50
  }
51
51
 
52
- // 1. 풀에서 커넥션 획득
52
+ // 1. Acquire connection from pool
53
53
  try {
54
54
  this._rawConn = await this._pool.acquire();
55
55
  } catch (err) {
@@ -57,57 +57,57 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
57
57
  const cause = this._getLastCreateError?.() ?? (err instanceof Error ? err : undefined);
58
58
  throw new SdError(
59
59
  ...(cause != null ? [cause] : []),
60
- `DB 연결 실패 [${dialect}://${host}:${port ?? ""}/${database ?? ""}]`,
60
+ `DB connection failed [${dialect}://${host}:${port ?? ""}/${database ?? ""}]`,
61
61
  );
62
62
  }
63
63
 
64
- // 2. 물리 연결이 (타임아웃 등으로) 끊어질 경우를 대비해 리스너 등록
65
- // 만약 사용 중에 끊기면 PooledDbConn close 이벤트를 발생시켜야
64
+ // 2. Register listener to handle physical connection loss (timeout, etc.)
65
+ // If connection disconnects while in use, PooledDbConn must emit close event
66
66
  this._rawConn.on("close", this._onRawConnClose);
67
67
  }
68
68
 
69
69
  /**
70
- * 풀에 DB 연결을 반환한다. (실제 연결을 종료하지 않음)
70
+ * Return DB connection to pool (does not terminate actual connection)
71
71
  */
72
72
  async close(): Promise<void> {
73
73
  if (this._rawConn != null) {
74
- // 1. 트랜잭션 진행 중이면 롤백하여 깨끗한 상태로 풀에 반환
74
+ // 1. If transaction is in progress, rollback to return clean state to pool
75
75
  if (this._rawConn.isInTransaction) {
76
76
  try {
77
77
  await this._rawConn.rollbackTransaction();
78
78
  } catch (err) {
79
- // 롤백 실패 로그만 남기고 계속 진행 (연결이 이미 끊긴 경우 )
80
- logger.warn(" 반환 롤백 실패", err instanceof Error ? err.message : String(err));
79
+ // Log failure and continue (connection may already be disconnected)
80
+ logger.warn("Rollback failed when returning to pool", err instanceof Error ? err.message : String(err));
81
81
  }
82
82
  }
83
83
 
84
- // 2. 리스너 해제 (Pool에 돌아가서 다른 래퍼에 의해 재사용될 영향 주지 않도록)
84
+ // 2. Remove listener (so it won't affect reuse by other wrappers when returned to pool)
85
85
  this._rawConn.off("close", this._onRawConnClose);
86
86
 
87
- // 3. 풀에 커넥션 반환 (실제로 끊지 않음)
87
+ // 3. Return connection to pool (does not actually close it)
88
88
  await this._pool.release(this._rawConn);
89
89
  this._rawConn = undefined;
90
90
 
91
- // 4. 소비자에게 논리적으로 연결이 닫혔음을 알림
91
+ // 4. Notify consumer that connection is logically closed
92
92
  this.emit("close");
93
93
  }
94
94
  }
95
95
 
96
- // 물리 연결이 끊겼을 처리 핸들러
96
+ // Handler for physical connection loss
97
97
  private readonly _onRawConnClose = () => {
98
- // 물리 연결이 끊겼으므로 참조 제거 (Pool에서는 validate 시점에 걸러낼 것임)
98
+ // Remove reference since physical connection is lost (will be filtered during pool validation)
99
99
  this._rawConn = undefined;
100
- // 소비자에게 알림
100
+ // Notify consumer
101
101
  this.emit("close");
102
102
  };
103
103
 
104
- // --- 아래는 위임(Delegation) 메소드 ---
104
+ // --- Below are delegation methods ---
105
105
 
106
106
  /**
107
- * 트랜잭션 시작
107
+ * Begin transaction
108
108
  *
109
- * @param isolationLevel - 트랜잭션 격리 수준
110
- * @throws {SdError} 연결이 획득되지 않은 상태일
109
+ * @param isolationLevel - Transaction isolation level
110
+ * @throws {SdError} When connection is not acquired
111
111
  */
112
112
  async beginTransaction(isolationLevel?: IsolationLevel): Promise<void> {
113
113
  const conn = this._requireRawConn();
@@ -115,9 +115,9 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
115
115
  }
116
116
 
117
117
  /**
118
- * 트랜잭션 커밋
118
+ * Commit transaction
119
119
  *
120
- * @throws {SdError} 연결이 획득되지 않은 상태일
120
+ * @throws {SdError} When connection is not acquired
121
121
  */
122
122
  async commitTransaction(): Promise<void> {
123
123
  const conn = this._requireRawConn();
@@ -125,9 +125,9 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
125
125
  }
126
126
 
127
127
  /**
128
- * 트랜잭션 롤백
128
+ * Rollback transaction
129
129
  *
130
- * @throws {SdError} 연결이 획득되지 않은 상태일
130
+ * @throws {SdError} When connection is not acquired
131
131
  */
132
132
  async rollbackTransaction(): Promise<void> {
133
133
  const conn = this._requireRawConn();
@@ -135,11 +135,11 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
135
135
  }
136
136
 
137
137
  /**
138
- * SQL 쿼리 실행
138
+ * Execute SQL query
139
139
  *
140
- * @param queries - 실행할 SQL 쿼리 배열
141
- * @returns 쿼리의 결과 배열
142
- * @throws {SdError} 연결이 획득되지 않은 상태일
140
+ * @param queries - SQL query array to execute
141
+ * @returns Result array for each query
142
+ * @throws {SdError} When connection is not acquired
143
143
  */
144
144
  async execute(queries: string[]): Promise<Record<string, unknown>[][]> {
145
145
  const conn = this._requireRawConn();
@@ -147,12 +147,12 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
147
147
  }
148
148
 
149
149
  /**
150
- * 파라미터화된 SQL 쿼리 실행
150
+ * Execute parameterized SQL query
151
151
  *
152
- * @param query - SQL 쿼리 문자열
153
- * @param params - 쿼리 파라미터 배열
154
- * @returns 쿼리 결과 배열
155
- * @throws {SdError} 연결이 획득되지 않은 상태일
152
+ * @param query - SQL query string
153
+ * @param params - Query parameter array
154
+ * @returns Query result array
155
+ * @throws {SdError} When connection is not acquired
156
156
  */
157
157
  async executeParametrized(
158
158
  query: string,
@@ -163,12 +163,12 @@ export class PooledDbConn extends EventEmitter<{ close: void }> implements DbCon
163
163
  }
164
164
 
165
165
  /**
166
- * 대량 데이터 삽입 (네이티브 벌크 API 사용)
166
+ * Bulk insert data (using native bulk API)
167
167
  *
168
- * @param tableName - 대상 테이블명
169
- * @param columnMetas - 컬럼 메타데이터
170
- * @param records - 삽입할 레코드 배열
171
- * @throws {SdError} 연결이 획득되지 않은 상태일
168
+ * @param tableName - Target table name
169
+ * @param columnMetas - Column metadata
170
+ * @param records - Record array to insert
171
+ * @throws {SdError} When connection is not acquired
172
172
  */
173
173
  async bulkInsert(
174
174
  tableName: string,
@@ -2,25 +2,25 @@ import type { EventEmitter } from "@simplysm/core-common";
2
2
  import type { ColumnMeta, Dialect, IsolationLevel } from "@simplysm/orm-common";
3
3
 
4
4
  // ============================================
5
- // 공통 상수
5
+ // Common constants
6
6
  // ============================================
7
7
 
8
8
  /**
9
- * DB 연결 수립 타임아웃 (10)
9
+ * DB connection establishment timeout (10 seconds)
10
10
  */
11
11
  export const DB_CONN_CONNECT_TIMEOUT = 10 * 1000;
12
12
 
13
13
  /**
14
- * DB 쿼리 기본 타임아웃 (10)
14
+ * DB query default timeout (10 minutes)
15
15
  */
16
16
  export const DB_CONN_DEFAULT_TIMEOUT = 10 * 60 * 1000;
17
17
 
18
18
  /**
19
- * DB 연결 에러 메시지
19
+ * DB connection error messages
20
20
  */
21
21
  export const DB_CONN_ERRORS = {
22
- NOT_CONNECTED: "'Connection' 연결되어있지 않습니다.",
23
- ALREADY_CONNECTED: "이미 'Connection' 연결되어있습니다.",
22
+ NOT_CONNECTED: "'Connection' is not connected.",
23
+ ALREADY_CONNECTED: "'Connection' is already connected.",
24
24
  } as const;
25
25
 
26
26
  // ============================================
@@ -28,86 +28,86 @@ export const DB_CONN_ERRORS = {
28
28
  // ============================================
29
29
 
30
30
  /**
31
- * 저수준 DB 연결 인터페이스
31
+ * Low-level DB connection interface
32
32
  *
33
- * DBMS 구현체가 인터페이스를 구현합니다.
34
- * - {@link MysqlDbConn} - MySQL 연결
35
- * - {@link MssqlDbConn} - MSSQL 연결
36
- * - {@link PostgresqlDbConn} - PostgreSQL 연결
33
+ * Implementations for each DBMS implement this interface.
34
+ * - {@link MysqlDbConn} - MySQL connection
35
+ * - {@link MssqlDbConn} - MSSQL connection
36
+ * - {@link PostgresqlDbConn} - PostgreSQL connection
37
37
  *
38
38
  * @remarks
39
- * SdEventEmitter를 상속하여 'close' 이벤트를 발생시킵니다.
39
+ * Inherits from EventEmitter and emits 'close' events.
40
40
  */
41
41
  export interface DbConn extends EventEmitter<{ close: void }> {
42
42
  /**
43
- * 연결 설정
43
+ * Connection configuration
44
44
  */
45
45
  config: DbConnConfig;
46
46
 
47
47
  /**
48
- * 연결 여부
48
+ * Whether connected
49
49
  */
50
50
  isConnected: boolean;
51
51
 
52
52
  /**
53
- * 트랜잭션 진행 여부
53
+ * Whether transaction is in progress
54
54
  */
55
55
  isInTransaction: boolean;
56
56
 
57
57
  /**
58
- * DB 연결 수립
58
+ * Establish DB connection
59
59
  */
60
60
  connect(): Promise<void>;
61
61
 
62
62
  /**
63
- * DB 연결 종료
63
+ * Close DB connection
64
64
  */
65
65
  close(): Promise<void>;
66
66
 
67
67
  /**
68
- * 트랜잭션 시작
68
+ * Begin transaction
69
69
  *
70
- * @param isolationLevel - 격리 수준 (선택)
70
+ * @param isolationLevel - Isolation level (optional)
71
71
  */
72
72
  beginTransaction(isolationLevel?: IsolationLevel): Promise<void>;
73
73
 
74
74
  /**
75
- * 트랜잭션 커밋
75
+ * Commit transaction
76
76
  */
77
77
  commitTransaction(): Promise<void>;
78
78
 
79
79
  /**
80
- * 트랜잭션 롤백
80
+ * Rollback transaction
81
81
  */
82
82
  rollbackTransaction(): Promise<void>;
83
83
 
84
84
  /**
85
- * SQL 쿼리 배열 실행
85
+ * Execute SQL query array
86
86
  *
87
- * @param queries - 실행할 SQL 문자열 배열
88
- * @returns 쿼리별 결과 배열의 배열
87
+ * @param queries - SQL string array to execute
88
+ * @returns Array of result arrays for each query
89
89
  */
90
90
  execute(queries: string[]): Promise<Record<string, unknown>[][]>;
91
91
 
92
92
  /**
93
- * 파라미터화된 쿼리 실행
93
+ * Execute parameterized query
94
94
  *
95
- * @param query - SQL 쿼리 문자열
96
- * @param params - 바인딩 파라미터 (선택)
97
- * @returns 결과 배열의 배열
95
+ * @param query - SQL query string
96
+ * @param params - Binding parameters (optional)
97
+ * @returns Array of result arrays
98
98
  */
99
99
  executeParametrized(query: string, params?: unknown[]): Promise<Record<string, unknown>[][]>;
100
100
 
101
101
  /**
102
- * 대량 INSERT (네이티브 벌크 API 사용)
102
+ * Bulk INSERT (using native bulk API)
103
103
  *
104
104
  * - MSSQL: tedious BulkLoad
105
- * - MySQL: LOAD DATA LOCAL INFILE (임시 파일)
105
+ * - MySQL: LOAD DATA LOCAL INFILE (temporary file)
106
106
  * - PostgreSQL: COPY FROM STDIN
107
107
  *
108
- * @param tableName - 테이블명 (database.table 또는 database.schema.table)
109
- * @param columnMetas - 컬럼명 → ColumnMeta 매핑
110
- * @param records - 삽입할 레코드 배열
108
+ * @param tableName - Table name (database.table or database.schema.table)
109
+ * @param columnMetas - Column name → ColumnMeta mapping
110
+ * @param records - Record array to insert
111
111
  */
112
112
  bulkInsert(
113
113
  tableName: string,
@@ -121,33 +121,33 @@ export interface DbConn extends EventEmitter<{ close: void }> {
121
121
  // ============================================
122
122
 
123
123
  /**
124
- * 커넥션 설정
124
+ * Connection pool configuration
125
125
  *
126
126
  * @remarks
127
- * 값의 기본값:
128
- * - min: 1 (최소 연결 )
129
- * - max: 10 (최대 연결 )
130
- * - acquireTimeoutMillis: 30000 (연결 획득 타임아웃)
131
- * - idleTimeoutMillis: 30000 (유휴 연결 타임아웃)
127
+ * Default values for each setting:
128
+ * - min: 1 (minimum connection count)
129
+ * - max: 10 (maximum connection count)
130
+ * - acquireTimeoutMillis: 30000 (connection acquisition timeout)
131
+ * - idleTimeoutMillis: 30000 (idle connection timeout)
132
132
  */
133
133
  export interface DbPoolConfig {
134
- /** 최소 연결 (기본: 1) */
134
+ /** Minimum connection count (default: 1) */
135
135
  min?: number;
136
- /** 최대 연결 (기본: 10) */
136
+ /** Maximum connection count (default: 10) */
137
137
  max?: number;
138
- /** 연결 획득 타임아웃 (밀리초, 기본: 30000) */
138
+ /** Connection acquisition timeout (milliseconds, default: 30000) */
139
139
  acquireTimeoutMillis?: number;
140
- /** 유휴 연결 타임아웃 (밀리초, 기본: 30000) */
140
+ /** Idle connection timeout (milliseconds, default: 30000) */
141
141
  idleTimeoutMillis?: number;
142
142
  }
143
143
 
144
144
  /**
145
- * DB 연결 설정 타입 (dialect별 분기)
145
+ * DB connection configuration type (branching by dialect)
146
146
  */
147
147
  export type DbConnConfig = MysqlDbConnConfig | MssqlDbConnConfig | PostgresqlDbConnConfig;
148
148
 
149
149
  /**
150
- * MySQL 연결 설정
150
+ * MySQL connection configuration
151
151
  */
152
152
  export interface MysqlDbConnConfig {
153
153
  dialect: "mysql";
@@ -161,7 +161,7 @@ export interface MysqlDbConnConfig {
161
161
  }
162
162
 
163
163
  /**
164
- * MSSQL 연결 설정
164
+ * MSSQL connection configuration
165
165
  */
166
166
  export interface MssqlDbConnConfig {
167
167
  dialect: "mssql" | "mssql-azure";
@@ -176,7 +176,7 @@ export interface MssqlDbConnConfig {
176
176
  }
177
177
 
178
178
  /**
179
- * PostgreSQL 연결 설정
179
+ * PostgreSQL connection configuration
180
180
  */
181
181
  export interface PostgresqlDbConnConfig {
182
182
  dialect: "postgresql";
@@ -191,7 +191,7 @@ export interface PostgresqlDbConnConfig {
191
191
  }
192
192
 
193
193
  /**
194
- * DbConnConfig에서 Dialect 추출
194
+ * Extract Dialect from DbConnConfig
195
195
  */
196
196
  export function getDialectFromConfig(config: DbConnConfig): Dialect {
197
197
  if (config.dialect === "mssql-azure") {