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.d.cts
CHANGED
|
@@ -3980,7 +3980,7 @@ type SelectionValueType<TValue> = TValue extends TypedExpression<infer TRuntime>
|
|
|
3980
3980
|
type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
|
|
3981
3981
|
[K in keyof TSelection]: SelectionValueType<TSelection[K]>;
|
|
3982
3982
|
};
|
|
3983
|
-
type
|
|
3983
|
+
type ParamOperandCompileOptions = {
|
|
3984
3984
|
allowParamOperands?: boolean;
|
|
3985
3985
|
};
|
|
3986
3986
|
type SelectionFromKeys<TTable extends TableDef, K extends keyof TTable['columns'] & string> = Pick<InferRow<TTable>, K>;
|
|
@@ -4349,7 +4349,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4349
4349
|
* // users is User[]
|
|
4350
4350
|
* users[0] instanceof User; // true
|
|
4351
4351
|
*/
|
|
4352
|
-
execute(ctx: OrmSession
|
|
4352
|
+
execute(ctx: OrmSession): Promise<T[]>;
|
|
4353
4353
|
/**
|
|
4354
4354
|
* Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
|
|
4355
4355
|
* Use this if you want raw data even when using selectFromEntity.
|
|
@@ -4361,7 +4361,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4361
4361
|
* // rows is EntityInstance<UserTable>[] (plain objects)
|
|
4362
4362
|
* rows[0] instanceof User; // false
|
|
4363
4363
|
*/
|
|
4364
|
-
executePlain(ctx: OrmSession
|
|
4364
|
+
executePlain(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
|
|
4365
4365
|
/**
|
|
4366
4366
|
* Executes the query and returns results as real class instances.
|
|
4367
4367
|
* Unlike execute(), this returns actual instances of the decorated entity class
|
|
@@ -4376,14 +4376,14 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4376
4376
|
* users[0] instanceof User; // true!
|
|
4377
4377
|
* users[0].getFullName(); // works!
|
|
4378
4378
|
*/
|
|
4379
|
-
executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession
|
|
4379
|
+
executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession): Promise<TEntity[]>;
|
|
4380
4380
|
/**
|
|
4381
4381
|
* Executes a count query for the current builder without LIMIT/OFFSET clauses.
|
|
4382
4382
|
*
|
|
4383
4383
|
* @example
|
|
4384
4384
|
* const total = await qb.count(session);
|
|
4385
4385
|
*/
|
|
4386
|
-
count(session: OrmSession
|
|
4386
|
+
count(session: OrmSession): Promise<number>;
|
|
4387
4387
|
/**
|
|
4388
4388
|
* Executes the query and returns both the paged items and the total.
|
|
4389
4389
|
*
|
|
@@ -4393,7 +4393,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4393
4393
|
executePaged(session: OrmSession, options: {
|
|
4394
4394
|
page: number;
|
|
4395
4395
|
pageSize: number;
|
|
4396
|
-
}
|
|
4396
|
+
}): Promise<PaginatedResult<T>>;
|
|
4397
4397
|
/**
|
|
4398
4398
|
* Executes the query with provided execution and hydration contexts
|
|
4399
4399
|
* @param execCtx - Execution context
|
|
@@ -4404,7 +4404,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4404
4404
|
* const hydCtx = new HydrationContext();
|
|
4405
4405
|
* const users = await qb.executeWithContexts(execCtx, hydCtx);
|
|
4406
4406
|
*/
|
|
4407
|
-
executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext
|
|
4407
|
+
executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<T[]>;
|
|
4408
4408
|
/**
|
|
4409
4409
|
* Adds a WHERE condition to the query
|
|
4410
4410
|
* @param expr - Expression for the WHERE clause
|
|
@@ -4576,7 +4576,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4576
4576
|
* .compile('postgres');
|
|
4577
4577
|
* console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
|
|
4578
4578
|
*/
|
|
4579
|
-
compile(dialect: SelectDialectInput, options?:
|
|
4579
|
+
compile(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): CompiledQuery;
|
|
4580
4580
|
/**
|
|
4581
4581
|
* Converts the query to SQL string for a specific dialect
|
|
4582
4582
|
* @param dialect - Database dialect to generate SQL for
|
|
@@ -4587,7 +4587,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4587
4587
|
* .toSql('postgres');
|
|
4588
4588
|
* console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
|
|
4589
4589
|
*/
|
|
4590
|
-
toSql(dialect: SelectDialectInput, options?:
|
|
4590
|
+
toSql(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): string;
|
|
4591
4591
|
/**
|
|
4592
4592
|
* Gets hydration plan for query
|
|
4593
4593
|
* @returns Hydration plan or undefined if none exists
|
|
@@ -6767,9 +6767,6 @@ declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undef
|
|
|
6767
6767
|
toJSON(): TTarget[];
|
|
6768
6768
|
}
|
|
6769
6769
|
|
|
6770
|
-
type ParamOperandOptions = {
|
|
6771
|
-
allowParamOperands?: boolean;
|
|
6772
|
-
};
|
|
6773
6770
|
/**
|
|
6774
6771
|
* Executes a hydrated query using the ORM session.
|
|
6775
6772
|
* @template TTable - The table type
|
|
@@ -6777,7 +6774,7 @@ type ParamOperandOptions = {
|
|
|
6777
6774
|
* @param qb - The select query builder
|
|
6778
6775
|
* @returns Promise resolving to array of entity instances
|
|
6779
6776
|
*/
|
|
6780
|
-
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable
|
|
6777
|
+
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
6781
6778
|
/**
|
|
6782
6779
|
* Executes a hydrated query and returns plain row objects (no entity proxies).
|
|
6783
6780
|
* @template TTable - The table type
|
|
@@ -6785,7 +6782,7 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
|
|
|
6785
6782
|
* @param qb - The select query builder
|
|
6786
6783
|
* @returns Promise resolving to array of plain row objects
|
|
6787
6784
|
*/
|
|
6788
|
-
declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable
|
|
6785
|
+
declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
|
|
6789
6786
|
/**
|
|
6790
6787
|
* Executes a hydrated query using execution and hydration contexts.
|
|
6791
6788
|
* @template TTable - The table type
|
|
@@ -6794,7 +6791,7 @@ declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSessi
|
|
|
6794
6791
|
* @param qb - The select query builder
|
|
6795
6792
|
* @returns Promise resolving to array of entity instances
|
|
6796
6793
|
*/
|
|
6797
|
-
declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable
|
|
6794
|
+
declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
6798
6795
|
/**
|
|
6799
6796
|
* Executes a hydrated query using execution context and returns plain row objects.
|
|
6800
6797
|
* @template TTable - The table type
|
|
@@ -6802,7 +6799,7 @@ declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: E
|
|
|
6802
6799
|
* @param qb - The select query builder
|
|
6803
6800
|
* @returns Promise resolving to array of plain row objects
|
|
6804
6801
|
*/
|
|
6805
|
-
declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable
|
|
6802
|
+
declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
|
|
6806
6803
|
|
|
6807
6804
|
type JsonifyScalar<T> = T extends Date ? string : T;
|
|
6808
6805
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -3980,7 +3980,7 @@ type SelectionValueType<TValue> = TValue extends TypedExpression<infer TRuntime>
|
|
|
3980
3980
|
type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
|
|
3981
3981
|
[K in keyof TSelection]: SelectionValueType<TSelection[K]>;
|
|
3982
3982
|
};
|
|
3983
|
-
type
|
|
3983
|
+
type ParamOperandCompileOptions = {
|
|
3984
3984
|
allowParamOperands?: boolean;
|
|
3985
3985
|
};
|
|
3986
3986
|
type SelectionFromKeys<TTable extends TableDef, K extends keyof TTable['columns'] & string> = Pick<InferRow<TTable>, K>;
|
|
@@ -4349,7 +4349,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4349
4349
|
* // users is User[]
|
|
4350
4350
|
* users[0] instanceof User; // true
|
|
4351
4351
|
*/
|
|
4352
|
-
execute(ctx: OrmSession
|
|
4352
|
+
execute(ctx: OrmSession): Promise<T[]>;
|
|
4353
4353
|
/**
|
|
4354
4354
|
* Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
|
|
4355
4355
|
* Use this if you want raw data even when using selectFromEntity.
|
|
@@ -4361,7 +4361,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4361
4361
|
* // rows is EntityInstance<UserTable>[] (plain objects)
|
|
4362
4362
|
* rows[0] instanceof User; // false
|
|
4363
4363
|
*/
|
|
4364
|
-
executePlain(ctx: OrmSession
|
|
4364
|
+
executePlain(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
|
|
4365
4365
|
/**
|
|
4366
4366
|
* Executes the query and returns results as real class instances.
|
|
4367
4367
|
* Unlike execute(), this returns actual instances of the decorated entity class
|
|
@@ -4376,14 +4376,14 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4376
4376
|
* users[0] instanceof User; // true!
|
|
4377
4377
|
* users[0].getFullName(); // works!
|
|
4378
4378
|
*/
|
|
4379
|
-
executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession
|
|
4379
|
+
executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession): Promise<TEntity[]>;
|
|
4380
4380
|
/**
|
|
4381
4381
|
* Executes a count query for the current builder without LIMIT/OFFSET clauses.
|
|
4382
4382
|
*
|
|
4383
4383
|
* @example
|
|
4384
4384
|
* const total = await qb.count(session);
|
|
4385
4385
|
*/
|
|
4386
|
-
count(session: OrmSession
|
|
4386
|
+
count(session: OrmSession): Promise<number>;
|
|
4387
4387
|
/**
|
|
4388
4388
|
* Executes the query and returns both the paged items and the total.
|
|
4389
4389
|
*
|
|
@@ -4393,7 +4393,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4393
4393
|
executePaged(session: OrmSession, options: {
|
|
4394
4394
|
page: number;
|
|
4395
4395
|
pageSize: number;
|
|
4396
|
-
}
|
|
4396
|
+
}): Promise<PaginatedResult<T>>;
|
|
4397
4397
|
/**
|
|
4398
4398
|
* Executes the query with provided execution and hydration contexts
|
|
4399
4399
|
* @param execCtx - Execution context
|
|
@@ -4404,7 +4404,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4404
4404
|
* const hydCtx = new HydrationContext();
|
|
4405
4405
|
* const users = await qb.executeWithContexts(execCtx, hydCtx);
|
|
4406
4406
|
*/
|
|
4407
|
-
executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext
|
|
4407
|
+
executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<T[]>;
|
|
4408
4408
|
/**
|
|
4409
4409
|
* Adds a WHERE condition to the query
|
|
4410
4410
|
* @param expr - Expression for the WHERE clause
|
|
@@ -4576,7 +4576,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4576
4576
|
* .compile('postgres');
|
|
4577
4577
|
* console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
|
|
4578
4578
|
*/
|
|
4579
|
-
compile(dialect: SelectDialectInput, options?:
|
|
4579
|
+
compile(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): CompiledQuery;
|
|
4580
4580
|
/**
|
|
4581
4581
|
* Converts the query to SQL string for a specific dialect
|
|
4582
4582
|
* @param dialect - Database dialect to generate SQL for
|
|
@@ -4587,7 +4587,7 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
|
|
|
4587
4587
|
* .toSql('postgres');
|
|
4588
4588
|
* console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
|
|
4589
4589
|
*/
|
|
4590
|
-
toSql(dialect: SelectDialectInput, options?:
|
|
4590
|
+
toSql(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): string;
|
|
4591
4591
|
/**
|
|
4592
4592
|
* Gets hydration plan for query
|
|
4593
4593
|
* @returns Hydration plan or undefined if none exists
|
|
@@ -6767,9 +6767,6 @@ declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undef
|
|
|
6767
6767
|
toJSON(): TTarget[];
|
|
6768
6768
|
}
|
|
6769
6769
|
|
|
6770
|
-
type ParamOperandOptions = {
|
|
6771
|
-
allowParamOperands?: boolean;
|
|
6772
|
-
};
|
|
6773
6770
|
/**
|
|
6774
6771
|
* Executes a hydrated query using the ORM session.
|
|
6775
6772
|
* @template TTable - The table type
|
|
@@ -6777,7 +6774,7 @@ type ParamOperandOptions = {
|
|
|
6777
6774
|
* @param qb - The select query builder
|
|
6778
6775
|
* @returns Promise resolving to array of entity instances
|
|
6779
6776
|
*/
|
|
6780
|
-
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable
|
|
6777
|
+
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
6781
6778
|
/**
|
|
6782
6779
|
* Executes a hydrated query and returns plain row objects (no entity proxies).
|
|
6783
6780
|
* @template TTable - The table type
|
|
@@ -6785,7 +6782,7 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
|
|
|
6785
6782
|
* @param qb - The select query builder
|
|
6786
6783
|
* @returns Promise resolving to array of plain row objects
|
|
6787
6784
|
*/
|
|
6788
|
-
declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable
|
|
6785
|
+
declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
|
|
6789
6786
|
/**
|
|
6790
6787
|
* Executes a hydrated query using execution and hydration contexts.
|
|
6791
6788
|
* @template TTable - The table type
|
|
@@ -6794,7 +6791,7 @@ declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSessi
|
|
|
6794
6791
|
* @param qb - The select query builder
|
|
6795
6792
|
* @returns Promise resolving to array of entity instances
|
|
6796
6793
|
*/
|
|
6797
|
-
declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable
|
|
6794
|
+
declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
6798
6795
|
/**
|
|
6799
6796
|
* Executes a hydrated query using execution context and returns plain row objects.
|
|
6800
6797
|
* @template TTable - The table type
|
|
@@ -6802,7 +6799,7 @@ declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: E
|
|
|
6802
6799
|
* @param qb - The select query builder
|
|
6803
6800
|
* @returns Promise resolving to array of plain row objects
|
|
6804
6801
|
*/
|
|
6805
|
-
declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable
|
|
6802
|
+
declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
|
|
6806
6803
|
|
|
6807
6804
|
type JsonifyScalar<T> = T extends Date ? string : T;
|
|
6808
6805
|
/**
|
package/dist/index.js
CHANGED
|
@@ -6160,9 +6160,9 @@ var flattenResults = (results) => {
|
|
|
6160
6160
|
}
|
|
6161
6161
|
return rows;
|
|
6162
6162
|
};
|
|
6163
|
-
var executeWithContexts = async (execCtx, entityCtx, qb
|
|
6163
|
+
var executeWithContexts = async (execCtx, entityCtx, qb) => {
|
|
6164
6164
|
const ast = qb.getAST();
|
|
6165
|
-
const compiled =
|
|
6165
|
+
const compiled = execCtx.dialect.compileSelect(ast);
|
|
6166
6166
|
const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6167
6167
|
const rows = flattenResults(executed);
|
|
6168
6168
|
const lazyRelations = qb.getLazyRelations();
|
|
@@ -6180,9 +6180,9 @@ var executeWithContexts = async (execCtx, entityCtx, qb, options) => {
|
|
|
6180
6180
|
await preloadRelationIncludes(entities, includeTree);
|
|
6181
6181
|
return entities;
|
|
6182
6182
|
};
|
|
6183
|
-
var executePlainWithContexts = async (execCtx, qb
|
|
6183
|
+
var executePlainWithContexts = async (execCtx, qb) => {
|
|
6184
6184
|
const ast = qb.getAST();
|
|
6185
|
-
const compiled =
|
|
6185
|
+
const compiled = execCtx.dialect.compileSelect(ast);
|
|
6186
6186
|
const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6187
6187
|
const rows = flattenResults(executed);
|
|
6188
6188
|
if (ast.setOps && ast.setOps.length > 0) {
|
|
@@ -6190,21 +6190,21 @@ var executePlainWithContexts = async (execCtx, qb, options) => {
|
|
|
6190
6190
|
}
|
|
6191
6191
|
return hydrateRows(rows, qb.getHydrationPlan());
|
|
6192
6192
|
};
|
|
6193
|
-
async function executeHydrated(session, qb
|
|
6194
|
-
return executeWithContexts(session.getExecutionContext(), session, qb
|
|
6193
|
+
async function executeHydrated(session, qb) {
|
|
6194
|
+
return executeWithContexts(session.getExecutionContext(), session, qb);
|
|
6195
6195
|
}
|
|
6196
|
-
async function executeHydratedPlain(session, qb
|
|
6197
|
-
return executePlainWithContexts(session.getExecutionContext(), qb
|
|
6196
|
+
async function executeHydratedPlain(session, qb) {
|
|
6197
|
+
return executePlainWithContexts(session.getExecutionContext(), qb);
|
|
6198
6198
|
}
|
|
6199
|
-
async function executeHydratedWithContexts(execCtx, hydCtx, qb
|
|
6199
|
+
async function executeHydratedWithContexts(execCtx, hydCtx, qb) {
|
|
6200
6200
|
const entityCtx = hydCtx.entityContext;
|
|
6201
6201
|
if (!entityCtx) {
|
|
6202
6202
|
throw new Error("Hydration context is missing an EntityContext");
|
|
6203
6203
|
}
|
|
6204
|
-
return executeWithContexts(execCtx, entityCtx, qb
|
|
6204
|
+
return executeWithContexts(execCtx, entityCtx, qb);
|
|
6205
6205
|
}
|
|
6206
|
-
async function executeHydratedPlainWithContexts(execCtx, qb
|
|
6207
|
-
return executePlainWithContexts(execCtx, qb
|
|
6206
|
+
async function executeHydratedPlainWithContexts(execCtx, qb) {
|
|
6207
|
+
return executePlainWithContexts(execCtx, qb);
|
|
6208
6208
|
}
|
|
6209
6209
|
var loadLazyRelationsForTable = async (ctx, table, lazyRelations, lazyRelationOptions) => {
|
|
6210
6210
|
if (!lazyRelations.length) return;
|
|
@@ -6405,7 +6405,7 @@ function applyOrderBy(context, predicateFacet, term, directionOrOptions) {
|
|
|
6405
6405
|
const dir = options.direction ?? ORDER_DIRECTIONS.ASC;
|
|
6406
6406
|
return predicateFacet.orderBy(context, term, dir, options.nulls, options.collation);
|
|
6407
6407
|
}
|
|
6408
|
-
async function executeCount(context, env, session
|
|
6408
|
+
async function executeCount(context, env, session) {
|
|
6409
6409
|
const unpagedAst = {
|
|
6410
6410
|
...context.state.ast,
|
|
6411
6411
|
orderBy: void 0,
|
|
@@ -6425,7 +6425,7 @@ async function executeCount(context, env, session, options) {
|
|
|
6425
6425
|
joins: []
|
|
6426
6426
|
};
|
|
6427
6427
|
const execCtx = session.getExecutionContext();
|
|
6428
|
-
const compiled =
|
|
6428
|
+
const compiled = execCtx.dialect.compileSelect(countQuery);
|
|
6429
6429
|
const results = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
|
|
6430
6430
|
const value = results[0]?.values?.[0]?.[0];
|
|
6431
6431
|
if (typeof value === "number") return value;
|
|
@@ -6433,7 +6433,7 @@ async function executeCount(context, env, session, options) {
|
|
|
6433
6433
|
if (typeof value === "string") return Number(value);
|
|
6434
6434
|
return value === null || value === void 0 ? 0 : Number(value);
|
|
6435
6435
|
}
|
|
6436
|
-
async function executePagedQuery(builder, session, options, countCallback
|
|
6436
|
+
async function executePagedQuery(builder, session, options, countCallback) {
|
|
6437
6437
|
const { page, pageSize } = options;
|
|
6438
6438
|
if (!Number.isInteger(page) || page < 1) {
|
|
6439
6439
|
throw new Error("executePaged: page must be an integer >= 1");
|
|
@@ -6443,7 +6443,7 @@ async function executePagedQuery(builder, session, options, countCallback, param
|
|
|
6443
6443
|
}
|
|
6444
6444
|
const offset = (page - 1) * pageSize;
|
|
6445
6445
|
const totalItems = await countCallback(session);
|
|
6446
|
-
const items = await builder.limit(pageSize).offset(offset).execute(session
|
|
6446
|
+
const items = await builder.limit(pageSize).offset(offset).execute(session);
|
|
6447
6447
|
return { items, totalItems, page, pageSize };
|
|
6448
6448
|
}
|
|
6449
6449
|
function buildWhereHasPredicate(env, context, relationFacet, createChildBuilder, relationName, callbackOrOptions, maybeOptions, negate = false) {
|
|
@@ -8234,8 +8234,7 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8234
8234
|
* Validates that the query does not contain Param operands.
|
|
8235
8235
|
* Param proxies are only for schema generation, not execution.
|
|
8236
8236
|
*/
|
|
8237
|
-
validateNoParamOperands(
|
|
8238
|
-
if (options?.allowParamOperands) return;
|
|
8237
|
+
validateNoParamOperands() {
|
|
8239
8238
|
const ast = this.context.hydration.applyToAst(this.context.state.ast);
|
|
8240
8239
|
const paramName = findFirstParamOperandName(ast);
|
|
8241
8240
|
if (paramName) {
|
|
@@ -8254,13 +8253,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8254
8253
|
* // users is User[]
|
|
8255
8254
|
* users[0] instanceof User; // true
|
|
8256
8255
|
*/
|
|
8257
|
-
async execute(ctx
|
|
8258
|
-
this.validateNoParamOperands(
|
|
8256
|
+
async execute(ctx) {
|
|
8257
|
+
this.validateNoParamOperands();
|
|
8259
8258
|
if (this.entityConstructor) {
|
|
8260
|
-
return this.executeAs(this.entityConstructor, ctx
|
|
8259
|
+
return this.executeAs(this.entityConstructor, ctx);
|
|
8261
8260
|
}
|
|
8262
8261
|
const builder = this.ensureDefaultSelection();
|
|
8263
|
-
return executeHydrated(ctx, builder
|
|
8262
|
+
return executeHydrated(ctx, builder);
|
|
8264
8263
|
}
|
|
8265
8264
|
/**
|
|
8266
8265
|
* Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
|
|
@@ -8273,10 +8272,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8273
8272
|
* // rows is EntityInstance<UserTable>[] (plain objects)
|
|
8274
8273
|
* rows[0] instanceof User; // false
|
|
8275
8274
|
*/
|
|
8276
|
-
async executePlain(ctx
|
|
8277
|
-
this.validateNoParamOperands(
|
|
8275
|
+
async executePlain(ctx) {
|
|
8276
|
+
this.validateNoParamOperands();
|
|
8278
8277
|
const builder = this.ensureDefaultSelection();
|
|
8279
|
-
const rows = await executeHydratedPlain(ctx, builder
|
|
8278
|
+
const rows = await executeHydratedPlain(ctx, builder);
|
|
8280
8279
|
return rows;
|
|
8281
8280
|
}
|
|
8282
8281
|
/**
|
|
@@ -8293,10 +8292,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8293
8292
|
* users[0] instanceof User; // true!
|
|
8294
8293
|
* users[0].getFullName(); // works!
|
|
8295
8294
|
*/
|
|
8296
|
-
async executeAs(entityClass, ctx
|
|
8297
|
-
this.validateNoParamOperands(
|
|
8295
|
+
async executeAs(entityClass, ctx) {
|
|
8296
|
+
this.validateNoParamOperands();
|
|
8298
8297
|
const builder = this.ensureDefaultSelection();
|
|
8299
|
-
const results = await executeHydrated(ctx, builder
|
|
8298
|
+
const results = await executeHydrated(ctx, builder);
|
|
8300
8299
|
return materializeAs(entityClass, results);
|
|
8301
8300
|
}
|
|
8302
8301
|
/**
|
|
@@ -8305,9 +8304,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8305
8304
|
* @example
|
|
8306
8305
|
* const total = await qb.count(session);
|
|
8307
8306
|
*/
|
|
8308
|
-
async count(session
|
|
8309
|
-
this.validateNoParamOperands(
|
|
8310
|
-
return executeCount(this.context, this.env, session
|
|
8307
|
+
async count(session) {
|
|
8308
|
+
this.validateNoParamOperands();
|
|
8309
|
+
return executeCount(this.context, this.env, session);
|
|
8311
8310
|
}
|
|
8312
8311
|
/**
|
|
8313
8312
|
* Executes the query and returns both the paged items and the total.
|
|
@@ -8316,9 +8315,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8316
8315
|
* const { items, totalItems, page, pageSize } = await qb.executePaged(session, { page: 1, pageSize: 20 });
|
|
8317
8316
|
*/
|
|
8318
8317
|
async executePaged(session, options) {
|
|
8319
|
-
this.validateNoParamOperands(
|
|
8318
|
+
this.validateNoParamOperands();
|
|
8320
8319
|
const builder = this.ensureDefaultSelection();
|
|
8321
|
-
return executePagedQuery(builder, session, options, (sess) => builder.count(sess
|
|
8320
|
+
return executePagedQuery(builder, session, options, (sess) => builder.count(sess));
|
|
8322
8321
|
}
|
|
8323
8322
|
/**
|
|
8324
8323
|
* Executes the query with provided execution and hydration contexts
|
|
@@ -8330,10 +8329,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
|
|
|
8330
8329
|
* const hydCtx = new HydrationContext();
|
|
8331
8330
|
* const users = await qb.executeWithContexts(execCtx, hydCtx);
|
|
8332
8331
|
*/
|
|
8333
|
-
async executeWithContexts(execCtx, hydCtx
|
|
8334
|
-
this.validateNoParamOperands(
|
|
8332
|
+
async executeWithContexts(execCtx, hydCtx) {
|
|
8333
|
+
this.validateNoParamOperands();
|
|
8335
8334
|
const builder = this.ensureDefaultSelection();
|
|
8336
|
-
const results = await executeHydratedWithContexts(execCtx, hydCtx, builder
|
|
8335
|
+
const results = await executeHydratedWithContexts(execCtx, hydCtx, builder);
|
|
8337
8336
|
if (this.entityConstructor) {
|
|
8338
8337
|
return materializeAs(this.entityConstructor, results);
|
|
8339
8338
|
}
|