@simplysm/orm-node 13.0.29 → 13.0.31
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/README.md +27 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ createOrm() (top-level entry point)
|
|
|
35
35
|
└── MysqlDbConn / MssqlDbConn / PostgresqlDbConn (DBMS-specific low-level connections)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
- `createOrm()` is the top-level factory function that takes a `
|
|
38
|
+
- `createOrm()` is the top-level factory function that takes a `DbContextDef` and connection settings to manage transactions.
|
|
39
39
|
- `NodeDbContextExecutor` is the executor used by `DbContext`, converting `QueryDef` to SQL and executing it.
|
|
40
40
|
- `createDbConn()` is a factory function that acquires connections from the connection pool.
|
|
41
41
|
- `PooledDbConn` is a connection pool wrapper based on `generic-pool`, returning connections to the pool instead of closing them after use.
|
|
@@ -47,7 +47,7 @@ createOrm() (top-level entry point)
|
|
|
47
47
|
|
|
48
48
|
| Function | Description |
|
|
49
49
|
|----------|-------------|
|
|
50
|
-
| `createOrm()` | ORM factory function. Takes `
|
|
50
|
+
| `createOrm()` | ORM factory function. Takes a `DbContextDef` and connection settings to manage transaction-based connections. |
|
|
51
51
|
| `createDbConn()` | Connection factory function. Caches connection pools by configuration and returns `PooledDbConn`. |
|
|
52
52
|
|
|
53
53
|
### Classes
|
|
@@ -65,18 +65,20 @@ createOrm() (top-level entry point)
|
|
|
65
65
|
| Type | Description |
|
|
66
66
|
|------|------|
|
|
67
67
|
| `DbConn` | Low-level DB connection interface. Implemented by all DBMS-specific connection classes. |
|
|
68
|
+
| `Orm<TDef>` | Return type of `createOrm()`. Exposes `connect()` and `connectWithoutTransaction()` methods. |
|
|
69
|
+
| `OrmOptions` | `createOrm()` options. `database`, `schema` settings that override `DbConnConfig`. |
|
|
68
70
|
| `DbConnConfig` | DB connection config union type (`MysqlDbConnConfig \| MssqlDbConnConfig \| PostgresqlDbConnConfig`). |
|
|
69
71
|
| `MysqlDbConnConfig` | MySQL connection config. `dialect: "mysql"`. |
|
|
70
72
|
| `MssqlDbConnConfig` | MSSQL connection config. `dialect: "mssql" \| "mssql-azure"`. |
|
|
71
73
|
| `PostgresqlDbConnConfig` | PostgreSQL connection config. `dialect: "postgresql"`. |
|
|
72
74
|
| `DbPoolConfig` | Connection pool config (`min`, `max`, `acquireTimeoutMillis`, `idleTimeoutMillis`). |
|
|
73
|
-
| `OrmOptions` | `createOrm()` options. `database`, `schema` settings that override `DbConnConfig`. |
|
|
74
75
|
|
|
75
76
|
### Constants and Utility Functions
|
|
76
77
|
|
|
77
78
|
| Name | Description |
|
|
78
79
|
|------|------|
|
|
79
|
-
| `
|
|
80
|
+
| `DB_CONN_CONNECT_TIMEOUT` | DB connection establishment timeout (10 seconds, 10000ms). |
|
|
81
|
+
| `DB_CONN_DEFAULT_TIMEOUT` | DB query default timeout (10 minutes, 600000ms). |
|
|
80
82
|
| `DB_CONN_ERRORS` | DB connection error message constants (`NOT_CONNECTED`, `ALREADY_CONNECTED`). |
|
|
81
83
|
| `getDialectFromConfig(config)` | Extract `Dialect` from `DbConnConfig`. `"mssql-azure"` is converted to `"mssql"`. |
|
|
82
84
|
|
|
@@ -84,11 +86,11 @@ createOrm() (top-level entry point)
|
|
|
84
86
|
|
|
85
87
|
### Basic Usage with createOrm
|
|
86
88
|
|
|
87
|
-
`createOrm()` is the top-level factory function used with `
|
|
89
|
+
`createOrm()` is the top-level factory function used with `defineDbContext`. It automatically handles transaction management.
|
|
88
90
|
|
|
89
91
|
```typescript
|
|
90
92
|
import { createOrm } from "@simplysm/orm-node";
|
|
91
|
-
import {
|
|
93
|
+
import { defineDbContext, Table } from "@simplysm/orm-common";
|
|
92
94
|
|
|
93
95
|
// 1. Define table
|
|
94
96
|
const User = Table("User")
|
|
@@ -101,9 +103,9 @@ const User = Table("User")
|
|
|
101
103
|
.primaryKey("id");
|
|
102
104
|
|
|
103
105
|
// 2. Define DbContext
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
106
|
+
const MyDb = defineDbContext({
|
|
107
|
+
tables: { user: User },
|
|
108
|
+
});
|
|
107
109
|
|
|
108
110
|
// 3. Create ORM instance
|
|
109
111
|
const orm = createOrm(MyDb, {
|
|
@@ -380,6 +382,18 @@ The common interface implemented by all DBMS-specific connection classes (`Mysql
|
|
|
380
382
|
|
|
381
383
|
`DbConn` extends `EventEmitter<{ close: void }>`, so you can listen for connection close events with `on("close", handler)` / `off("close", handler)`.
|
|
382
384
|
|
|
385
|
+
## Orm Interface
|
|
386
|
+
|
|
387
|
+
The return type of `createOrm()`. Provides the `connect()` and `connectWithoutTransaction()` methods.
|
|
388
|
+
|
|
389
|
+
| Member | Signature | Description |
|
|
390
|
+
|--------|-----------|-------------|
|
|
391
|
+
| `dbContextDef` | `TDef` | The `DbContextDef` passed to `createOrm()` |
|
|
392
|
+
| `config` | `DbConnConfig` | The connection config passed to `createOrm()` |
|
|
393
|
+
| `options` | `OrmOptions \| undefined` | The options passed to `createOrm()` |
|
|
394
|
+
| `connect()` | `(callback, isolationLevel?) => Promise<R>` | Run callback inside a transaction; auto-commits on success, auto-rolls back on error |
|
|
395
|
+
| `connectWithoutTransaction()` | `(callback) => Promise<R>` | Run callback without a transaction |
|
|
396
|
+
|
|
383
397
|
## Supported Databases
|
|
384
398
|
|
|
385
399
|
| Database | Driver Package | dialect Value | Minimum Version |
|
|
@@ -393,8 +407,9 @@ The common interface implemented by all DBMS-specific connection classes (`Mysql
|
|
|
393
407
|
|
|
394
408
|
### Timeouts
|
|
395
409
|
|
|
396
|
-
-
|
|
397
|
-
-
|
|
410
|
+
- Connection establishment timeout is 10 seconds (`DB_CONN_CONNECT_TIMEOUT = 10000ms`).
|
|
411
|
+
- Query default timeout is 10 minutes (`DB_CONN_DEFAULT_TIMEOUT = 600000ms`).
|
|
412
|
+
- Connections are automatically closed if idle for more than twice the query timeout (20 minutes).
|
|
398
413
|
- Connection pool's `acquireTimeoutMillis` (default 30s) and `idleTimeoutMillis` (default 30s) operate separately.
|
|
399
414
|
|
|
400
415
|
### SQL Injection Security
|
|
@@ -417,6 +432,7 @@ DBMS-specific drivers (`mysql2`, `tedious`, `pg`) are lazy-loaded within `create
|
|
|
417
432
|
| `tedious` | MSSQL driver |
|
|
418
433
|
| `pg` | PostgreSQL driver |
|
|
419
434
|
| `pg-copy-streams` | PostgreSQL bulk COPY support |
|
|
435
|
+
| `generic-pool` | Connection pooling |
|
|
420
436
|
|
|
421
437
|
## License
|
|
422
438
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/orm-node",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.31",
|
|
4
4
|
"description": "심플리즘 패키지 - ORM 모듈 (node)",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"consola": "^3.4.2",
|
|
22
22
|
"generic-pool": "^3.9.0",
|
|
23
|
-
"@simplysm/core-common": "13.0.
|
|
24
|
-
"@simplysm/orm-common": "13.0.
|
|
23
|
+
"@simplysm/core-common": "13.0.31",
|
|
24
|
+
"@simplysm/orm-common": "13.0.31"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/pg": "^8.16.0",
|