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 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
- That’s it: schema, query, SQL, done.
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`, `selectRelationColumns`, `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.
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, `selectRelationColumns` / `includePick` on relations, and `selectColumnsDeep` or the `sel`/`esel` helpers to build typed selection maps without repeating `table.columns.*`.
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`/`selectRelationColumns` or the `sel`/`esel` helpers instead of spelling `table.columns.*` over and over.
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