metal-orm 1.0.56 → 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 +41 -33
- package/dist/index.cjs +1461 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +541 -114
- package/dist/index.d.ts +541 -114
- package/dist/index.js +1424 -195
- package/dist/index.js.map +1 -1
- package/package.json +69 -69
- package/src/codegen/naming-strategy.ts +3 -1
- package/src/codegen/typescript.ts +20 -10
- package/src/core/ast/aggregate-functions.ts +14 -0
- package/src/core/ast/builders.ts +38 -20
- package/src/core/ast/expression-builders.ts +70 -2
- package/src/core/ast/expression-nodes.ts +305 -274
- package/src/core/ast/expression-visitor.ts +11 -1
- package/src/core/ast/expression.ts +4 -0
- package/src/core/ast/query.ts +3 -0
- package/src/core/ddl/introspect/catalogs/mysql.ts +5 -0
- package/src/core/ddl/introspect/catalogs/sqlite.ts +3 -0
- package/src/core/ddl/introspect/functions/mssql.ts +13 -0
- package/src/core/ddl/introspect/mssql.ts +4 -0
- package/src/core/ddl/introspect/mysql.ts +4 -0
- package/src/core/ddl/introspect/sqlite.ts +4 -0
- package/src/core/dialect/abstract.ts +552 -531
- package/src/core/dialect/base/function-table-formatter.ts +9 -30
- package/src/core/dialect/base/sql-dialect.ts +24 -0
- package/src/core/dialect/mssql/functions.ts +40 -2
- package/src/core/dialect/mysql/functions.ts +16 -2
- package/src/core/dialect/postgres/functions.ts +66 -2
- package/src/core/dialect/postgres/index.ts +17 -4
- package/src/core/dialect/postgres/table-functions.ts +27 -0
- package/src/core/dialect/sqlite/functions.ts +34 -0
- package/src/core/dialect/sqlite/index.ts +17 -1
- package/src/core/driver/database-driver.ts +9 -1
- package/src/core/driver/mssql-driver.ts +3 -0
- package/src/core/driver/mysql-driver.ts +3 -0
- package/src/core/driver/postgres-driver.ts +3 -0
- package/src/core/driver/sqlite-driver.ts +3 -0
- package/src/core/execution/executors/mssql-executor.ts +5 -0
- package/src/core/execution/executors/mysql-executor.ts +5 -0
- package/src/core/execution/executors/postgres-executor.ts +5 -0
- package/src/core/execution/executors/sqlite-executor.ts +5 -0
- package/src/core/functions/array.ts +26 -0
- package/src/core/functions/control-flow.ts +69 -0
- package/src/core/functions/datetime.ts +50 -0
- package/src/core/functions/definitions/aggregate.ts +16 -0
- package/src/core/functions/definitions/control-flow.ts +24 -0
- package/src/core/functions/definitions/datetime.ts +36 -0
- package/src/core/functions/definitions/helpers.ts +29 -0
- package/src/core/functions/definitions/json.ts +49 -0
- package/src/core/functions/definitions/numeric.ts +55 -0
- package/src/core/functions/definitions/string.ts +43 -0
- package/src/core/functions/function-registry.ts +48 -0
- package/src/core/functions/group-concat-helpers.ts +57 -0
- package/src/core/functions/json.ts +38 -0
- package/src/core/functions/numeric.ts +14 -0
- package/src/core/functions/standard-strategy.ts +86 -115
- package/src/core/functions/standard-table-strategy.ts +13 -0
- package/src/core/functions/table-types.ts +15 -0
- package/src/core/functions/text.ts +57 -0
- package/src/core/sql/sql.ts +59 -38
- package/src/decorators/bootstrap.ts +41 -4
- package/src/index.ts +18 -11
- 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/hydration-context.ts +10 -0
- package/src/orm/identity-map.ts +19 -0
- package/src/orm/interceptor-pipeline.ts +4 -0
- package/src/orm/lazy-batch.ts +237 -54
- package/src/orm/relations/belongs-to.ts +19 -2
- package/src/orm/relations/has-many.ts +23 -9
- package/src/orm/relations/has-one.ts +19 -2
- package/src/orm/relations/many-to-many.ts +59 -4
- 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 +124 -106
- package/src/schema/table-guards.ts +6 -0
- package/src/schema/types.ts +109 -85
package/README.md
CHANGED
|
@@ -74,21 +74,21 @@ MetalORM is a TypeScript-first, AST-driven SQL toolkit you can dial up or down d
|
|
|
74
74
|
<a id="documentation"></a>
|
|
75
75
|
## Documentation 📚
|
|
76
76
|
|
|
77
|
-
Full docs live in the `docs/` folder:
|
|
78
|
-
|
|
79
|
-
- [Introduction](https://github.com/celsowm/metal-orm/blob/main/docs/index.md)
|
|
80
|
-
- [Getting Started](https://github.com/celsowm/metal-orm/blob/main/docs/getting-started.md)
|
|
81
|
-
- [Level 3 Backend Tutorial](https://github.com/celsowm/metal-orm/blob/main/docs/level-3-backend-tutorial.md)
|
|
82
|
-
- [Schema Definition](https://github.com/celsowm/metal-orm/blob/main/docs/schema-definition.md)
|
|
83
|
-
- [Query Builder](https://github.com/celsowm/metal-orm/blob/main/docs/query-builder.md)
|
|
84
|
-
- [DML Operations](https://github.com/celsowm/metal-orm/blob/main/docs/dml-operations.md)
|
|
85
|
-
- [Hydration & Entities](https://github.com/celsowm/metal-orm/blob/main/docs/hydration.md)
|
|
86
|
-
- [Runtime & Unit of Work](https://github.com/celsowm/metal-orm/blob/main/docs/runtime.md)
|
|
87
|
-
- [Save Graph](https://github.com/celsowm/metal-orm/blob/main/docs/save-graph.md)
|
|
88
|
-
- [Advanced Features](https://github.com/celsowm/metal-orm/blob/main/docs/advanced-features.md)
|
|
89
|
-
- [Multi-Dialect Support](https://github.com/celsowm/metal-orm/blob/main/docs/multi-dialect-support.md)
|
|
90
|
-
- [Schema Generation (DDL)](https://github.com/celsowm/metal-orm/blob/main/docs/schema-generation.md)
|
|
91
|
-
- [API Reference](https://github.com/celsowm/metal-orm/blob/main/docs/api-reference.md)
|
|
77
|
+
Full docs live in the `docs/` folder:
|
|
78
|
+
|
|
79
|
+
- [Introduction](https://github.com/celsowm/metal-orm/blob/main/docs/index.md)
|
|
80
|
+
- [Getting Started](https://github.com/celsowm/metal-orm/blob/main/docs/getting-started.md)
|
|
81
|
+
- [Level 3 Backend Tutorial](https://github.com/celsowm/metal-orm/blob/main/docs/level-3-backend-tutorial.md)
|
|
82
|
+
- [Schema Definition](https://github.com/celsowm/metal-orm/blob/main/docs/schema-definition.md)
|
|
83
|
+
- [Query Builder](https://github.com/celsowm/metal-orm/blob/main/docs/query-builder.md)
|
|
84
|
+
- [DML Operations](https://github.com/celsowm/metal-orm/blob/main/docs/dml-operations.md)
|
|
85
|
+
- [Hydration & Entities](https://github.com/celsowm/metal-orm/blob/main/docs/hydration.md)
|
|
86
|
+
- [Runtime & Unit of Work](https://github.com/celsowm/metal-orm/blob/main/docs/runtime.md)
|
|
87
|
+
- [Save Graph](https://github.com/celsowm/metal-orm/blob/main/docs/save-graph.md)
|
|
88
|
+
- [Advanced Features](https://github.com/celsowm/metal-orm/blob/main/docs/advanced-features.md)
|
|
89
|
+
- [Multi-Dialect Support](https://github.com/celsowm/metal-orm/blob/main/docs/multi-dialect-support.md)
|
|
90
|
+
- [Schema Generation (DDL)](https://github.com/celsowm/metal-orm/blob/main/docs/schema-generation.md)
|
|
91
|
+
- [API Reference](https://github.com/celsowm/metal-orm/blob/main/docs/api-reference.md)
|
|
92
92
|
- [DB ➜ TS Type Mapping](https://github.com/celsowm/metal-orm/blob/main/docs/db-to-ts-types.md)
|
|
93
93
|
|
|
94
94
|
---
|
|
@@ -102,8 +102,9 @@ Full docs live in the `docs/` folder:
|
|
|
102
102
|
- **Typed temporal columns**: `col.date()` / `col.datetime()` / `col.timestamp()` default to `string` but accept a generic when your driver returns `Date` (e.g. `col.date<Date>()`).
|
|
103
103
|
- **Fluent query builder** over a real SQL AST
|
|
104
104
|
(`SelectQueryBuilder`, `InsertQueryBuilder`, `UpdateQueryBuilder`, `DeleteQueryBuilder`).
|
|
105
|
-
- **Advanced SQL**: CTEs, aggregates, window functions, subqueries, JSON, CASE, EXISTS.
|
|
106
|
-
- **
|
|
105
|
+
- **Advanced SQL**: CTEs, aggregates, window functions, subqueries, bitwise operators (`&`, `|`, `^`, `<<`, `>>`), JSON, CASE, EXISTS, and the full SQL function catalog (e.g. `STDDEV`, `VARIANCE`, `LOG2`, `CBRT`, `COALESCE`, `NULLIF`, `GREATEST`, `LEAST`, `IFNULL`, `LOCALTIME`, `LOCALTIMESTAMP`, `AGE`).
|
|
106
|
+
- **Table-valued functions**: use the new `tvf(key, …)` helper when you want portable intents such as `ARRAY_UNNEST`, letting the dialects’ `TableFunctionStrategy` renderers emit dialect-specific syntax (`LATERAL`/`WITH ORDINALITY`, alias validation, quoting, etc.). `fnTable()` remains available as the raw escape hatch when you need to emit a specific SQL function directly.
|
|
107
|
+
- **String helpers**: `lower`, `upper`, `trim`, `ltrim/rtrim`, `concat/concatWs`, `substr/left/right`, `position/instr/locate`, `replace`, `repeat`, `lpad/rpad`, `space`, and more with dialect-aware rendering.
|
|
107
108
|
- **Set operations**: `union`, `unionAll`, `intersect`, `except` across all dialects (ORDER/LIMIT apply to the combined result; hydration is disabled for compound queries so rows are returned as-is without collapsing duplicates).
|
|
108
109
|
- **Expression builders**: `eq`, `and`, `or`, `between`, `inList`, `exists`, `jsonPath`, `caseWhen`, window functions like `rowNumber`, `rank`, `lag`, `lead`, etc., all backed by typed AST nodes.
|
|
109
110
|
- **Relation-aware hydration**: turn flat rows into nested objects (`user.posts`, `user.roles`, etc.) using a hydration plan derived from the AST metadata.
|
|
@@ -230,10 +231,10 @@ todos.columns.done.default = false;
|
|
|
230
231
|
const t = tableRef(todos);
|
|
231
232
|
|
|
232
233
|
// 2) Build a simple query
|
|
233
|
-
const listOpenTodos = selectFrom(todos)
|
|
234
|
-
.select('id', 'title', 'done')
|
|
235
|
-
.where(eq(t.done, false))
|
|
236
|
-
.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');
|
|
237
238
|
|
|
238
239
|
// 3) Compile to SQL + params
|
|
239
240
|
const dialect = new MySqlDialect();
|
|
@@ -243,16 +244,23 @@ const { sql, params } = listOpenTodos.compile(dialect);
|
|
|
243
244
|
const connection = await mysql.createConnection({ /* ... */ });
|
|
244
245
|
const [rows] = await connection.execute(sql, params);
|
|
245
246
|
|
|
246
|
-
console.log(rows);
|
|
247
|
-
// [
|
|
248
|
-
// { id: 1, title: 'Write docs', done: 0 },
|
|
249
|
-
// { id: 2, title: 'Ship feature', done: 0 },
|
|
250
|
-
// ]
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
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
|
+
```
|
|
254
253
|
|
|
255
|
-
If you
|
|
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.
|
|
262
|
+
|
|
263
|
+
If you are using the Level 2 runtime (`OrmSession`), `SelectQueryBuilder` also provides `count(session)` and `executePaged(session, { page, pageSize })` for common pagination patterns.
|
|
256
264
|
|
|
257
265
|
#### Column pickers (preferred selection helpers)
|
|
258
266
|
|
|
@@ -267,7 +275,7 @@ const listOpenTodos = selectFrom(todos)
|
|
|
267
275
|
.orderBy(t.id, 'ASC');
|
|
268
276
|
```
|
|
269
277
|
|
|
270
|
-
`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.
|
|
271
279
|
|
|
272
280
|
#### Ergonomic column access (opt-in) with `tableRef`
|
|
273
281
|
|
|
@@ -451,7 +459,7 @@ What the runtime gives you:
|
|
|
451
459
|
- Relation tracking (add/remove/sync on collections).
|
|
452
460
|
- Cascades on relations: `'all' | 'persist' | 'remove' | 'link'`.
|
|
453
461
|
- Single flush: `session.commit()` figures out inserts, updates, deletes, and pivot changes.
|
|
454
|
-
- 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.*`.
|
|
455
463
|
|
|
456
464
|
<a id="level-3"></a>
|
|
457
465
|
### Level 3: Decorator entities ✨
|
|
@@ -542,7 +550,7 @@ user.posts.add({ title: 'From decorators' });
|
|
|
542
550
|
await session.commit();
|
|
543
551
|
```
|
|
544
552
|
|
|
545
|
-
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.
|
|
546
554
|
|
|
547
555
|
This level is nice when:
|
|
548
556
|
|