pqb 0.43.5 → 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 +11 -9
- package/dist/index.js +59 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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 |
|
|
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
|
|
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] |
|
|
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,
|
|
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] =
|
|
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
|
|
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
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
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
|
-
|
|
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(
|
|
3652
|
+
const shape = getShapeFromSelect(arg, true);
|
|
3649
3653
|
setQueryObjectValue(q, "joinedShapes", joinKey, shape);
|
|
3650
|
-
setQueryObjectValue(q, "joinedParsers", joinKey,
|
|
3651
|
-
if (
|
|
3652
|
-
((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] =
|
|
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(
|
|
3656
|
-
((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] =
|
|
3657
|
-
return pushQueryValue(q, "join", [type,
|
|
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 {
|
|
@@ -5203,7 +5207,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5203
5207
|
let value = arg[key];
|
|
5204
5208
|
let joinQuery;
|
|
5205
5209
|
if (typeof value === "function") {
|
|
5206
|
-
value =
|
|
5210
|
+
value = resolveSubQueryCallbackV2(q, value);
|
|
5207
5211
|
if (isQueryNone(value)) {
|
|
5208
5212
|
if (value.q.innerJoinLateral) {
|
|
5209
5213
|
return false;
|
|
@@ -5245,7 +5249,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5245
5249
|
q,
|
|
5246
5250
|
value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
5247
5251
|
query,
|
|
5248
|
-
(q2) => q2,
|
|
5249
5252
|
key
|
|
5250
5253
|
);
|
|
5251
5254
|
}
|
|
@@ -6903,13 +6906,13 @@ const getQueryAs = (q) => {
|
|
|
6903
6906
|
const makeRegexToFindInSql = (value) => {
|
|
6904
6907
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
6905
6908
|
};
|
|
6906
|
-
const
|
|
6907
|
-
let
|
|
6909
|
+
const resolveSubQueryCallbackV2 = (q, cb) => {
|
|
6910
|
+
let base;
|
|
6908
6911
|
if (q.table) {
|
|
6909
|
-
|
|
6910
|
-
|
|
6912
|
+
base = q.internal.callbackArg;
|
|
6913
|
+
if (!base) {
|
|
6914
|
+
base = Object.create(q.baseQuery);
|
|
6911
6915
|
base.baseQuery = base;
|
|
6912
|
-
q.internal.callbackArg = base;
|
|
6913
6916
|
const { relations } = q;
|
|
6914
6917
|
for (const key in relations) {
|
|
6915
6918
|
Object.defineProperty(base, key, {
|
|
@@ -6919,21 +6922,17 @@ const resolveSubQueryCallback = (q, cb) => {
|
|
|
6919
6922
|
}
|
|
6920
6923
|
});
|
|
6921
6924
|
}
|
|
6925
|
+
q.internal.callbackArg = base;
|
|
6922
6926
|
}
|
|
6923
|
-
arg = Object.create(q.internal.callbackArg);
|
|
6924
|
-
arg.q = q.q;
|
|
6925
6927
|
} else {
|
|
6926
|
-
|
|
6927
|
-
}
|
|
6928
|
-
const
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
q.q.relChain = relChain;
|
|
6935
|
-
q.q.outerAliases = outerAliases;
|
|
6936
|
-
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);
|
|
6937
6936
|
};
|
|
6938
6937
|
const joinSubQuery = (q, sub) => {
|
|
6939
6938
|
if (!("relationConfig" in sub)) return sub;
|
|
@@ -8149,7 +8148,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
|
|
|
8149
8148
|
);
|
|
8150
8149
|
} else {
|
|
8151
8150
|
if (typeof item[key] === "function") {
|
|
8152
|
-
item[key] =
|
|
8151
|
+
item[key] = resolveSubQueryCallbackV2(
|
|
8153
8152
|
q,
|
|
8154
8153
|
item[key]
|
|
8155
8154
|
);
|
|
@@ -9905,11 +9904,11 @@ class Join {
|
|
|
9905
9904
|
* @param cb - {@link JoinLateralCallback}
|
|
9906
9905
|
*/
|
|
9907
9906
|
joinLateral(arg, cb) {
|
|
9907
|
+
const q = _clone(this);
|
|
9908
9908
|
return _joinLateral(
|
|
9909
|
-
|
|
9909
|
+
q,
|
|
9910
9910
|
"JOIN",
|
|
9911
|
-
arg,
|
|
9912
|
-
cb
|
|
9911
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9913
9912
|
);
|
|
9914
9913
|
}
|
|
9915
9914
|
/**
|
|
@@ -9928,28 +9927,32 @@ class Join {
|
|
|
9928
9927
|
* @param cb - {@link JoinLateralCallback}
|
|
9929
9928
|
*/
|
|
9930
9929
|
leftJoinLateral(arg, cb) {
|
|
9930
|
+
const q = _clone(this);
|
|
9931
9931
|
return _joinLateral(
|
|
9932
9932
|
_clone(this),
|
|
9933
9933
|
"LEFT JOIN",
|
|
9934
|
-
arg,
|
|
9935
|
-
cb
|
|
9934
|
+
_joinLateralProcessArg(q, arg, cb)
|
|
9936
9935
|
);
|
|
9937
9936
|
}
|
|
9938
9937
|
}
|
|
9939
9938
|
const makeOnItem = (joinTo, joinFrom, args) => ({
|
|
9940
9939
|
ON: {
|
|
9941
|
-
joinTo,
|
|
9942
9940
|
joinFrom,
|
|
9943
|
-
|
|
9941
|
+
from: args[0],
|
|
9942
|
+
joinTo,
|
|
9943
|
+
to: args.length === 2 ? args[1] : args[2],
|
|
9944
|
+
op: args.length === 2 ? void 0 : args[1]
|
|
9944
9945
|
}
|
|
9945
9946
|
});
|
|
9946
9947
|
const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
|
|
9947
9948
|
return pushQueryValue(q, "and", {
|
|
9948
9949
|
ON: {
|
|
9949
|
-
joinTo: joinFrom,
|
|
9950
9950
|
joinFrom: joinTo,
|
|
9951
|
+
from: on[0],
|
|
9952
|
+
joinTo: joinFrom,
|
|
9953
|
+
to: on.length === 2 ? on[1] : on[2],
|
|
9951
9954
|
useOuterAliases: true,
|
|
9952
|
-
on
|
|
9955
|
+
op: on.length === 2 ? void 0 : on[1]
|
|
9953
9956
|
}
|
|
9954
9957
|
});
|
|
9955
9958
|
};
|
|
@@ -10367,11 +10370,11 @@ const _queryUpdate = (query, arg) => {
|
|
|
10367
10370
|
} else {
|
|
10368
10371
|
let value = set[key];
|
|
10369
10372
|
if (typeof value === "function") {
|
|
10370
|
-
value =
|
|
10373
|
+
value = resolveSubQueryCallbackV2(
|
|
10371
10374
|
query.baseQuery,
|
|
10372
10375
|
value
|
|
10373
10376
|
);
|
|
10374
|
-
if (value instanceof Db && value.q.type) {
|
|
10377
|
+
if (value instanceof Db && value.q.type && value.q.subQuery) {
|
|
10375
10378
|
throw new OrchidOrmInternalError(
|
|
10376
10379
|
value,
|
|
10377
10380
|
`Only selecting queries are allowed inside callback of update, ${value.q.type} is given instead.`
|
|
@@ -10493,7 +10496,7 @@ class Update {
|
|
|
10493
10496
|
*
|
|
10494
10497
|
* // use query that returns a single value
|
|
10495
10498
|
* // returning multiple values will result in Postgres error
|
|
10496
|
-
* column3: db.otherTable.get('someColumn'),
|
|
10499
|
+
* column3: () => db.otherTable.get('someColumn'),
|
|
10497
10500
|
*
|
|
10498
10501
|
* // select a single value from a related record
|
|
10499
10502
|
* fromRelation: (q) => q.relatedTable.get('someColumn'),
|
|
@@ -10510,16 +10513,16 @@ class Update {
|
|
|
10510
10513
|
* ```ts
|
|
10511
10514
|
* await db.table.where({ ...conditions }).update({
|
|
10512
10515
|
* // `column` will be set to a value of the `otherColumn` of the created record.
|
|
10513
|
-
* column: db.otherTable.get('otherColumn').create({ ...data }),
|
|
10516
|
+
* column: () => db.otherTable.get('otherColumn').create({ ...data }),
|
|
10514
10517
|
*
|
|
10515
10518
|
* // `column2` will be set to a value of the `otherColumn` of the updated record.
|
|
10516
|
-
* column2: db.otherTable
|
|
10519
|
+
* column2: () => db.otherTable
|
|
10517
10520
|
* .get('otherColumn')
|
|
10518
10521
|
* .findBy({ ...conditions })
|
|
10519
10522
|
* .update({ key: 'value' }),
|
|
10520
10523
|
*
|
|
10521
10524
|
* // `column3` will be set to a value of the `otherColumn` of the deleted record.
|
|
10522
|
-
* column3: db.otherTable
|
|
10525
|
+
* column3: () => db.otherTable
|
|
10523
10526
|
* .get('otherColumn')
|
|
10524
10527
|
* .findBy({ ...conditions })
|
|
10525
10528
|
* .delete(),
|
|
@@ -13151,7 +13154,7 @@ exports.queryTypeWithLimitOne = queryTypeWithLimitOne;
|
|
|
13151
13154
|
exports.queryWrap = queryWrap;
|
|
13152
13155
|
exports.raw = raw;
|
|
13153
13156
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
13154
|
-
exports.
|
|
13157
|
+
exports.resolveSubQueryCallbackV2 = resolveSubQueryCallbackV2;
|
|
13155
13158
|
exports.rollbackSql = rollbackSql$1;
|
|
13156
13159
|
exports.saveSearchAlias = saveSearchAlias;
|
|
13157
13160
|
exports.setColumnDefaultParse = setColumnDefaultParse;
|