pqb 0.44.0 → 0.45.1

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.d.ts CHANGED
@@ -406,7 +406,7 @@ interface CommonQueryData {
406
406
  log?: QueryLogObject;
407
407
  logger: QueryLogger;
408
408
  autoPreparedStatements?: boolean;
409
- [toSQLCacheKey]?: Sql;
409
+ sqlCache?: Sql;
410
410
  transform?: QueryDataTransform[];
411
411
  language?: string;
412
412
  subQuery?: number;
@@ -3663,8 +3663,6 @@ interface ToSQLCtx {
3663
3663
  values: unknown[];
3664
3664
  aliasValue?: true;
3665
3665
  }
3666
- type toSQLCacheKey = typeof toSQLCacheKey;
3667
- declare const toSQLCacheKey: unique symbol;
3668
3666
  interface ToSQLOptions {
3669
3667
  clearCache?: boolean;
3670
3668
  values?: unknown[];
@@ -5442,16 +5440,14 @@ declare class QueryLog {
5442
5440
  log<T>(this: T, log?: boolean): T;
5443
5441
  }
5444
5442
 
5445
- type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows> = {
5443
+ type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindowsThen, Q extends PickQueryMetaResultReturnTypeWithDataWindowsThen> = {
5446
5444
  [K in keyof T]: K extends 'meta' ? {
5447
5445
  [K in keyof T['meta'] | keyof Q['meta']]: K extends 'selectable' ? Q['meta']['selectable'] & Omit<T['meta']['selectable'], keyof Q['meta']['selectable']> : K extends 'hasWhere' | 'hasSelect' ? T['meta'][K] & Q['meta'][K] : K extends keyof Q['meta'] ? Q['meta'][K] : T['meta'][K];
5448
- } : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? Q['returnType'] extends undefined ? T['returnType'] : Q['returnType'] : K extends 'then' ? QueryThenByQuery<Q['returnType'] extends undefined ? T : Q, MergeQueryResult<T, Q>> : K extends 'windows' ? Q['windows'] & Omit<T['windows'], keyof Q['windows']> : K extends 'withData' ? Q['withData'] & Omit<T['withData'], keyof Q['withData']> : T[K];
5446
+ } : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? Q['returnType'] extends undefined ? T['returnType'] : Q['returnType'] : K extends 'then' ? Q['returnType'] extends undefined ? QueryThenByQuery<T, MergeQueryResult<T, Q>> : Q['returnType'] extends 'all' | 'one' | 'oneOrThrow' | 'rows' ? QueryThenByQuery<Q, MergeQueryResult<T, Q>> : Q['meta']['hasSelect'] extends true ? Q['then'] : T['meta']['hasSelect'] extends true ? T['then'] : Q['then'] : K extends 'windows' ? Q['windows'] & Omit<T['windows'], keyof Q['windows']> : K extends 'withData' ? Q['withData'] & Omit<T['withData'], keyof Q['withData']> : T[K];
5449
5447
  };
5450
- type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? {
5451
- [K in keyof T['result'] | keyof Q['result']]: K extends keyof Q['result'] ? Q['result'][K] : T['result'][K];
5452
- } : T['result'] : Q['result'];
5448
+ type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? Omit<T['result'], keyof Q['result']> & Q['result'] : T['result'] : Q['result'];
5453
5449
  declare class MergeQueryMethods {
5454
- merge<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows>(this: T, q: Q): MergeQuery<T, Q>;
5450
+ merge<T extends PickQueryMetaResultReturnTypeWithDataWindowsThen, Q extends PickQueryMetaResultReturnTypeWithDataWindowsThen>(this: T, q: Q): MergeQuery<T, Q>;
5455
5451
  }
5456
5452
 
5457
5453
  interface SelectSelf {
@@ -7096,16 +7092,24 @@ type OrderArgKey<T extends OrderArgSelf> = {
7096
7092
  type GroupArgs<T extends PickQueryResult> = ({
7097
7093
  [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K;
7098
7094
  }[keyof T['result']] | Expression)[];
7099
- interface QueryHelper<T extends PickQueryMetaShape, Args extends any[], Result> {
7100
- <Q extends {
7101
- returnType: QueryReturnType;
7102
- meta: QueryMetaBase & {
7103
- selectable: Omit<T['meta']['selectable'], `${AliasOrTable<T>}.${Extract<keyof T['shape'], string>}`>;
7104
- };
7105
- result: QueryColumns;
7106
- windows: EmptyObject;
7107
- withData: WithDataItems;
7108
- }>(q: Q, ...args: Args): Result extends PickQueryMetaResultReturnTypeWithDataWindows ? MergeQuery<Q, Result> : Result;
7095
+ interface QueryHelperQuery<T extends PickQueryMetaShape> {
7096
+ returnType: QueryReturnType;
7097
+ meta: QueryMetaBase & {
7098
+ selectable: Omit<T['meta']['selectable'], `${AliasOrTable<T>}.${Extract<keyof T['shape'], string>}`>;
7099
+ };
7100
+ result: QueryColumns;
7101
+ windows: EmptyObject;
7102
+ withData: WithDataItems;
7103
+ then: unknown;
7104
+ }
7105
+ interface IsQueryHelper {
7106
+ isQueryHelper: true;
7107
+ args: unknown[];
7108
+ result: unknown;
7109
+ }
7110
+ interface QueryHelper<T extends PickQueryMetaShape, Args extends any[], Result> extends IsQueryHelper {
7111
+ <Q extends QueryHelperQuery<T>>(q: Q, ...args: Args): Result extends PickQueryMetaResultReturnTypeWithDataWindowsThen ? MergeQuery<Q, Result> : Result;
7112
+ args: Args;
7109
7113
  result: Result;
7110
7114
  }
7111
7115
  type QueryHelperResult<T extends QueryHelper<PickQueryMetaShape, any[], unknown>> = T['result'];
@@ -7569,50 +7573,6 @@ declare class QueryMethods<ColumnTypes> {
7569
7573
  * ```
7570
7574
  */
7571
7575
  none<T>(this: T): T;
7572
- /**
7573
- * `modify` allows modifying the query with your function:
7574
- *
7575
- * ```ts
7576
- * const doSomethingWithQuery = (q: typeof db.table) => {
7577
- * // can use all query methods
7578
- * return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
7579
- * };
7580
- *
7581
- * const record = await db.table.select('id').modify(doSomethingWithQuery).find(1);
7582
- *
7583
- * record.id; // id was selected before `modify`
7584
- * record.name; // name was selected by the function
7585
- * ```
7586
- *
7587
- * It's possible to apply different `select`s inside the function, and then the result type will be a union of all possibilities:
7588
- *
7589
- * Use this sparingly as it complicates dealing with the result.
7590
- *
7591
- * ```ts
7592
- * const doSomethingWithQuery = (q: typeof db.table) => {
7593
- * if (Math.random() > 0.5) {
7594
- * return q.select('one');
7595
- * } else {
7596
- * return q.select('two');
7597
- * }
7598
- * };
7599
- *
7600
- * const record = await db.table.modify(doSomethingWithQuery).find(1);
7601
- *
7602
- * // TS error: we don't know for sure if the `one` was selected.
7603
- * record.one;
7604
- *
7605
- * // use `in` operator to disambiguate the result type
7606
- * if ('one' in record) {
7607
- * record.one;
7608
- * } else {
7609
- * record.two;
7610
- * }
7611
- * ```
7612
- *
7613
- * @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
7614
- */
7615
- modify<T extends PickQueryMetaResultReturnTypeWithDataWindowsTable<string | undefined>, Arg extends PickQueryMetaResultReturnTypeWithDataWindowsTable<T['table']>, Result>(this: T, fn: (q: Arg) => Result): Result extends PickQueryMetaResultReturnTypeWithDataWindows ? MergeQuery<T, Result> : Result;
7616
7576
  /**
7617
7577
  * Use `makeHelper` to make a query helper - a function where you can modify the query, and reuse this function across different places.
7618
7578
  *
@@ -7665,6 +7625,63 @@ declare class QueryMethods<ColumnTypes> {
7665
7625
  * @param fn - helper function
7666
7626
  */
7667
7627
  makeHelper<T extends PickQueryMetaShape, Args extends unknown[], Result>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
7628
+ /**
7629
+ * `modify` allows modifying the query with helpers defined with {@link makeHelper}:
7630
+ *
7631
+ * ```ts
7632
+ * const helper = db.table.makeHelper((q) => {
7633
+ * // all query methods are available
7634
+ * return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
7635
+ * });
7636
+ *
7637
+ * const record = await db.table.select('id').modify(helper).find(1);
7638
+ *
7639
+ * record.id; // id was selected before `modify`
7640
+ * record.name; // name was selected by the function
7641
+ * ```
7642
+ *
7643
+ * When the helper result isn't certain, it will result in a union of all possibilities.
7644
+ * Use this sparingly as it complicates dealing with the result.
7645
+ *
7646
+ * ```ts
7647
+ * const helper = db.table((q) => {
7648
+ * if (Math.random() > 0.5) {
7649
+ * return q.select('one');
7650
+ * } else {
7651
+ * return q.select('two');
7652
+ * }
7653
+ * });
7654
+ *
7655
+ * const record = await db.table.modify(helper).find(1);
7656
+ *
7657
+ * // TS error: we don't know for sure if the `one` was selected.
7658
+ * record.one;
7659
+ *
7660
+ * // use `in` operator to disambiguate the result type
7661
+ * if ('one' in record) {
7662
+ * record.one;
7663
+ * } else {
7664
+ * record.two;
7665
+ * }
7666
+ * ```
7667
+ *
7668
+ * You can define and pass parameters:
7669
+ *
7670
+ * ```ts
7671
+ * const helper = db.table.makeHelper((q, select: 'id' | 'name') => {
7672
+ * return q.select(select);
7673
+ * });
7674
+ *
7675
+ * const record = await db.table.modify(helper, 'id').find(1);
7676
+ * // record has type { id: number } | { name: string }
7677
+ * if ('id' in record) {
7678
+ * record.id;
7679
+ * }
7680
+ * ```
7681
+ *
7682
+ * @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
7683
+ */
7684
+ modify<T extends PickQueryMetaResultReturnTypeWithDataWindowsThen, Fn extends IsQueryHelper>(this: T, fn: Fn, ...args: Fn['args']): Fn['result'] extends PickQueryMetaResultReturnTypeWithDataWindowsThen ? MergeQuery<T, Fn['result']> : Fn['result'];
7668
7685
  /**
7669
7686
  * Narrows a part of the query output type.
7670
7687
  * Use with caution, type-safety isn't guaranteed with it.
@@ -7843,8 +7860,8 @@ interface PickQueryMetaResultRelationsWithDataReturnTypeShape extends PickQueryM
7843
7860
  }
7844
7861
  interface PickQueryMetaResultReturnTypeWithDataWindows extends PickQueryMetaResultReturnType, PickQueryWithData, PickQueryWindows {
7845
7862
  }
7846
- interface PickQueryMetaResultReturnTypeWithDataWindowsTable<Table extends string | undefined> extends PickQueryMetaResultReturnType, PickQueryWithData, PickQueryWindows {
7847
- table: Table;
7863
+ interface PickQueryMetaResultReturnTypeWithDataWindowsThen extends PickQueryMetaResultReturnTypeWithDataWindows {
7864
+ then: unknown;
7848
7865
  }
7849
7866
  interface PickQueryQAndInternal extends PickQueryQ, PickQueryInternal {
7850
7867
  }
@@ -8583,6 +8600,14 @@ declare const pushQueryArray: <T extends {
8583
8600
  * @param value - new element to push
8584
8601
  */
8585
8602
  declare const pushQueryValue: <T extends PickQueryQ>(q: T, key: string, value: unknown) => T;
8603
+ /**
8604
+ * Push new element into array in the query data - immutable version
8605
+ *
8606
+ * @param q - query
8607
+ * @param key - key to get the array
8608
+ * @param value - new element to push
8609
+ */
8610
+ declare const pushQueryValueImmutable: <T extends PickQueryQ>(q: T, key: string, value: unknown) => T;
8586
8611
  /**
8587
8612
  * Set value into the object in query data, create the object if it doesn't yet exist.
8588
8613
  *
@@ -8743,4 +8768,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
8743
8768
  */
8744
8769
  declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
8745
8770
 
8746
- export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsTable, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOne, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsOneOptional, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL, toSQLCacheKey };
8771
+ export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOne, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsOneOptional, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
package/dist/index.js CHANGED
@@ -3387,6 +3387,11 @@ const pushQueryValue = (q, key, value) => {
3387
3387
  );
3388
3388
  return q;
3389
3389
  };
3390
+ const pushQueryValueImmutable = (q, key, value) => {
3391
+ const arr = q.q[key];
3392
+ q.q[key] = arr ? [...arr, value] : [value];
3393
+ return q;
3394
+ };
3390
3395
  const setQueryObjectValue = (q, object, key, value) => {
3391
3396
  if (!q.q[object])
3392
3397
  q.q[object] = {
@@ -5265,7 +5270,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5265
5270
  return { selectAs };
5266
5271
  };
5267
5272
  const setParserForSelectedString = (q, arg, as, columnAs) => {
5268
- var _a, _b;
5273
+ var _a;
5269
5274
  const index = arg.indexOf(".");
5270
5275
  if (index !== -1) {
5271
5276
  const table = getFullColumnTable(q, arg, index, as);
@@ -5294,7 +5299,7 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
5294
5299
  const computeds = q.q.joinedComputeds?.[table];
5295
5300
  if (computeds?.[column]) {
5296
5301
  const computed = computeds[column];
5297
- const map = (_b = q.q).hookSelect ?? (_b.hookSelect = /* @__PURE__ */ new Map());
5302
+ const map = q.q.hookSelect = new Map(q.q.hookSelect);
5298
5303
  for (const column2 of computed.deps) {
5299
5304
  map.set(column2, { select: `${table}.${column2}` });
5300
5305
  }
@@ -5314,10 +5319,9 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
5314
5319
  }
5315
5320
  };
5316
5321
  const handleComputed = (q, computeds, column) => {
5317
- var _a;
5318
5322
  if (computeds?.[column]) {
5319
5323
  const computed = computeds[column];
5320
- const map = (_a = q.q).hookSelect ?? (_a.hookSelect = /* @__PURE__ */ new Map());
5324
+ const map = q.q.hookSelect = new Map(q.q.hookSelect);
5321
5325
  for (const column2 of computed.deps) {
5322
5326
  map.set(column2, { select: column2 });
5323
5327
  }
@@ -6660,16 +6664,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6660
6664
  pushWhereStatementSql(ctx, table, query, quotedAs);
6661
6665
  };
6662
6666
 
6663
- const toSQLCacheKey = Symbol("toSQLCache");
6664
6667
  const toSQL = (table, options) => {
6665
- if (table.q[toSQLCacheKey] && !options?.clearCache) {
6666
- const cached = table.q[toSQLCacheKey];
6668
+ if (table.q.sqlCache && !options?.clearCache) {
6669
+ const cached = table.q.sqlCache;
6667
6670
  if (options?.values && "values" in cached && cached.values && options.values !== cached.values) {
6668
6671
  options.values.push(...cached.values);
6669
6672
  }
6670
6673
  return cached;
6671
6674
  }
6672
- return table.q[toSQLCacheKey] = makeSQL(table, options);
6675
+ return table.q.sqlCache = makeSQL(table, options);
6673
6676
  };
6674
6677
  const makeSQL = (table, options) => {
6675
6678
  const query = table.q;
@@ -6804,11 +6807,8 @@ function pushLimitSQL(sql, values, q) {
6804
6807
  const cloneQuery = (q) => {
6805
6808
  if (q.with) q.with = q.with.slice(0);
6806
6809
  if (q.select) q.select = q.select.slice(0);
6807
- if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
6808
6810
  if (q.and) q.and = q.and.slice(0);
6809
6811
  if (q.or) q.or = q.or.slice(0);
6810
- if (q.before) q.before = q.before.slice(0);
6811
- if (q.after) q.after = q.after.slice(0);
6812
6812
  if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
6813
6813
  if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
6814
6814
  if (q.batchParsers) q.batchParsers = [...q.batchParsers];
@@ -6833,29 +6833,6 @@ const cloneQuery = (q) => {
6833
6833
  q.values = Array.isArray(q.values) ? q.values.slice(0) : q.values;
6834
6834
  if (q.using) q.using = q.using.slice(0);
6835
6835
  if (q.join) q.join = q.join.slice(0);
6836
- if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
6837
- if (q.afterCreate) {
6838
- q.afterCreate = q.afterCreate.slice(0);
6839
- if (q.afterCreateSelect) {
6840
- q.afterCreateSelect = new Set(q.afterCreateSelect);
6841
- }
6842
- }
6843
- } else if (q.type === "update") {
6844
- if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
6845
- if (q.afterUpdate) {
6846
- q.afterUpdate = q.afterUpdate.slice(0);
6847
- if (q.afterUpdateSelect) {
6848
- q.afterUpdateSelect = new Set(q.afterUpdateSelect);
6849
- }
6850
- }
6851
- } else if (q.type === "delete") {
6852
- if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
6853
- if (q.afterDelete) {
6854
- q.afterDelete = q.afterDelete.slice(0);
6855
- if (q.afterDeleteSelect) {
6856
- q.afterDeleteSelect = new Set(q.afterDeleteSelect);
6857
- }
6858
- }
6859
6836
  }
6860
6837
  };
6861
6838
 
@@ -6896,7 +6873,7 @@ const _chain = (fromQuery, toQuery, rel) => {
6896
6873
 
6897
6874
  const getClonedQueryData = (query) => {
6898
6875
  const cloned = { ...query };
6899
- delete cloned[toSQLCacheKey];
6876
+ delete cloned.sqlCache;
6900
6877
  cloneQuery(cloned);
6901
6878
  return cloned;
6902
6879
  };
@@ -9074,21 +9051,22 @@ class Having {
9074
9051
  }
9075
9052
  }
9076
9053
 
9077
- const before = (q, key, cb) => pushQueryValue(q, `before${key}`, cb);
9078
- const after = (q, key, select, cb, commit) => {
9079
- var _a, _b;
9080
- pushQueryValue(q, `after${key}${commit ? "Commit" : ""}`, cb);
9081
- const set = (_a = q.q)[_b = `after${key}Select`] ?? (_a[_b] = /* @__PURE__ */ new Set());
9054
+ const before = (q, key, cb) => pushQueryValueImmutable(q, `before${key}`, cb);
9055
+ const after = (query, key, select, cb, commit) => {
9056
+ const q = query;
9057
+ pushQueryValueImmutable(q, `after${key}${commit ? "Commit" : ""}`, cb);
9058
+ const prop = `after${key}Select`;
9059
+ const set = q.q[prop] = new Set(q.q[prop]);
9082
9060
  for (const column of select) {
9083
9061
  set.add(column);
9084
9062
  }
9085
- return q;
9063
+ return query;
9086
9064
  };
9087
9065
  const _queryHookBeforeQuery = (q, cb) => {
9088
- return pushQueryValue(q, "before", cb);
9066
+ return pushQueryValueImmutable(q, "before", cb);
9089
9067
  };
9090
9068
  const _queryHookAfterQuery = (q, cb) => {
9091
- return pushQueryValue(q, "after", cb);
9069
+ return pushQueryValueImmutable(q, "after", cb);
9092
9070
  };
9093
9071
  const _queryHookBeforeCreate = (q, cb) => {
9094
9072
  return before(q, "Create", cb);
@@ -11004,7 +10982,7 @@ function orCreate(query, data, updateData, mergeData) {
11004
10982
  q.handleResult = (q2, t, r, s) => {
11005
10983
  return created ? result : handleResult(q2, t, r, s);
11006
10984
  };
11007
- q.hookSelect ?? (q.hookSelect = /* @__PURE__ */ new Map());
10985
+ q.hookSelect = new Map(q.hookSelect);
11008
10986
  q.patchResult = async (q2, hookSelect, queryResult) => {
11009
10987
  var _a, _b;
11010
10988
  if (queryResult.rowCount === 0) {
@@ -12169,52 +12147,6 @@ class QueryMethods {
12169
12147
  none() {
12170
12148
  return _queryNone(this);
12171
12149
  }
12172
- /**
12173
- * `modify` allows modifying the query with your function:
12174
- *
12175
- * ```ts
12176
- * const doSomethingWithQuery = (q: typeof db.table) => {
12177
- * // can use all query methods
12178
- * return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
12179
- * };
12180
- *
12181
- * const record = await db.table.select('id').modify(doSomethingWithQuery).find(1);
12182
- *
12183
- * record.id; // id was selected before `modify`
12184
- * record.name; // name was selected by the function
12185
- * ```
12186
- *
12187
- * It's possible to apply different `select`s inside the function, and then the result type will be a union of all possibilities:
12188
- *
12189
- * Use this sparingly as it complicates dealing with the result.
12190
- *
12191
- * ```ts
12192
- * const doSomethingWithQuery = (q: typeof db.table) => {
12193
- * if (Math.random() > 0.5) {
12194
- * return q.select('one');
12195
- * } else {
12196
- * return q.select('two');
12197
- * }
12198
- * };
12199
- *
12200
- * const record = await db.table.modify(doSomethingWithQuery).find(1);
12201
- *
12202
- * // TS error: we don't know for sure if the `one` was selected.
12203
- * record.one;
12204
- *
12205
- * // use `in` operator to disambiguate the result type
12206
- * if ('one' in record) {
12207
- * record.one;
12208
- * } else {
12209
- * record.two;
12210
- * }
12211
- * ```
12212
- *
12213
- * @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
12214
- */
12215
- modify(fn) {
12216
- return fn(this);
12217
- }
12218
12150
  /**
12219
12151
  * Use `makeHelper` to make a query helper - a function where you can modify the query, and reuse this function across different places.
12220
12152
  *
@@ -12276,6 +12208,65 @@ class QueryMethods {
12276
12208
  return fn(q, ...args);
12277
12209
  };
12278
12210
  }
12211
+ /**
12212
+ * `modify` allows modifying the query with helpers defined with {@link makeHelper}:
12213
+ *
12214
+ * ```ts
12215
+ * const helper = db.table.makeHelper((q) => {
12216
+ * // all query methods are available
12217
+ * return q.select('name').where({ active: true }).order({ createdAt: 'DESC' });
12218
+ * });
12219
+ *
12220
+ * const record = await db.table.select('id').modify(helper).find(1);
12221
+ *
12222
+ * record.id; // id was selected before `modify`
12223
+ * record.name; // name was selected by the function
12224
+ * ```
12225
+ *
12226
+ * When the helper result isn't certain, it will result in a union of all possibilities.
12227
+ * Use this sparingly as it complicates dealing with the result.
12228
+ *
12229
+ * ```ts
12230
+ * const helper = db.table((q) => {
12231
+ * if (Math.random() > 0.5) {
12232
+ * return q.select('one');
12233
+ * } else {
12234
+ * return q.select('two');
12235
+ * }
12236
+ * });
12237
+ *
12238
+ * const record = await db.table.modify(helper).find(1);
12239
+ *
12240
+ * // TS error: we don't know for sure if the `one` was selected.
12241
+ * record.one;
12242
+ *
12243
+ * // use `in` operator to disambiguate the result type
12244
+ * if ('one' in record) {
12245
+ * record.one;
12246
+ * } else {
12247
+ * record.two;
12248
+ * }
12249
+ * ```
12250
+ *
12251
+ * You can define and pass parameters:
12252
+ *
12253
+ * ```ts
12254
+ * const helper = db.table.makeHelper((q, select: 'id' | 'name') => {
12255
+ * return q.select(select);
12256
+ * });
12257
+ *
12258
+ * const record = await db.table.modify(helper, 'id').find(1);
12259
+ * // record has type { id: number } | { name: string }
12260
+ * if ('id' in record) {
12261
+ * record.id;
12262
+ * }
12263
+ * ```
12264
+ *
12265
+ * @param fn - function to modify the query with. The result type will be merged with the main query as if the `merge` method was used.
12266
+ */
12267
+ modify(fn, ...args) {
12268
+ return fn(this, ...args);
12269
+ }
12279
12270
  /**
12280
12271
  * Narrows a part of the query output type.
12281
12272
  * Use with caution, type-safety isn't guaranteed with it.
@@ -13145,6 +13136,7 @@ exports.pushQueryOn = pushQueryOn;
13145
13136
  exports.pushQueryOnForOuter = pushQueryOnForOuter;
13146
13137
  exports.pushQueryOrOn = pushQueryOrOn;
13147
13138
  exports.pushQueryValue = pushQueryValue;
13139
+ exports.pushQueryValueImmutable = pushQueryValueImmutable;
13148
13140
  exports.pushTableDataCode = pushTableDataCode;
13149
13141
  exports.queryFrom = queryFrom;
13150
13142
  exports.queryFromSql = queryFromSql;
@@ -13173,5 +13165,4 @@ exports.testTransaction = testTransaction;
13173
13165
  exports.throwIfJoinLateral = throwIfJoinLateral;
13174
13166
  exports.throwIfNoWhere = throwIfNoWhere;
13175
13167
  exports.toSQL = toSQL;
13176
- exports.toSQLCacheKey = toSQLCacheKey;
13177
13168
  //# sourceMappingURL=index.js.map