pqb 0.43.4 → 0.44.0

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
@@ -196,9 +196,11 @@ type WhereJsonPathEqualsItem = [
196
196
  ];
197
197
  interface WhereOnItem {
198
198
  joinFrom: WhereOnJoinItem;
199
+ from: string;
199
200
  joinTo: WhereOnJoinItem;
201
+ to: string;
200
202
  useOuterAliases?: true;
201
- on: [leftFullColumn: string, rightFullColumn: string] | [leftFullColumn: string, op: string, rightFullColumn: string];
203
+ op?: string;
202
204
  }
203
205
  type WhereOnJoinItem = {
204
206
  table?: string;
@@ -3298,7 +3300,7 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
3298
3300
  dateAsDate<T extends ColumnType>(this: T): ParseColumn<T, unknown, Date>;
3299
3301
  enum<U extends string, T extends readonly [U, ...U[]]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, U, T>;
3300
3302
  array<Item extends ArrayColumnValue>(item: Item): ArrayColumn<DefaultSchemaConfig, Item, unknown, unknown, unknown>;
3301
- json<T>(): JSONColumn<unknown extends T ? MaybeArray<string | number | boolean | RecordUnknown> : T, DefaultSchemaConfig>;
3303
+ json<T>(): JSONColumn<unknown extends T ? MaybeArray<string | number | boolean | object> : T, DefaultSchemaConfig>;
3302
3304
  inputSchema(): undefined;
3303
3305
  outputSchema(): undefined;
3304
3306
  querySchema(): undefined;
@@ -3718,7 +3720,7 @@ declare const makeRegexToFindInSql: (value: string) => RegExp;
3718
3720
  * @param q - main query object to pass to a callback as argument
3719
3721
  * @param cb - sub-query callback
3720
3722
  */
3721
- declare const resolveSubQueryCallback: (q: ToSQLQuery, cb: (q: ToSQLQuery) => ToSQLQuery) => ToSQLQuery;
3723
+ declare const resolveSubQueryCallbackV2: (q: ToSQLQuery, cb: (q: ToSQLQuery) => ToSQLQuery) => ToSQLQuery;
3722
3724
  /**
3723
3725
  * After getting a query from a sub-query callback,
3724
3726
  * join it to the main query in case it's a relation query.
@@ -6134,7 +6136,7 @@ type UpdateData<T extends UpdateSelf> = EmptyObject extends T['relations'] ? {
6134
6136
  } : {
6135
6137
  [K in keyof T['inputType'] | keyof T['relations']]?: K extends keyof T['inputType'] ? UpdateColumn<T, K> : UpdateRelationData<T, T['relations'][K]['relationConfig']>;
6136
6138
  };
6137
- type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] | QueryOrExpression<T['inputType'][Key]> | ((q: {
6139
+ type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] | ((q: {
6138
6140
  [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K] : K extends keyof T ? T[K] : never;
6139
6141
  }) => QueryOrExpression<T['inputType'][Key]>);
6140
6142
  type UpdateRelationData<T extends UpdateSelf, Rel extends RelationConfigBase> = T['returnType'] extends undefined | 'all' ? Rel['dataForUpdate'] : Rel['dataForUpdateOne'];
@@ -6219,7 +6221,7 @@ declare class Update {
6219
6221
  *
6220
6222
  * // use query that returns a single value
6221
6223
  * // returning multiple values will result in Postgres error
6222
- * column3: db.otherTable.get('someColumn'),
6224
+ * column3: () => db.otherTable.get('someColumn'),
6223
6225
  *
6224
6226
  * // select a single value from a related record
6225
6227
  * fromRelation: (q) => q.relatedTable.get('someColumn'),
@@ -6236,16 +6238,16 @@ declare class Update {
6236
6238
  * ```ts
6237
6239
  * await db.table.where({ ...conditions }).update({
6238
6240
  * // `column` will be set to a value of the `otherColumn` of the created record.
6239
- * column: db.otherTable.get('otherColumn').create({ ...data }),
6241
+ * column: () => db.otherTable.get('otherColumn').create({ ...data }),
6240
6242
  *
6241
6243
  * // `column2` will be set to a value of the `otherColumn` of the updated record.
6242
- * column2: db.otherTable
6244
+ * column2: () => db.otherTable
6243
6245
  * .get('otherColumn')
6244
6246
  * .findBy({ ...conditions })
6245
6247
  * .update({ key: 'value' }),
6246
6248
  *
6247
6249
  * // `column3` will be set to a value of the `otherColumn` of the deleted record.
6248
- * column3: db.otherTable
6250
+ * column3: () => db.otherTable
6249
6251
  * .get('otherColumn')
6250
6252
  * .findBy({ ...conditions })
6251
6253
  * .delete(),
@@ -8741,4 +8743,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
8741
8743
  */
8742
8744
  declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
8743
8745
 
8744
- 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, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL, toSQLCacheKey };
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 };
package/dist/index.js CHANGED
@@ -2127,14 +2127,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2127
2127
  } else {
2128
2128
  const item = value;
2129
2129
  const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
2130
- const { on } = item;
2131
2130
  const q = item.useOuterAliases ? {
2132
2131
  joinedShapes: query.joinedShapes,
2133
2132
  aliases: query.outerAliases,
2134
2133
  shape: query.shape
2135
2134
  } : query;
2136
2135
  ands.push(
2137
- `${onColumnToSql(ctx, q, joinAs, on[0])} ${on.length === 2 ? "=" : on[1]} ${onColumnToSql(ctx, q, joinAs, on.length === 3 ? on[2] : on[1])}`
2136
+ `${onColumnToSql(ctx, q, joinAs, item.from)} ${item.op || "="} ${onColumnToSql(ctx, q, joinAs, item.to)}`
2138
2137
  );
2139
2138
  }
