metal-orm 1.0.86 → 1.0.87
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/dist/index.cjs +35 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -16
- package/dist/index.d.ts +13 -16
- package/dist/index.js +35 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/orm/execute.ts +12 -26
- package/src/query-builder/select/select-operations.ts +4 -12
- package/src/query-builder/select.ts +23 -25
package/dist/index.cjs
CHANGED
|
@@ -6446,9 +6446,9 @@ var flattenResults = (results) => {
|
|
|
6446
6446
|
}
|
|
6447
6447
|
return rows;
|
|
6448
6448
|
};
|
|
6449
|
-
var executeWithContexts = async (execCtx, entityCtx, qb
|
|
6449
|
+
var executeWithContexts = async (execCtx, entityCtx, qb) => {
|
|
6450
6450
|
const ast = qb.getAST();
|
|
6451
|
-
const compiled =
|
|
6451
|
+
const compiled = execCtx.dialect.compileSelect(ast);
|
|
6452
6452
|
const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6453
6453
|
const rows = flattenResults(executed);
|
|
6454
6454
|
const lazyRelations = qb.getLazyRelations();
|
|
@@ -6466,9 +6466,9 @@ var executeWithContexts = async (execCtx, entityCtx, qb, options) => {
|
|
|
6466
6466
|
await preloadRelationIncludes(entities, includeTree);
|
|
6467
6467
|
return entities;
|
|
6468
6468
|
};
|
|
6469
|
-
var executePlainWithContexts = async (execCtx, qb
|
|
6469
|
+
var executePlainWithContexts = async (execCtx, qb) => {
|
|
6470
6470
|
const ast = qb.getAST();
|
|
6471
|
-
const compiled =
|
|
6471
|
+
const compiled = execCtx.dialect.compileSelect(ast);
|
|
6472
6472
|
const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6473
6473
|
const rows = flattenResults(executed);
|
|
6474
6474
|
if (ast.setOps && ast.setOps.length > 0) {
|
|
@@ -6476,21 +6476,21 @@ var executePlainWithContexts = async (execCtx, qb, options) => {
|
|
|
6476
6476
|
}
|
|
6477
6477
|
return hydrateRows(rows, qb.getHydrationPlan());
|
|
6478
6478
|
};
|
|
6479
|
-
async function executeHydrated(session, qb
|
|
6480
|
-
return executeWithContexts(session.getExecutionContext(), session, qb
|
|
6479
|
+
async function executeHydrated(session, qb) {
|
|
6480
|
+
return executeWithContexts(session.getExecutionContext(), session, qb);
|
|
6481
6481
|
}
|
|
6482
|
-
async function executeHydratedPlain(session, qb
|
|
6483
|
-
return executePlainWithContexts(session.getExecutionContext(), qb
|
|
6482
|
+
async function executeHydratedPlain(session, qb) {
|
|
6483
|
+
return executePlainWithContexts(session.getExecutionContext(), qb);
|
|
6484
6484
|
}
|
|
6485
|
-
async function executeHydratedWithContexts(execCtx, hydCtx, qb
|
|
6485
|
+
async function executeHydratedWithContexts(execCtx, hydCtx, qb) {
|
|
6486
6486
|
const entityCtx = hydCtx.entityContext;
|
|
6487
6487
|
if (!entityCtx) {
|
|
6488
6488
|
throw new Error("Hydration context is missing an EntityContext");
|
|
6489
6489
|
}
|
|
6490
|
-
return executeWithContexts(execCtx, entityCtx, qb
|
|
6490
|
+
return executeWithContexts(execCtx, entityCtx, qb);
|
|
6491
6491
|
}
|
|
6492
|
-
async function executeHydratedPlainWithContexts(execCtx, qb
|
|
6493
|
-
return executePlainWithContexts(execCtx, qb
|
|
6492
|
+
async function executeHydratedPlainWithContexts(execCtx, qb) {
|
|
6493
|
+
return executePlainWithContexts(execCtx, qb);
|
|
6494
6494
|
}
|
|
6495
6495
|
var loadLazyRelationsForTable = async (ctx, table, lazyRelations, lazyRelationOptions) => {
|
|
6496
6496
|
if (!lazyRelations.length) return;
|
|
@@ -6691,7 +6691,7 @@ function applyOrderBy(context, predicateFacet, term, directionOrOptions) {
|
|
|
6691
6691
|
const dir = options.direction ?? ORDER_DIRECTIONS.ASC;
|
|
6692
6692
|
return predicateFacet.orderBy(context, term, dir, options.nulls, options.collation);
|
|
6693
6693
|
}
|
|
6694
|
-
async function executeCount(context, env, session
|
|
6694
|
+
async function executeCount(context, env, session) {
|
|
6695
6695
|
const unpagedAst = {
|
|
6696
6696
|
...context.state.ast,
|
|
6697
6697
|
orderBy: void 0,
|
|
@@ -6711,7 +6711,7 @@ async function executeCount(context, env, session, options) {
|
|
|
6711
6711
|
joins: []
|
|
6712
6712
|
};
|
|
6713
6713
|
const execCtx = session.getExecutionContext();
|
|
6714
|
-
const compiled =
|
|
6714
|
+
const compiled = execCtx.dialect.compileSelect(countQuery);
|
|
6715
6715
|
const results = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6716
6716
|
const value = results[0]?.values?.[0]?.[0];
|
|
6717
6717
|
if (typeof value === "number") return value;
|
|
@@ -6719,7 +6719,7 @@ async function executeCount(context, env, session, options) {
|
|
|
6719
6719
|
if (typeof value === "string") return Number(value);
|
|
6720
6720
|
return value === null || value === void 0 ? 0 : Number(value);
|
|
6721
6721
|
}
|
|
6722
|
-
async function executePagedQuery(builder, session, options, countCallback
|
|
6722
|
+
async function executePagedQuery(builder, session, options, countCallback) {
|
|
6723
6723
|
const { page, pageSize } = options;
|
|
6724
6724
|
if (!Number.isInteger(page) || page < 1) {
|
|
6725
6725
|
throw new Error("executePaged: page must be an integer >= 1");
|
|
@@ -6729,7 +6729,7 @@ async function executePagedQuery(builder, session, options, countCallback, param
|
|
|
6729
6729
|
}
|
|
6730
6730
|
const offset = (page - 1) * pageSize;
|
|
6731
6731
|
const totalItems = await countCallback(session);
|
|
6732
|
-
const items = await builder.limit(pageSize).offset(offset).execute(session
|
|
6732
|
+
const items = await builder.limit(pageSize).offset(offset).execute(session);
|
|
6733
6733
|
return { items, totalItems, page, pageSize };
|
|
6734
6734
|
}
|
|
6735
6735
|
function buildWhereHasPredicate(env, context, relationFacet, createChildBuilder, relationName, callbackOrOptions, maybeOptions, negate = false) {
|
|
@@ -8520,8 +8520,7 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8520
8520
|
* Validates that the query does not contain Param operands.
|
|
8521
8521
|
* Param proxies are only for schema generation, not execution.
|
|
8522
8522
|
*/
|
|
8523
|
-
validateNoParamOperands(
|
|
8524
|
-
if (options?.allowParamOperands) return;
|
|
8523
|
+
validateNoParamOperands() {
|
|
8525
8524
|
const ast = this.context.hydration.applyToAst(this.context.state.ast);
|
|
8526
8525
|
const paramName = findFirstParamOperandName(ast);
|
|
8527
8526
|
if (paramName) {
|
|
@@ -8540,13 +8539,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8540
8539
|
* // users is User[]
|
|
8541
8540
|
* users[0] instanceof User; // true
|
|
8542
8541
|
*/
|
|
8543
|
-
async execute(ctx
|
|
8544
|
-
this.validateNoParamOperands(
|
|
8542
|
+
async execute(ctx) {
|
|
8543
|
+
this.validateNoParamOperands();
|
|
8545
8544
|
if (this.entityConstructor) {
|
|
8546
|
-
return this.executeAs(this.entityConstructor, ctx
|
|
8545
|
+
return this.executeAs(this.entityConstructor, ctx);
|
|
8547
8546
|
}
|
|
8548
8547
|
const builder = this.ensureDefaultSelection();
|
|
8549
|
-
return executeHydrated(ctx, builder
|
|
8548
|
+
return executeHydrated(ctx, builder);
|
|
8550
8549
|
}
|
|
8551
8550
|
/**
|
|
8552
8551
|
* Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
|
|
@@ -8559,10 +8558,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8559
8558
|
* // rows is EntityInstance<UserTable>[] (plain objects)
|
|
8560
8559
|
* rows[0] instanceof User; // false
|
|
8561
8560
|
*/
|
|
8562
|
-
async executePlain(ctx
|
|
8563
|
-
this.validateNoParamOperands(
|
|
8561
|
+
async executePlain(ctx) {
|
|
8562
|
+
this.validateNoParamOperands();
|
|
8564
8563
|
const builder = this.ensureDefaultSelection();
|
|
8565
|
-
const rows = await executeHydratedPlain(ctx, builder
|
|
8564
|
+
const rows = await executeHydratedPlain(ctx, builder);
|
|
8566
8565
|
return rows;
|
|
8567
8566
|
}
|
|
8568
8567
|
/**
|
|
@@ -8579,10 +8578,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8579
8578
|
* users[0] instanceof User; // true!
|
|
8580
8579
|
* users[0].getFullName(); // works!
|
|
8581
8580
|
*/
|
|
8582
|
-
async executeAs(entityClass, ctx
|
|
8583
|
-
this.validateNoParamOperands(
|
|
8581
|
+
async executeAs(entityClass, ctx) {
|
|
8582
|
+
this.validateNoParamOperands();
|
|
8584
8583
|
const builder = this.ensureDefaultSelection();
|
|
8585
|
-
const results = await executeHydrated(ctx, builder
|
|
8584
|
+
const results = await executeHydrated(ctx, builder);
|
|
8586
8585
|
return materializeAs(entityClass, results);
|
|
8587
8586
|
}
|
|
8588
8587
|
/**
|
|
@@ -8591,9 +8590,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8591
8590
|
* @example
|
|
8592
8591
|
* const total = await qb.count(session);
|
|
8593
8592
|
*/
|
|
8594
|
-
async count(session
|
|
8595
|
-
this.validateNoParamOperands(
|
|
8596
|
-
return executeCount(this.context, this.env, session
|
|
8593
|
+
async count(session) {
|
|
8594
|
+
this.validateNoParamOperands();
|
|
8595
|
+
return executeCount(this.context, this.env, session);
|
|
8597
8596
|
}
|
|
8598
8597
|
/**
|
|
8599
8598
|
* Executes the query and returns both the paged items and the total.
|
|
@@ -8602,9 +8601,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8602
8601
|
* const { items, totalItems, page, pageSize } = await qb.executePaged(session, { page: 1, pageSize: 20 });
|
|
8603
8602
|
*/
|
|
8604
8603
|
async executePaged(session, options) {
|
|
8605
|
-
this.validateNoParamOperands(
|
|
8604
|
+
this.validateNoParamOperands();
|
|
8606
8605
|
const builder = this.ensureDefaultSelection();
|
|
8607
|
-
return executePagedQuery(builder, session, options, (sess) => builder.count(sess
|
|
8606
|
+
return executePagedQuery(builder, session, options, (sess) => builder.count(sess));
|
|
8608
8607
|
}
|
|
8609
8608
|
/**
|
|
8610
8609
|
* Executes the query with provided execution and hydration contexts
|
|
@@ -8616,10 +8615,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8616
8615
|
* const hydCtx = new HydrationContext();
|
|
8617
8616
|
* const users = await qb.executeWithContexts(execCtx, hydCtx);
|
|
8618
8617
|
*/
|
|
8619
|
-
async executeWithContexts(execCtx, hydCtx
|
|
8620
|
-
this.validateNoParamOperands(
|
|
8618
|
+
async executeWithContexts(execCtx, hydCtx) {
|
|
8619
|
+
this.validateNoParamOperands();
|
|
8621
8620
|
const builder = this.ensureDefaultSelection();
|
|
8622
|
-
const results = await executeHydratedWithContexts(execCtx, hydCtx, builder
|
|
8621
|
+
const results = await executeHydratedWithContexts(execCtx, hydCtx, builder);
|
|
8623
8622
|
if (this.entityConstructor) {
|
|
8624
8623
|
return materializeAs(this.entityConstructor, results);
|
|
8625
8624
|
}
|