@simplysm/orm-node 14.0.17 → 14.0.19

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 CHANGED
@@ -17,18 +17,13 @@ Peer dependencies (install the driver for your DBMS):
17
17
 
18
18
  ## API Overview
19
19
 
20
- ### ORM Factory
20
+ ### ORM Factory & Query Execution
21
21
 
22
22
  | Export | Type | Description |
23
23
  |--------|------|-------------|
24
- | [`createOrm`](./docs/orm-factory.md#createorm) | Function | Create an ORM instance with connection management |
24
+ | [`createOrm`](./docs/orm-factory.md#createorm) | Function | Create an ORM instance from a DbContext subclass and connection config |
25
25
  | [`Orm`](./docs/orm-factory.md#orm) | Interface | ORM instance type with `connect` and `connectWithoutTransaction` |
26
26
  | [`OrmOptions`](./docs/orm-factory.md#ormoptions) | Interface | ORM options (database/schema override) |
27
-
28
- ### Query Execution
29
-
30
- | Export | Type | Description |
31
- |--------|------|-------------|
32
27
  | [`NodeDbContextExecutor`](./docs/orm-factory.md#nodedbcontextexecutor) | Class | Node.js `DbContextExecutor` implementation |
33
28
 
34
29
  ### Connection
@@ -64,12 +59,13 @@ Peer dependencies (install the driver for your DBMS):
64
59
  ### Basic ORM Usage
65
60
 
66
61
  ```typescript
67
- import { defineDbContext } from "@simplysm/orm-common";
62
+ import { DbContext } from "@simplysm/orm-common";
68
63
  import { createOrm } from "@simplysm/orm-node";
69
64
 
70
- const MyDb = defineDbContext({
71
- tables: { user: User, post: Post },
72
- });
65
+ class MyDb extends DbContext {
66
+ user = this.queryable(User);
67
+ post = this.queryable(Post);
68
+ }
73
69
 
74
70
  const orm = createOrm(MyDb, {
75
71
  dialect: "mysql",
@@ -5,28 +5,31 @@ High-level ORM instance creation and Node.js query execution.
5
5
  ## createOrm
6
6
 
7
7
  ```typescript
8
- function createOrm<TDef extends DbContextDef<any, any, any>>(
9
- dbContextDef: TDef,
8
+ function createOrm<T extends DbContext>(
9
+ DbClass: new (executor: DbContextExecutor, opt: { database: string; schema?: string }) => T,
10
10
  config: DbConnConfig,
11
11
  options?: OrmOptions,
12
- ): Orm<TDef>
12
+ ): Orm<T>
13
13
  ```
14
14
 
15
15
  Creates an ORM instance that manages DbContext creation and database connections. Each `connect()` or `connectWithoutTransaction()` call creates a fresh DbContext and connection.
16
16
 
17
+ The `database` parameter is required -- it is resolved from `options.database` first, then `config.database`. An error is thrown if neither is provided.
18
+
17
19
  | Parameter | Type | Description |
18
20
  |-----------|------|-------------|
19
- | `dbContextDef` | `DbContextDef` | DbContext definition from `defineDbContext()` |
21
+ | `DbClass` | `new (executor, opt) => T` | DbContext subclass constructor |
20
22
  | `config` | `DbConnConfig` | Database connection configuration |
21
23
  | `options` | `OrmOptions?` | Optional overrides for database/schema |
22
24
 
23
25
  ```typescript
24
- import { defineDbContext } from "@simplysm/orm-common";
26
+ import { DbContext } from "@simplysm/orm-common";
25
27
  import { createOrm } from "@simplysm/orm-node";
26
28
 
27
- const MyDb = defineDbContext({
28
- tables: { user: User, post: Post },
29
- });
29
+ class MyDb extends DbContext {
30
+ user = this.queryable(User);
31
+ post = this.queryable(Post);
32
+ }
30
33
 
31
34
  const orm = createOrm(MyDb, {
32
35
  dialect: "mysql",
@@ -40,25 +43,27 @@ const orm = createOrm(MyDb, {
40
43
  // Transaction mode
41
44
  await orm.connect(async (db) => {
42
45
  const users = await db.user().execute();
43
- await db.post().insert([{ title: "Hello", authorId: users[0].id }]);
44
46
  return users;
45
47
  });
46
48
 
47
49
  // No-transaction mode (for DDL, read-only)
48
50
  await orm.connectWithoutTransaction(async (db) => {
49
- await db.initialize();
51
+ // ...
50
52
  });
51
53
  ```
52
54
 
53
55
  ## Orm
54
56
 
55
57
  ```typescript
56
- interface Orm<TDef extends DbContextDef<any, any, any>> {
57
- readonly dbContextDef: TDef;
58
+ interface Orm<T extends DbContext> {
59
+ readonly DbClass: new (
60
+ executor: DbContextExecutor,
61
+ opt: { database: string; schema?: string },
62
+ ) => T;
58
63
  readonly config: DbConnConfig;
59
64
  readonly options?: OrmOptions;
60
- connect<R>(callback: (conn: DbContextInstance<TDef>) => Promise<R>, isolationLevel?: IsolationLevel): Promise<R>;
61
- connectWithoutTransaction<R>(callback: (conn: DbContextInstance<TDef>) => Promise<R>): Promise<R>;
65
+ connect<R>(callback: (conn: T) => Promise<R>, isolationLevel?: IsolationLevel): Promise<R>;
66
+ connectWithoutTransaction<R>(callback: (conn: T) => Promise<R>): Promise<R>;
62
67
  }
63
68
  ```
64
69
 
@@ -66,14 +71,14 @@ ORM instance returned by `createOrm()`.
66
71
 
67
72
  | Field | Type | Description |
68
73
  |-------|------|-------------|
69
- | `dbContextDef` | `TDef` | The DbContext definition |
74
+ | `DbClass` | `new (executor, opt) => T` | The DbContext subclass constructor |
70
75
  | `config` | `DbConnConfig` | The connection configuration |
71
76
  | `options` | `OrmOptions?` | The ORM options |
72
77
 
73
78
  | Method | Signature | Description |
74
79
  |--------|-----------|-------------|
75
- | `connect` | `<R>(callback: (conn) => Promise<R>, isolationLevel?) => Promise<R>` | Open connection, begin transaction, execute callback, commit (auto-rollback on error), close |
76
- | `connectWithoutTransaction` | `<R>(callback: (conn) => Promise<R>) => Promise<R>` | Open connection, execute callback, close (no transaction) |
80
+ | `connect` | `<R>(callback: (conn: T) => Promise<R>, isolationLevel?) => Promise<R>` | Open connection, begin transaction, execute callback, commit (auto-rollback on error), close |
81
+ | `connectWithoutTransaction` | `<R>(callback: (conn: T) => Promise<R>) => Promise<R>` | Open connection, execute callback, close (no transaction) |
77
82
 
78
83
  ## OrmOptions
79
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/orm-node",
3
- "version": "14.0.17",
3
+ "version": "14.0.19",
4
4
  "description": "심플리즘 패키지 - ORM (node)",
5
5
  "author": "심플리즘",
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": "14.0.17",
24
- "@simplysm/orm-common": "14.0.17"
23
+ "@simplysm/core-common": "14.0.19",
24
+ "@simplysm/orm-common": "14.0.19"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/pg": "^8.20.0",