@simplysm/orm-node 13.0.95 → 13.0.96

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.
Files changed (2) hide show
  1. package/README.md +20 -7
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -28,8 +28,8 @@ createOrm() -- 최상위 팩토리 (ORM 인스턴스)
28
28
  ```
29
29
 
30
30
  - `createOrm` -- `@simplysm/orm-common`의 `DbContext`와 DB 연결을 결합하는 고수준 API
31
- - `NodeDbContextExecutor` -- `QueryDef` SQL 변환 및 실행을 담당하는 어댑터
32
- - `createDbConn` -- DB 연결 인스턴스를 생성
31
+ - `NodeDbContextExecutor` -- `QueryDef` -> SQL 변환 및 실행을 담당하는 어댑터
32
+ - `createDbConn` -- DB 연결 인스턴스를 생성하는 팩토리
33
33
  - `MysqlDbConn` / `PostgresqlDbConn` / `MssqlDbConn` -- 각 DBMS별 실제 연결 구현
34
34
 
35
35
  ## 주요 사용법
@@ -54,6 +54,7 @@ const MyDb = defineDbContext({
54
54
  });
55
55
 
56
56
  // 2. ORM 인스턴스 생성
57
+ // database는 필수 -- config 또는 options 중 하나에 반드시 지정해야 한다.
57
58
  const orm = createOrm(MyDb, {
58
59
  dialect: "mysql",
59
60
  host: "localhost",
@@ -95,6 +96,7 @@ const orm = createOrm(MyDb, config, {
95
96
  ```typescript
96
97
  import { createDbConn } from "@simplysm/orm-node";
97
98
 
99
+ // createDbConn은 연결 객체만 생성한다. connect()를 호출해야 실제 연결이 수립된다.
98
100
  const conn = await createDbConn(config);
99
101
  await conn.connect();
100
102
 
@@ -138,6 +140,8 @@ function createOrm<TDef extends DbContextDef<any, any, any>>(
138
140
  ): Orm<TDef>;
139
141
  ```
140
142
 
143
+ `database`는 `options.database` -> `config.database` 순서로 결정되며, 둘 다 없으면 에러가 발생한다. `schema`도 같은 우선순위로 결정된다.
144
+
141
145
  **`Orm<TDef>` 인터페이스:**
142
146
 
143
147
  | 속성/메서드 | 타입 | 설명 |
@@ -157,7 +161,7 @@ function createOrm<TDef extends DbContextDef<any, any, any>>(
157
161
 
158
162
  ### `createDbConn(config): Promise<DbConn>`
159
163
 
160
- DB 연결 인스턴스를 생성하여 반환한다. 반환된 객체에 `connect()`를 호출해야 실제 연결이 수립된다.
164
+ DB 연결 인스턴스를 생성하여 반환한다. 반환된 객체에 `connect()`를 호출해야 실제 연결이 수립된다. 드라이버 모듈은 호출 시 lazy import된다.
161
165
 
162
166
  ```typescript
163
167
  function createDbConn(config: DbConnConfig): Promise<DbConn>;
@@ -207,6 +211,7 @@ type DbConnConfig = MysqlDbConnConfig | MssqlDbConnConfig | PostgresqlDbConnConf
207
211
  | `password` | `string` | 비밀번호 |
208
212
  | `database?` | `string` | 데이터베이스명 |
209
213
  | `defaultIsolationLevel?` | `IsolationLevel` | 기본 격리 수준 |
214
+
210
215
  **MSSQL/PostgreSQL 전용:**
211
216
 
212
217
  | 필드 | 타입 | 설명 |
@@ -237,8 +242,8 @@ class NodeDbContextExecutor implements DbContextExecutor {
237
242
 
238
243
  **`executeDefs` 동작:**
239
244
  - `QueryDef`를 dialect에 맞는 SQL로 변환 (`createQueryBuilder`)
240
- - `resultMetas`가 모두 `undefined`이면 결과 없는 쿼리로 판단하여 단일 배치 실행
241
- - `ResultMeta`가 있으면 `parseQueryResult`로 타입 변환 적용
245
+ - `resultMetas`가 모두 `undefined`이면 -> 결과 없는 쿼리로 판단하여 단일 배치 실행
246
+ - `ResultMeta`가 있으면 -> `parseQueryResult`로 타입 변환 적용
242
247
 
243
248
  ### DB 연결 구현 클래스
244
249
 
@@ -250,9 +255,15 @@ class NodeDbContextExecutor implements DbContextExecutor {
250
255
 
251
256
  모두 `EventEmitter<{ close: void }>`를 상속하고 `DbConn`을 구현한다. 드라이버 모듈은 `createDbConn` 호출 시 lazy import된다.
252
257
 
258
+ **DBMS별 참고 사항:**
259
+ - MySQL: `username`이 `"root"`인 경우 특정 database에 바인딩하지 않고 연결한다 (관리 작업용).
260
+ - MySQL: `charset`은 `utf8mb4`로 고정, `multipleStatements`가 활성화되어 있다.
261
+ - PostgreSQL: 기본 포트 `5432`가 자동 적용된다.
262
+ - MSSQL: `trustServerCertificate: true`로 설정된다.
263
+
253
264
  ### `getDialectFromConfig(config): Dialect`
254
265
 
255
- config에서 `Dialect`를 추출한다. `"mssql-azure"` `"mssql"`로 변환된다.
266
+ config에서 `Dialect`를 추출한다. `"mssql-azure"` -> `"mssql"`로 변환된다.
256
267
 
257
268
  ```typescript
258
269
  function getDialectFromConfig(config: DbConnConfig): Dialect;
@@ -267,9 +278,11 @@ function getDialectFromConfig(config: DbConnConfig): Dialect;
267
278
  | `DB_CONN_ERRORS.NOT_CONNECTED` | `"'Connection' is not connected."` | 미연결 에러 메시지 |
268
279
  | `DB_CONN_ERRORS.ALREADY_CONNECTED` | `"'Connection' is already connected."` | 중복 연결 에러 메시지 |
269
280
 
281
+ 연결 유휴 시 자동 종료: 마지막 쿼리 실행 후 `DB_CONN_DEFAULT_TIMEOUT * 2` (20분) 동안 활동이 없으면 연결이 자동으로 닫힌다.
282
+
270
283
  ### IsolationLevel 타입
271
284
 
272
- `@simplysm/orm-common`에서 제공하는 트랜잭션 격리 수준이다.
285
+ `@simplysm/orm-common`에서 제공하는 트랜잭션 격리 수준이다. `isolationLevel`을 지정하지 않으면 `config.defaultIsolationLevel`이 사용되고, 이것도 없으면 `READ_UNCOMMITTED`가 기본값이다.
273
286
 
274
287
  ```typescript
275
288
  type IsolationLevel = "READ_UNCOMMITTED" | "READ_COMMITTED" | "REPEATABLE_READ" | "SERIALIZABLE";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/orm-node",
3
- "version": "13.0.95",
3
+ "version": "13.0.96",
4
4
  "description": "Simplysm package - ORM module (node)",
5
5
  "author": "simplysm",
6
6
  "license": "Apache-2.0",
@@ -20,8 +20,8 @@
20
20
  "sideEffects": false,
21
21
  "dependencies": {
22
22
  "consola": "^3.4.2",
23
- "@simplysm/core-common": "13.0.95",
24
- "@simplysm/orm-common": "13.0.95"
23
+ "@simplysm/core-common": "13.0.96",
24
+ "@simplysm/orm-common": "13.0.96"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/pg": "^8.18.0",