2140
2139
  } else if (key === "IN") {
@@ -2611,7 +2610,7 @@ const resolveCallbacksInArgs = (q, args) => {
2611
2610
  qb.q.and = qb.q.or = qb.q.scopes = void 0;
2612
2611
  qb.q.subQuery = 1;
2613
2612
  qb.q.outerAliases = qb.q.aliases;
2614
- args[i] = resolveSubQueryCallback(qb, arg);
2613
+ args[i] = resolveSubQueryCallbackV2(qb, arg);
2615
2614
  }
2616
2615
  }
2617
2616
  };
@@ -3608,9 +3607,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
3608
3607
  computeds
3609
3608
  );
3610
3609
  };
3611
- const _joinLateral = (self, type, arg, cb, as) => {
3612
- var _a, _b, _c;
3613
- const q = self;
3610
+ const _joinLateralProcessArg = (q, arg, cb) => {
3614
3611
  let relation;
3615
3612
  if (typeof arg === "string") {
3616
3613
  relation = q.relations[arg];
@@ -3632,29 +3629,36 @@ const _joinLateral = (self, type, arg, cb, as) => {
3632
3629
  }
3633
3630
  }
3634
3631
  }
3635
- const query = arg;
3636
- query.q.joinTo = q;
3637
- const joinedAs = getQueryAs(q);
3638
- ((_a = query.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
3639
- let result = resolveSubQueryCallback(query, cb);
3632
+ let result = resolveSubQueryCallbackV2(
3633
+ arg,
3634
+ cb
3635
+ );
3640
3636
  if (relation) {
3641
3637
  result = relation.relationConfig.joinQuery(
3642
3638
  result,
3643
3639
  q
3644
3640
  );
3645
3641
  }
3646
- const joinKey = as || result.q.as || result.table;
3642
+ return result;
3643
+ };
3644
+ const _joinLateral = (self, type, arg, as) => {
3645
+ var _a, _b, _c;
3646
+ const q = self;
3647
+ arg.q.joinTo = q;
3648
+ const joinedAs = getQueryAs(q);
3649
+ ((_a = arg.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
3650
+ const joinKey = as || arg.q.as || arg.table;
3647
3651
  if (joinKey) {
3648
- const shape = getShapeFromSelect(result, true);
3652
+ const shape = getShapeFromSelect(arg, true);
3649
3653
  setQueryObjectValue(q, "joinedShapes", joinKey, shape);
3650
- setQueryObjectValue(q, "joinedParsers", joinKey, result.q.parsers);
3651
- if (result.q.batchParsers) {
3652
- ((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = result.q.batchParsers;
3654
+ setQueryObjectValue(q, "joinedParsers", joinKey, arg.q.parsers);
3655
+ if (arg.q.batchParsers) {
3656
+ ((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = arg.q.batchParsers;
3653
3657
  }
3654
3658
  }
3655
- as || (as = getQueryAs(result));
3656
- ((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = result.q.computeds;
3657
- return pushQueryValue(q, "join", [type, result, as]);
3659
+ as || (as = getQueryAs(arg));
3660
+ ((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = arg.q.computeds;
3661
+ return pushQueryValue(q, "join", [type, arg, as]);
3658
3662
  };
3659
3663
 
3660
3664
  class EnumColumn extends ColumnType {
@@ -3709,6 +3713,7 @@ class ArrayColumn extends ColumnType {
3709
3713
  }
3710
3714
  }
3711
3715
  const parse = function(source) {
3716
+ if (typeof source !== "string") return source;
3712
3717
  const entries = [];
3713
3718
  parsePostgresArray(source, entries, this.data.item.data.parseItem);
3714
3719
  return entries;
@@ -5202,7 +5207,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5202
5207
  let value = arg[key];
5203
5208
  let joinQuery;
5204
5209
  if (typeof value === "function") {
5205
- value = resolveSubQueryCallback(q, value);
5210
+ value = resolveSubQueryCallbackV2(q, value);
5206
5211
  if (isQueryNone(value)) {
5207
5212
  if (value.q.innerJoinLateral) {
5208
5213
  return false;
@@ -5244,7 +5249,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
5244
5249
  q,
5245
5250
  value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
5246
5251
  query,
5247
- (q2) => q2,
5248
5252
  key
5249
5253
  );
5250
5254
  }
@@ -6658,7 +6662,14 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6658
6662
 
6659
6663
  const toSQLCacheKey = Symbol("toSQLCache");
6660
6664
  const toSQL = (table, options) => {
6661
- return !options?.clearCache && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6665
+ if (table.q[toSQLCacheKey] && !options?.clearCache) {
6666
+ const cached = table.q[toSQLCacheKey];
6667
+ if (options?.values && "values" in cached && cached.values && options.values !== cached.values) {
6668
+ options.values.push(...cached.values);
6669
+ }
6670
+ return cached;
6671
+ }
6672
+ return table.q[toSQLCacheKey] = makeSQL(table, options);
6662
6673
  };
6663
6674
  const makeSQL = (table, options) => {
6664
6675
  const query = table.q;
@@ -6895,13 +6906,13 @@ const getQueryAs = (q) => {
6895
6906
  const makeRegexToFindInSql = (value) => {
6896
6907
  return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
6897
6908
  };
6898
- const resolveSubQueryCallback = (q, cb) => {
6899
- let arg;
6909
+ const resolveSubQueryCallbackV2 = (q, cb) => {
6910
+ let base;
6900
6911
  if (q.table) {
6901
- if (!q.internal.callbackArg) {
6902
- const base = Object.create(q.baseQuery);
6912
+ base = q.internal.callbackArg;
6913
+ if (!base) {
6914
+ base = Object.create(q.baseQuery);
6903
6915
  base.baseQuery = base;
6904
- q.internal.callbackArg = base;
6905
6916
  const { relations } = q;
6906
6917
  for (const key in relations) {
6907
6918
  Object.defineProperty(base, key, {
@@ -6911,21 +6922,17 @@ const resolveSubQueryCallback = (q, cb) => {
6911
6922
  }
6912
6923
  });
6913
6924
  }
6925
+ q.internal.callbackArg = base;
6914
6926
  }
6915
- arg = Object.create(q.internal.callbackArg);
6916
- arg.q = q.q;
6917
6927
  } else {
6918
- arg = q;
6919
- }
6920
- const { subQuery, relChain, outerAliases } = q.q;
6921
- q.q.subQuery = 1;
6922
- q.q.relChain = void 0;
6923
- q.q.outerAliases = q.q.aliases;
6924
- const result = cb(arg);
6925
- q.q.subQuery = subQuery;
6926
- q.q.relChain = relChain;
6927
- q.q.outerAliases = outerAliases;
6928
- return result;
6928
+ base = q;
6929
+ }
6930
+ const arg = Object.create(base);
6931
+ arg.q = getClonedQueryData(q.q);
6932
+ arg.q.subQuery = 1;
6933
+ arg.q.relChain = void 0;
6934
+ arg.q.outerAliases = q.q.aliases;
6935
+ return cb(arg);
6929
6936
  };
6930
6937
  const joinSubQuery = (q, sub) => {
6931
6938
  if (!("relationConfig" in sub)) return sub;
@@ -8141,7 +8148,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8141
8148
  );
8142
8149
  } else {
8143
8150
  if (typeof item[key] === "function") {
8144
- item[key] = resolveSubQueryCallback(
8151
+ item[key] = resolveSubQueryCallbackV2(
8145
8152
  q,
8146
8153
  item[key]
8147
8154
  );
@@ -9897,11 +9904,11 @@ class Join {
9897
9904
  * @param cb - {@link JoinLateralCallback}
9898
9905
  */
9899
9906
  joinLateral(arg, cb) {
9907
+ const q = _clone(this);
9900
9908
  return _joinLateral(
9901
- _clone(this),
9909
+ q,
9902
9910
  "JOIN",
9903
- arg,
9904
- cb
9911
+ _joinLateralProcessArg(q, arg, cb)
9905
9912
  );
9906
9913
  }
9907
9914
  /**
@@ -9920,28 +9927,32 @@ class Join {
9920
9927
  * @param cb - {@link JoinLateralCallback}
9921
9928
  */
9922
9929
  leftJoinLateral(arg, cb) {
9930
+ const q = _clone(this);
9923
9931
  return _joinLateral(
9924
9932
  _clone(this),
9925
9933
  "LEFT JOIN",
9926
- arg,
9927
- cb
9934
+ _joinLateralProcessArg(q, arg, cb)
9928
9935
  );
9929
9936
  }
9930
9937
  }
9931
9938
  const makeOnItem = (joinTo, joinFrom, args) => ({
9932
9939
  ON: {
9933
- joinTo,
9934
9940
  joinFrom,
9935
- on: args
9941
+ from: args[0],
9942
+ joinTo,
9943
+ to: args.length === 2 ? args[1] : args[2],
9944
+ op: args.length === 2 ? void 0 : args[1]
9936
9945
  }
9937
9946
  });
9938
9947
  const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
9939
9948
  return pushQueryValue(q, "and", {
9940
9949
  ON: {
9941
- joinTo: joinFrom,
9942
9950
  joinFrom: joinTo,
9951
+ from: on[0],
9952
+ joinTo: joinFrom,
9953
+ to: on.length === 2 ? on[1] : on[2],
9943
9954
  useOuterAliases: true,
9944
- on
9955
+ op: on.length === 2 ? void 0 : on[1]
9945
9956
  }
9946
9957
  });
9947
9958
  };
@@ -10359,11 +10370,11 @@ const _queryUpdate = (query, arg) => {
10359
10370
  } else {
10360
10371
  let value = set[key];
10361
10372
  if (typeof value === "function") {
10362
- value = resolveSubQueryCallback(
10373
+ value = resolveSubQueryCallbackV2(
10363
10374
  query.baseQuery,
10364
10375
  value
10365
10376
  );
10366
- if (value instanceof Db && value.q.type) {
10377
+ if (value instanceof Db && value.q.type && value.q.subQuery) {
10367
10378
  throw new OrchidOrmInternalError(
10368
10379
  value,
10369
10380
  `Only selecting queries are allowed inside callback of update, ${value.q.type} is given instead.`
@@ -10485,7 +10496,7 @@ class Update {
10485
10496
  *
10486
10497
  * // use query that returns a single value
10487
10498
  * // returning multiple values will result in Postgres error
10488
- * column3: db.otherTable.get('someColumn'),
10499
+ * column3: () => db.otherTable.get('someColumn'),
10489
10500
  *
10490
10501
  * // select a single value from a related record
10491
10502
  * fromRelation: (q) => q.relatedTable.get('someColumn'),
@@ -10502,16 +10513,16 @@ class Update {
10502
10513
  * ```ts
10503
10514
  * await db.table.where({ ...conditions }).update({
10504
10515
  * // `column` will be set to a value of the `otherColumn` of the created record.
10505
- * column: db.otherTable.get('otherColumn').create({ ...data }),
10516
+ * column: () => db.otherTable.get('otherColumn').create({ ...data }),
10506
10517
  *
10507
10518
  * // `column2` will be set to a value of the `otherColumn` of the updated record.
10508
- * column2: db.otherTable
10519
+ * column2: () => db.otherTable
10509
10520
  * .get('otherColumn')
10510
10521
  * .findBy({ ...conditions })
10511
10522
  * .update({ key: 'value' }),
10512
10523
  *
10513
10524
  * // `column3` will be set to a value of the `otherColumn` of the deleted record.
10514
- * column3: db.otherTable
10525
+ * column3: () => db.otherTable
10515
10526
  * .get('otherColumn')
10516
10527
  * .findBy({ ...conditions })
10517
10528
  * .delete(),
@@ -13143,7 +13154,7 @@ exports.queryTypeWithLimitOne = queryTypeWithLimitOne;
13143
13154
  exports.queryWrap = queryWrap;
13144
13155
  exports.raw = raw;
13145
13156
  exports.referencesArgsToCode = referencesArgsToCode;
13146
- exports.resolveSubQueryCallback = resolveSubQueryCallback;
13157
+ exports.resolveSubQueryCallbackV2 = resolveSubQueryCallbackV2;
13147
13158
  exports.rollbackSql = rollbackSql$1;
13148
13159
  exports.saveSearchAlias = saveSearchAlias;
13149
13160
  exports.setColumnDefaultParse = setColumnDefaultParse;