metal-orm 1.0.57 → 1.0.58
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 +22 -15
- package/dist/index.cjs +640 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -45
- package/dist/index.d.ts +113 -45
- package/dist/index.js +639 -83
- package/dist/index.js.map +1 -1
- package/package.json +69 -69
- package/src/decorators/bootstrap.ts +39 -3
- package/src/orm/entity-meta.ts +6 -3
- package/src/orm/entity.ts +81 -14
- package/src/orm/execute.ts +87 -20
- package/src/orm/lazy-batch.ts +237 -54
- package/src/orm/relations/belongs-to.ts +2 -2
- package/src/orm/relations/has-many.ts +23 -9
- package/src/orm/relations/has-one.ts +2 -2
- package/src/orm/relations/many-to-many.ts +27 -13
- package/src/orm/save-graph-types.ts +2 -2
- package/src/orm/save-graph.ts +18 -18
- package/src/query-builder/relation-conditions.ts +80 -59
- package/src/query-builder/relation-service.ts +399 -95
- package/src/query-builder/relation-types.ts +2 -2
- package/src/query-builder/select.ts +58 -40
- package/src/schema/types.ts +106 -89
package/README.md
CHANGED
|
@@ -231,10 +231,10 @@ todos.columns.done.default = false;
|
|
|
231
231
|
const t = tableRef(todos);
|
|
232
232
|
|
|
233
233
|
// 2) Build a simple query
|
|
234
|
-
const listOpenTodos = selectFrom(todos)
|
|
235
|
-
.select('id', 'title', 'done')
|
|
236
|
-
.where(eq(t.done, false))
|
|
237
|
-
.orderBy(t.id, 'ASC');
|
|
234
|
+
const listOpenTodos = selectFrom(todos)
|
|
235
|
+
.select('id', 'title', 'done')
|
|
236
|
+
.where(eq(t.done, false))
|
|
237
|
+
.orderBy(t.id, 'ASC');
|
|
238
238
|
|
|
239
239
|
// 3) Compile to SQL + params
|
|
240
240
|
const dialect = new MySqlDialect();
|
|
@@ -244,14 +244,21 @@ const { sql, params } = listOpenTodos.compile(dialect);
|
|
|
244
244
|
const connection = await mysql.createConnection({ /* ... */ });
|
|
245
245
|
const [rows] = await connection.execute(sql, params);
|
|
246
246
|
|
|
247
|
-
console.log(rows);
|
|
248
|
-
// [
|
|
249
|
-
// { id: 1, title: 'Write docs', done: 0 },
|
|
250
|
-
// { id: 2, title: 'Ship feature', done: 0 },
|
|
251
|
-
// ]
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
|
|
247
|
+
console.log(rows);
|
|
248
|
+
// [
|
|
249
|
+
// { id: 1, title: 'Write docs', done: 0 },
|
|
250
|
+
// { id: 2, title: 'Ship feature', done: 0 },
|
|
251
|
+
// ]
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
If you keep a reusable array of column names (e.g. shared across helpers or pulled from config), you can spread it into `.select(...)` since the method accepts rest arguments:
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
const defaultColumns = ['id', 'title', 'done'] as const;
|
|
258
|
+
const listOpenTodos = selectFrom(todos).select(...defaultColumns);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
That's it: schema, query, SQL, done.
|
|
255
262
|
|
|
256
263
|
If you are using the Level 2 runtime (`OrmSession`), `SelectQueryBuilder` also provides `count(session)` and `executePaged(session, { page, pageSize })` for common pagination patterns.
|
|
257
264
|
|
|
@@ -268,7 +275,7 @@ const listOpenTodos = selectFrom(todos)
|
|
|
268
275
|
.orderBy(t.id, 'ASC');
|
|
269
276
|
```
|
|
270
277
|
|
|
271
|
-
`select`, `
|
|
278
|
+
`select`, `include` (with `columns`), `includePick`, `selectColumnsDeep`, the `sel()` helpers for tables, and `esel()` for entities all build typed selection maps without repeating `table.columns.*`. Use those helpers when building query selections and reserve `table.columns.*` for schema definition, relations, or rare cases where you need a column reference outside of a picker. See the [Query Builder docs](./docs/query-builder.md#selection-helpers) for the reference, examples, and best practices for these helpers.
|
|
272
279
|
|
|
273
280
|
#### Ergonomic column access (opt-in) with `tableRef`
|
|
274
281
|
|
|
@@ -452,7 +459,7 @@ What the runtime gives you:
|
|
|
452
459
|
- Relation tracking (add/remove/sync on collections).
|
|
453
460
|
- Cascades on relations: `'all' | 'persist' | 'remove' | 'link'`.
|
|
454
461
|
- Single flush: `session.commit()` figures out inserts, updates, deletes, and pivot changes.
|
|
455
|
-
- Column pickers to stay DRY: `select` on the root table, `
|
|
462
|
+
- Column pickers to stay DRY: `select` on the root table, `include` (with `columns`) or `includePick` on relations, and `selectColumnsDeep` or the `sel`/`esel` helpers to build typed selection maps without repeating `table.columns.*`.
|
|
456
463
|
|
|
457
464
|
<a id="level-3"></a>
|
|
458
465
|
### Level 3: Decorator entities ✨
|
|
@@ -543,7 +550,7 @@ user.posts.add({ title: 'From decorators' });
|
|
|
543
550
|
await session.commit();
|
|
544
551
|
```
|
|
545
552
|
|
|
546
|
-
Tip: to keep selections terse, use `select
|
|
553
|
+
Tip: to keep selections terse, use `select`, `include` (with `columns`), or the `sel`/`esel` helpers instead of spelling `table.columns.*` over and over.
|
|
547
554
|
|
|
548
555
|
This level is nice when:
|
|
549
556
|
|