metal-orm 1.0.2 → 1.0.4
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 +20 -0
- package/package.json +1 -1
- package/src/ast/expression.ts +433 -175
- package/src/ast/join.ts +8 -1
- package/src/ast/query.ts +64 -9
- package/src/builder/hydration-manager.ts +42 -11
- package/src/builder/hydration-planner.ts +80 -31
- package/src/builder/operations/column-selector.ts +37 -1
- package/src/builder/operations/cte-manager.ts +16 -0
- package/src/builder/operations/filter-manager.ts +32 -0
- package/src/builder/operations/join-manager.ts +17 -7
- package/src/builder/operations/pagination-manager.ts +19 -0
- package/src/builder/operations/relation-manager.ts +58 -3
- package/src/builder/query-ast-service.ts +100 -29
- package/src/builder/relation-conditions.ts +30 -1
- package/src/builder/relation-projection-helper.ts +43 -1
- package/src/builder/relation-service.ts +68 -13
- package/src/builder/relation-types.ts +6 -0
- package/src/builder/select-query-builder-deps.ts +64 -3
- package/src/builder/select-query-state.ts +72 -0
- package/src/builder/select.ts +166 -0
- package/src/codegen/typescript.ts +142 -44
- package/src/constants/sql-operator-config.ts +36 -0
- package/src/constants/sql.ts +125 -58
- package/src/dialect/abstract.ts +97 -22
- package/src/dialect/mssql/index.ts +27 -0
- package/src/dialect/mysql/index.ts +22 -0
- package/src/dialect/postgres/index.ts +22 -0
- package/src/dialect/sqlite/index.ts +22 -0
- package/src/runtime/als.ts +15 -1
- package/src/runtime/hydration.ts +20 -15
- package/src/schema/column.ts +45 -5
- package/src/schema/relation.ts +49 -2
- package/src/schema/table.ts +27 -3
- package/src/utils/join-node.ts +20 -0
- package/src/utils/raw-column-parser.ts +32 -0
- package/src/utils/relation-alias.ts +43 -0
package/README.md
CHANGED
|
@@ -84,6 +84,26 @@ const hydrated = hydrateRows(rows as Record<string, unknown>[], builder.getHydra
|
|
|
84
84
|
console.log(hydrated);
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
## Helper idea
|
|
88
|
+
|
|
89
|
+
If you find yourself compiling/executing the same way across your app, wrap the compiler + driver interaction in a tiny helper instead of repeating it:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
async function runMetalQuery<T>(
|
|
93
|
+
builder: SelectQueryBuilder<T>,
|
|
94
|
+
connection: mysql.Connection,
|
|
95
|
+
dialect = new MySqlDialect()
|
|
96
|
+
) {
|
|
97
|
+
const { sql, params } = builder.compile(dialect);
|
|
98
|
+
const [rows] = await connection.execute(sql, params);
|
|
99
|
+
return hydrateRows(rows as Record<string, unknown>[], builder.getHydrationPlan());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const results = await runMetalQuery(builder, connection);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This keeps the ORM-focused pieces in one place while letting you reuse any pooling/transaction strategy the driver provides.
|
|
106
|
+
|
|
87
107
|
## Contributing
|
|
88
108
|
|
|
89
109
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
|