metal-orm 1.0.59 → 1.0.62

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
@@ -149,7 +149,7 @@ If you like explicit model classes, you can add a thin decorator layer on top of
149
149
  - `@BelongsTo({ target, foreignKey, ... })`
150
150
  - `@BelongsToMany({ target, pivotTable, ... })`
151
151
  - `bootstrapEntities()` scans metadata, builds `TableDef`s, wires relations with the same `hasOne` / `hasMany` / `belongsTo` / `belongsToMany` helpers you would use manually, and returns the resulting tables. (If you forget to call it, `getTableDefFromEntity` / `selectFromEntity` will bootstrap lazily on first use, but bootstrapping once at startup lets you reuse the same table defs and generate schema SQL.)
152
- - `selectFromEntity(MyEntity)` lets you start a `SelectQueryBuilder` directly from the class.
152
+ - `selectFromEntity(MyEntity)` lets you start a `SelectQueryBuilder` directly from the class. By default, `execute(session)` returns actual entity instances with all columns selected.
153
153
  - **Generate entities from an existing DB**: `npx metal-orm-gen -- --dialect=postgres --url=$DATABASE_URL --schema=public --out=src/entities.ts` introspects your schema and spits out `@Entity` / `@Column` classes you can immediately `bootstrapEntities()` with.
154
154
 
155
155
  You don’t have to use decorators, but when you do, you’re still on the same AST + dialect + runtime foundation.
@@ -465,14 +465,14 @@ What the runtime gives you:
465
465
  <a id="level-3"></a>
466
466
  ### Level 3: Decorator entities ✨
467
467
 
468
- Finally, you can describe your models with decorators and still use the same runtime and query builder.
469
-
470
- The decorator layer is built on the TC39 Stage 3 standard (TypeScript 5.6+), so you simply decorate class fields (or accessors if you need custom logic) and the standard `ClassFieldDecoratorContext` keeps a metadata bag on `context.metadata`/`Symbol.metadata`. `@Entity` reads that bag when it runs and builds your `TableDef`s—no `experimentalDecorators`, parameter decorators, or extra polyfills required.
471
-
472
- ```ts
473
- import mysql from 'mysql2/promise';
474
- import {
475
- Orm,
468
+ Finally, you can describe your models with decorators and still use the same runtime and query builder.
469
+
470
+ The decorator layer is built on the TC39 Stage 3 standard (TypeScript 5.6+), so you simply decorate class fields (or accessors if you need custom logic) and the standard `ClassFieldDecoratorContext` keeps a metadata bag on `context.metadata`/`Symbol.metadata`. `@Entity` reads that bag when it runs and builds your `TableDef`s—no `experimentalDecorators`, parameter decorators, or extra polyfills required.
471
+
472
+ ```ts
473
+ import mysql from 'mysql2/promise';
474
+ import {
475
+ Orm,
476
476
  OrmSession,
477
477
  MySqlDialect,
478
478
  col,
@@ -547,13 +547,17 @@ const [user] = await selectFromEntity(User)
547
547
  .select('id', 'name')
548
548
  .includeLazy('posts')
549
549
  .where(eq(U.id, 1))
550
- .execute(session);
550
+ .execute(session); // user is an actual instance of the User class!
551
+
552
+ // Use executePlain() if you want raw POJOs instead of class instances
553
+ const [rawUser] = await selectFromEntity(User).executePlain(session);
551
554
 
552
555
  user.posts.add({ title: 'From decorators' });
553
556
  await session.commit();
554
557
  ```
555
558
 
556
- Tip: to keep selections terse, use `select`, `include` (with `columns`), or the `sel`/`esel` helpers instead of spelling `table.columns.*` over and over.
559
+ Tip: to keep selections terse, use `select`, `include` (with `columns`), or the `sel`/`esel` helpers instead of spelling `table.columns.*` over and over. By default, `selectFromEntity` selects all columns if you don't specify any.
560
+
557
561
 
558
562
  This level is nice when:
559
563