pqb 0.51.1 → 0.51.3
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 +51 -21
- package/dist/index.js +85 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
2
2
|
import * as orchid_core from 'orchid-core';
|
|
3
|
-
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, EmptyObject, QueryColumns,
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, QueryColumn, EmptyObject, QueryColumns, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ValExpression, PickOutputType, QueryThen, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryCatch, TransactionState, QueryColumnOfDataType, PickQueryUniqueProperties, PickQueryMetaResult, PickQueryTableMetaResultInputType, UnionToIntersection, getValueKey, QueryThenByReturnType, QueryMetaIsSubQuery, PickQueryReturnType, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, PickQueryTableMetaShape, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
6
|
|
|
@@ -257,14 +257,17 @@ declare module 'orchid-core' {
|
|
|
257
257
|
computed?: Expression;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
type ComputedColumnsFromOptions<T extends ComputedOptionsFactory<never, never> | undefined> = T extends ((...args: any[]) => infer R extends {
|
|
261
|
-
[K
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
type ComputedColumnsFromOptions<T extends ComputedOptionsFactory<never, never> | undefined> = T extends ((...args: any[]) => infer R extends ComputedOptionsConfig) ? {
|
|
261
|
+
[K in keyof R]: R[K] extends QueryOrExpression<unknown> ? R[K]['result']['value'] : R[K] extends () => {
|
|
262
|
+
result: {
|
|
263
|
+
value: infer Value extends QueryColumn;
|
|
264
|
+
};
|
|
265
|
+
} ? Value : never;
|
|
264
266
|
} : EmptyObject;
|
|
265
|
-
|
|
266
|
-
[K: string]: QueryOrExpression<unknown>;
|
|
267
|
-
}
|
|
267
|
+
interface ComputedOptionsConfig {
|
|
268
|
+
[K: string]: QueryOrExpression<unknown> | ReturnsQueryOrExpression<unknown>;
|
|
269
|
+
}
|
|
270
|
+
type ComputedOptionsFactory<ColumnTypes, Shape extends QueryColumns> = (t: ComputedMethods<ColumnTypes, Shape>) => ComputedOptionsConfig;
|
|
268
271
|
interface RuntimeComputedQueryColumn<OutputType> extends QueryColumn {
|
|
269
272
|
dataType: 'runtimeComputed';
|
|
270
273
|
type: never;
|
|
@@ -377,7 +380,10 @@ interface CommonQueryData {
|
|
|
377
380
|
aliases: string[];
|
|
378
381
|
};
|
|
379
382
|
selectAllColumns?: string[];
|
|
380
|
-
|
|
383
|
+
/**
|
|
384
|
+
* Subset of the `shape` that only includes columns with no `data.explicitSelect`.
|
|
385
|
+
*/
|
|
386
|
+
selectAllShape: RecordUnknown;
|
|
381
387
|
/**
|
|
382
388
|
* column type for query with 'value' or 'valueOrThrow' return type
|
|
383
389
|
* Is needed in {@link getShapeFromSelect} to get shape of sub-select that returns a single value.
|
|
@@ -5589,9 +5595,9 @@ interface QueryBatchResult {
|
|
|
5589
5595
|
parent: any;
|
|
5590
5596
|
key: PropertyKey;
|
|
5591
5597
|
}
|
|
5592
|
-
declare const addParserForSelectItem: <T extends PickQueryMeta>(q: T, as: string | getValueKey | undefined, key: string, arg: SelectableOrExpression<T> | Query, joinQuery?: boolean) => string | Expression | Query | undefined;
|
|
5598
|
+
declare const addParserForSelectItem: <T extends PickQueryMeta>(q: T, as: string | getValueKey | undefined, key: string, arg: SelectableOrExpression<T> | Query, columnAlias?: string, joinQuery?: boolean) => string | Expression | Query | undefined;
|
|
5593
5599
|
declare const processSelectArg: <T extends SelectSelf>(q: T, as: string | undefined, arg: SelectArg<T>, columnAs?: string | getValueKey) => SelectItem | undefined | false;
|
|
5594
|
-
declare const setParserForSelectedString: (query: PickQueryQAndInternal, arg: string, as: string | getValueKey | undefined, columnAs?: string | getValueKey) => string | undefined;
|
|
5600
|
+
declare const setParserForSelectedString: (query: PickQueryQAndInternal, arg: string, as: string | getValueKey | undefined, columnAs?: string | getValueKey, columnAlias?: string) => string | undefined;
|
|
5595
5601
|
declare const getShapeFromSelect: (q: IsQuery, isSubQuery?: boolean) => QueryColumns;
|
|
5596
5602
|
declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>>(q: T, columns: Columns): SelectResult<T, Columns>;
|
|
5597
5603
|
declare function _querySelect<T extends SelectSelf, Obj extends SelectAsArg<T>>(q: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
@@ -7192,11 +7198,22 @@ interface QueryHelper<T extends PickQueryTableMetaShape, Args extends any[], Res
|
|
|
7192
7198
|
result: Result;
|
|
7193
7199
|
}
|
|
7194
7200
|
type QueryHelperResult<T extends QueryHelper<PickQueryMetaShape, any[], unknown>> = T['result'];
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7201
|
+
interface NarrowTypeSelf extends PickQueryMetaResultReturnType {
|
|
7202
|
+
returnType: undefined | 'all' | 'one' | 'oneOrThrow' | 'value' | 'valueOrThrow' | 'pluck';
|
|
7203
|
+
}
|
|
7204
|
+
type NarrowInvalidKeys<T extends PickQueryResult, Narrow> = {
|
|
7205
|
+
[K in keyof Narrow]: K extends keyof T['result'] ? Narrow[K] extends T['result'][K]['outputType'] ? never : K : K;
|
|
7206
|
+
}[keyof Narrow];
|
|
7207
|
+
interface NarrowValueTypeResult<T extends PickQueryMetaResultReturnType, Narrow> extends QueryColumns {
|
|
7208
|
+
value: {
|
|
7209
|
+
[K in keyof T['result']['value']]: K extends 'outputType' ? Narrow : T['result']['value'][K];
|
|
7210
|
+
};
|
|
7211
|
+
}
|
|
7212
|
+
interface NarrowPluckTypeResult<T extends PickQueryMetaResultReturnType, Narrow> extends QueryColumns {
|
|
7213
|
+
pluck: {
|
|
7214
|
+
[K in keyof T['result']['pluck']]: K extends 'outputType' ? Narrow extends unknown[] ? Narrow[number] : Narrow : T['result']['pluck'][K];
|
|
7215
|
+
};
|
|
7216
|
+
}
|
|
7200
7217
|
type QueryIfResult<T extends PickQueryMetaResultReturnType, R extends PickQueryResult> = {
|
|
7201
7218
|
[K in keyof T]: K extends 'result' ? {
|
|
7202
7219
|
[K in keyof T['result'] | keyof R['result']]: K extends keyof T['result'] ? K extends keyof R['result'] ? R['result'][K] | T['result'][K] : T['result'][K] : R['result'][K];
|
|
@@ -7794,9 +7811,19 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7794
7811
|
* .narrowType()<{ kind: 'first', approved: true }>();
|
|
7795
7812
|
* ```
|
|
7796
7813
|
*/
|
|
7797
|
-
narrowType<T extends
|
|
7798
|
-
[K in keyof T]: K extends 'result' ?
|
|
7799
|
-
|
|
7814
|
+
narrowType<T extends NarrowTypeSelf>(this: T): <Narrow>() => T['returnType'] extends undefined | 'all' | 'one' | 'oneOrThrow' ? [NarrowInvalidKeys<T, Narrow>] extends [never] ? {
|
|
7815
|
+
[K in keyof T]: K extends 'result' ? T['result'] & {
|
|
7816
|
+
[K in keyof Narrow]: {
|
|
7817
|
+
outputType: Narrow[K];
|
|
7818
|
+
};
|
|
7819
|
+
} : K extends 'then' ? QueryThenByQuery<T, T['result'] & {
|
|
7820
|
+
[K in keyof Narrow]: {
|
|
7821
|
+
outputType: Narrow[K];
|
|
7822
|
+
};
|
|
7823
|
+
}> : T[K];
|
|
7824
|
+
} : `narrowType() error: provided type does not extend the '${NarrowInvalidKeys<T, Narrow> & string}' column type` : (T['returnType'] extends 'pluck' ? Narrow extends unknown[] ? Narrow[number] : Narrow : Narrow) extends (T['returnType'] extends 'pluck' ? T['result']['pluck']['outputType'] : T['result']['value']['outputType']) ? {
|
|
7825
|
+
[K in keyof T]: K extends 'result' ? T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow> : K extends 'then' ? QueryThenByQuery<T, T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow>> : T[K];
|
|
7826
|
+
} : 'narrowType() error: provided type does not extend the returning column column type';
|
|
7800
7827
|
if<T extends PickQueryMetaResultReturnType, R extends PickQueryResult>(this: T, condition: boolean | null | undefined, fn: (q: T) => R & {
|
|
7801
7828
|
returnType: T['returnType'];
|
|
7802
7829
|
}): QueryIfResult<T, R>;
|
|
@@ -8129,6 +8156,9 @@ interface QueryOrExpression<T> {
|
|
|
8129
8156
|
value: QueryColumn<T>;
|
|
8130
8157
|
};
|
|
8131
8158
|
}
|
|
8159
|
+
interface ReturnsQueryOrExpression<T> {
|
|
8160
|
+
(): QueryOrExpression<T>;
|
|
8161
|
+
}
|
|
8132
8162
|
interface QueryOrExpressionBooleanOrNullResult {
|
|
8133
8163
|
result: {
|
|
8134
8164
|
value: QueryColumn<boolean | null>;
|
|
@@ -8604,7 +8634,7 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
|
|
|
8604
8634
|
declare const makeColumnTypes: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>(schema: SchemaConfig) => DefaultColumnTypes<SchemaConfig>;
|
|
8605
8635
|
|
|
8606
8636
|
declare const simplifyColumnDefault: (value?: string) => RawSQL<orchid_core.QueryColumn<unknown, any>, DefaultColumnTypes<orchid_core.ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>> | undefined;
|
|
8607
|
-
declare const
|
|
8637
|
+
declare const assignDbDataToColumn: (column: ColumnTypeBase, params: ColumnFromDbParams) => ColumnTypeBase;
|
|
8608
8638
|
|
|
8609
8639
|
interface ColumnsShape {
|
|
8610
8640
|
[K: string]: ColumnType;
|
|
@@ -8878,4 +8908,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8878
8908
|
*/
|
|
8879
8909
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8880
8910
|
|
|
8881
|
-
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 GeneratedColumn, 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 JoinResultRequireMain, 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 PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaRelationsReturnType, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsReturnType, 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 PickQueryShapeResultReturnTypeSinglePrimaryKey, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryTableMetaResultReturnTypeWithDataWindowsThen, 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, type QueryTake, type QueryTakeOptional, 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 SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, 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, 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, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
8911
|
+
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 ComputedOptionsConfig, 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 GeneratedColumn, 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 JoinResultRequireMain, 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 PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaRelationsReturnType, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsReturnType, 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 PickQueryShapeResultReturnTypeSinglePrimaryKey, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryTableMetaResultReturnTypeWithDataWindowsThen, 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, type QueryTake, type QueryTakeOptional, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type ReturnsQueryOrExpression, 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 SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, 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, assignDbDataToColumn, checkIfASimpleQuery, 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, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
package/dist/index.js
CHANGED
|
@@ -448,8 +448,7 @@ const simplifyColumnDefault = (value) => {
|
|
|
448
448
|
}
|
|
449
449
|
return;
|
|
450
450
|
};
|
|
451
|
-
const
|
|
452
|
-
const column = typeFn();
|
|
451
|
+
const assignDbDataToColumn = (column, params) => {
|
|
453
452
|
const { dateTimePrecision } = params;
|
|
454
453
|
Object.assign(column.data, {
|
|
455
454
|
...params,
|
|
@@ -3056,7 +3055,8 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3056
3055
|
q.computeBatchAtRuntime = computeBatchAtRuntime;
|
|
3057
3056
|
const computed = fn(q);
|
|
3058
3057
|
for (const key in computed) {
|
|
3059
|
-
|
|
3058
|
+
let item = computed[key];
|
|
3059
|
+
if (typeof item === "function") item = item.call(computed);
|
|
3060
3060
|
if (item instanceof ComputedColumn) {
|
|
3061
3061
|
q.q.computeds = {
|
|
3062
3062
|
...q.q.computeds,
|
|
@@ -3369,9 +3369,13 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3369
3369
|
let renames;
|
|
3370
3370
|
if (hookSelect) {
|
|
3371
3371
|
for (const column of hookSelect.keys()) {
|
|
3372
|
-
const as = hookSelect.get(column)
|
|
3373
|
-
if (as)
|
|
3374
|
-
|
|
3372
|
+
const { as, temp } = hookSelect.get(column);
|
|
3373
|
+
if (as) {
|
|
3374
|
+
(renames ?? (renames = {}))[column] = as;
|
|
3375
|
+
}
|
|
3376
|
+
if (temp) {
|
|
3377
|
+
(tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(temp);
|
|
3378
|
+
}
|
|
3375
3379
|
}
|
|
3376
3380
|
if (renames) {
|
|
3377
3381
|
for (const record of result) {
|
|
@@ -3438,9 +3442,11 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3438
3442
|
}
|
|
3439
3443
|
if (hookSelect || tempReturnType !== returnType) {
|
|
3440
3444
|
if (renames) {
|
|
3441
|
-
for (const
|
|
3442
|
-
for (const
|
|
3445
|
+
for (const a in renames) {
|
|
3446
|
+
for (const record of result) {
|
|
3447
|
+
const value = record[a];
|
|
3443
3448
|
record[a] = record[renames[a]];
|
|
3449
|
+
record[renames[a]] = value;
|
|
3444
3450
|
}
|
|
3445
3451
|
}
|
|
3446
3452
|
}
|
|
@@ -3483,7 +3489,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3483
3489
|
if (log && sql) {
|
|
3484
3490
|
log.onError(error, sql, logData);
|
|
3485
3491
|
}
|
|
3486
|
-
return reject
|
|
3492
|
+
if (reject) return reject(error);
|
|
3493
|
+
throw error;
|
|
3487
3494
|
}
|
|
3488
3495
|
};
|
|
3489
3496
|
const execQuery = (adapter, method, sql) => {
|
|
@@ -3906,7 +3913,7 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
|
|
|
3906
3913
|
);
|
|
3907
3914
|
}
|
|
3908
3915
|
};
|
|
3909
|
-
const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
|
|
3916
|
+
const addParserForSelectItem = (q, as, key, arg, columnAlias, joinQuery) => {
|
|
3910
3917
|
if (typeof arg === "object" || typeof arg === "function") {
|
|
3911
3918
|
const { q: query } = arg;
|
|
3912
3919
|
if (query.batchParsers) {
|
|
@@ -4078,7 +4085,13 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
|
|
|
4078
4085
|
}
|
|
4079
4086
|
return arg;
|
|
4080
4087
|
}
|
|
4081
|
-
return setParserForSelectedString(
|
|
4088
|
+
return setParserForSelectedString(
|
|
4089
|
+
q,
|
|
4090
|
+
arg,
|
|
4091
|
+
as,
|
|
4092
|
+
key,
|
|
4093
|
+
columnAlias
|
|
4094
|
+
);
|
|
4082
4095
|
};
|
|
4083
4096
|
const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
4084
4097
|
const stack = rows.map(
|
|
@@ -4170,15 +4183,18 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4170
4183
|
as,
|
|
4171
4184
|
key,
|
|
4172
4185
|
value,
|
|
4186
|
+
key,
|
|
4173
4187
|
joinQuery
|
|
4174
4188
|
);
|
|
4175
4189
|
}
|
|
4176
4190
|
return { selectAs };
|
|
4177
4191
|
};
|
|
4178
|
-
const setParserForSelectedString = (query, arg, as, columnAs) => {
|
|
4192
|
+
const setParserForSelectedString = (query, arg, as, columnAs, columnAlias) => {
|
|
4179
4193
|
const { q } = query;
|
|
4180
4194
|
const index = arg.indexOf(".");
|
|
4181
|
-
if (index === -1)
|
|
4195
|
+
if (index === -1) {
|
|
4196
|
+
return selectColumn(query, q, arg, columnAs, columnAlias);
|
|
4197
|
+
}
|
|
4182
4198
|
const table = getFullColumnTable(query, arg, index, as);
|
|
4183
4199
|
const column = arg.slice(index + 1);
|
|
4184
4200
|
if (column === "*") {
|
|
@@ -4186,7 +4202,7 @@ const setParserForSelectedString = (query, arg, as, columnAs) => {
|
|
|
4186
4202
|
return table === as ? column : arg;
|
|
4187
4203
|
}
|
|
4188
4204
|
if (table === as) {
|
|
4189
|
-
return selectColumn(query, q, column, columnAs);
|
|
4205
|
+
return selectColumn(query, q, column, columnAs, columnAlias);
|
|
4190
4206
|
}
|
|
4191
4207
|
const parser = q.joinedParsers?.[table]?.[column];
|
|
4192
4208
|
if (parser) orchidCore.setParserToQuery(q, columnAs || column, parser);
|
|
@@ -4215,24 +4231,24 @@ const setParserForSelectedString = (query, arg, as, columnAs) => {
|
|
|
4215
4231
|
}
|
|
4216
4232
|
return arg;
|
|
4217
4233
|
};
|
|
4218
|
-
const selectColumn = (query, q, key, columnAs) => {
|
|
4234
|
+
const selectColumn = (query, q, key, columnAs, columnAlias) => {
|
|
4219
4235
|
if (columnAs && q.parsers) {
|
|
4220
4236
|
const parser = q.parsers[key];
|
|
4221
4237
|
if (parser) orchidCore.setObjectValueImmutable(q, "parsers", columnAs, parser);
|
|
4222
4238
|
}
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
const
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
const map = q.q.hookSelect = new Map(q.q.hookSelect);
|
|
4229
|
-
for (const column2 of computed.deps) {
|
|
4230
|
-
map.set(column2, { select: column2 });
|
|
4239
|
+
if (q.computeds?.[key]) {
|
|
4240
|
+
const computed = q.computeds[key];
|
|
4241
|
+
const map = query.q.hookSelect = new Map(query.q.hookSelect);
|
|
4242
|
+
for (const key2 of computed.deps) {
|
|
4243
|
+
map.set(key2, { select: key2 });
|
|
4231
4244
|
}
|
|
4232
|
-
|
|
4245
|
+
query.q.selectedComputeds = {
|
|
4246
|
+
...query.q.selectedComputeds,
|
|
4247
|
+
[columnAlias || key]: computed
|
|
4248
|
+
};
|
|
4233
4249
|
return;
|
|
4234
4250
|
}
|
|
4235
|
-
return
|
|
4251
|
+
return key;
|
|
4236
4252
|
};
|
|
4237
4253
|
const getShapeFromSelect = (q, isSubQuery) => {
|
|
4238
4254
|
const query = q.q;
|
|
@@ -4252,7 +4268,9 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
4252
4268
|
result = {};
|
|
4253
4269
|
for (const key in shape) {
|
|
4254
4270
|
const column = shape[key];
|
|
4255
|
-
|
|
4271
|
+
if (!column.data.explicitSelect) {
|
|
4272
|
+
result[key] = column.data.name ? orchidCore.setColumnData(column, "name", void 0) : column;
|
|
4273
|
+
}
|
|
4256
4274
|
}
|
|
4257
4275
|
} else {
|
|
4258
4276
|
result = shape;
|
|
@@ -4312,10 +4330,12 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
|
|
|
4312
4330
|
}
|
|
4313
4331
|
} else if (arg === "*") {
|
|
4314
4332
|
for (const key2 in shape) {
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4333
|
+
if (!shape[key2].data.explicitSelect) {
|
|
4334
|
+
result[key2] = mapSubSelectColumn(
|
|
4335
|
+
shape[key2],
|
|
4336
|
+
isSubQuery
|
|
4337
|
+
);
|
|
4338
|
+
}
|
|
4319
4339
|
}
|
|
4320
4340
|
} else {
|
|
4321
4341
|
result[key || arg] = mapSubSelectColumn(
|
|
@@ -4834,6 +4854,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4834
4854
|
return query.inCTE.selectNum || !select ? select ? "0, " + select : "0" : select;
|
|
4835
4855
|
}
|
|
4836
4856
|
let selected;
|
|
4857
|
+
let selectedAs;
|
|
4837
4858
|
const list = [];
|
|
4838
4859
|
if (query.select) {
|
|
4839
4860
|
for (const item of query.select) {
|
|
@@ -4842,8 +4863,10 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4842
4863
|
if (item === "*") {
|
|
4843
4864
|
if (hookSelect) {
|
|
4844
4865
|
selected ?? (selected = {});
|
|
4845
|
-
|
|
4866
|
+
selectedAs ?? (selectedAs = {});
|
|
4867
|
+
for (const key in query.selectAllShape) {
|
|
4846
4868
|
selected[key] = quotedAs;
|
|
4869
|
+
selectedAs[key] = key;
|
|
4847
4870
|
}
|
|
4848
4871
|
}
|
|
4849
4872
|
sql = selectAllSql(query, quotedAs, jsonList);
|
|
@@ -4854,6 +4877,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4854
4877
|
const key = item.slice(index + 1);
|
|
4855
4878
|
if (hookSelect?.get(key)) {
|
|
4856
4879
|
(selected ?? (selected = {}))[key] = `"${tableName}"`;
|
|
4880
|
+
(selectedAs ?? (selectedAs = {}))[key] = key;
|
|
4857
4881
|
}
|
|
4858
4882
|
sql = tableColumnToSqlWithAs(
|
|
4859
4883
|
ctx,
|
|
@@ -4867,7 +4891,10 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4867
4891
|
jsonList
|
|
4868
4892
|
);
|
|
4869
4893
|
} else {
|
|
4870
|
-
if (hookSelect?.get(item))
|
|
4894
|
+
if (hookSelect?.get(item)) {
|
|
4895
|
+
(selected ?? (selected = {}))[item] = quotedAs;
|
|
4896
|
+
(selectedAs ?? (selectedAs = {}))[item] = item;
|
|
4897
|
+
}
|
|
4871
4898
|
sql = ownColumnToSqlWithAs(
|
|
4872
4899
|
ctx,
|
|
4873
4900
|
table.q,
|
|
@@ -4885,7 +4912,9 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4885
4912
|
if ("selectAs" in item) {
|
|
4886
4913
|
const obj = item.selectAs;
|
|
4887
4914
|
for (const as in obj) {
|
|
4888
|
-
if (hookSelect)
|
|
4915
|
+
if (hookSelect) {
|
|
4916
|
+
(selected ?? (selected = {}))[as] = true;
|
|
4917
|
+
}
|
|
4889
4918
|
const value = obj[as];
|
|
4890
4919
|
if (typeof value === "object") {
|
|
4891
4920
|
if (orchidCore.isExpression(value)) {
|
|
@@ -4901,6 +4930,9 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4901
4930
|
}
|
|
4902
4931
|
}
|
|
4903
4932
|
} else if (value) {
|
|
4933
|
+
if (hookSelect) {
|
|
4934
|
+
(selectedAs ?? (selectedAs = {}))[value] = as;
|
|
4935
|
+
}
|
|
4904
4936
|
list.push(
|
|
4905
4937
|
columnToSqlWithAs(
|
|
4906
4938
|
ctx,
|
|
@@ -4957,9 +4989,17 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4957
4989
|
let i = 2;
|
|
4958
4990
|
while (selected[name = `${column}${i}`]) i++;
|
|
4959
4991
|
item.as = name;
|
|
4992
|
+
item.temp = name;
|
|
4960
4993
|
sql += ` "${name}"`;
|
|
4961
|
-
} else if (
|
|
4962
|
-
|
|
4994
|
+
} else if (selectedAs?.[columnName]) {
|
|
4995
|
+
item.as = selectedAs[columnName];
|
|
4996
|
+
item.temp = columnName;
|
|
4997
|
+
continue;
|
|
4998
|
+
} else {
|
|
4999
|
+
if (col?.data.name || typeof select === "object") {
|
|
5000
|
+
sql += ` "${columnName}"`;
|
|
5001
|
+
}
|
|
5002
|
+
item.temp = columnName;
|
|
4963
5003
|
}
|
|
4964
5004
|
if (jsonList) jsonList[name] = col;
|
|
4965
5005
|
list.push(sql);
|
|
@@ -4973,7 +5013,7 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
|
4973
5013
|
}
|
|
4974
5014
|
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
4975
5015
|
if (jsonList) {
|
|
4976
|
-
Object.assign(jsonList, query.
|
|
5016
|
+
Object.assign(jsonList, query.selectAllShape);
|
|
4977
5017
|
}
|
|
4978
5018
|
return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
|
|
4979
5019
|
};
|
|
@@ -11773,7 +11813,7 @@ class ExpressionMethods {
|
|
|
11773
11813
|
column(name) {
|
|
11774
11814
|
const column = this.shape[name];
|
|
11775
11815
|
return new ColumnRefExpression(
|
|
11776
|
-
column,
|
|
11816
|
+
column || UnknownColumn.instance,
|
|
11777
11817
|
name
|
|
11778
11818
|
);
|
|
11779
11819
|
}
|
|
@@ -11815,12 +11855,12 @@ class ExpressionMethods {
|
|
|
11815
11855
|
if (table === as) {
|
|
11816
11856
|
column = shape[col];
|
|
11817
11857
|
} else {
|
|
11818
|
-
column = q.q.joinedShapes[table][col];
|
|
11858
|
+
column = q.q.joinedShapes?.[table][col];
|
|
11819
11859
|
}
|
|
11820
11860
|
} else {
|
|
11821
11861
|
column = shape[arg];
|
|
11822
11862
|
}
|
|
11823
|
-
return new RefExpression(column, q, arg);
|
|
11863
|
+
return new RefExpression(column || UnknownColumn.instance, q, arg);
|
|
11824
11864
|
}
|
|
11825
11865
|
val(value) {
|
|
11826
11866
|
return new orchidCore.ValExpression(value);
|
|
@@ -12700,7 +12740,7 @@ const parseIndexOrExclude = (item) => {
|
|
|
12700
12740
|
|
|
12701
12741
|
const anyShape = {};
|
|
12702
12742
|
class Db extends QueryMethods {
|
|
12703
|
-
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData =
|
|
12743
|
+
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = {}) {
|
|
12704
12744
|
super();
|
|
12705
12745
|
this.adapter = adapter;
|
|
12706
12746
|
this.queryBuilder = queryBuilder;
|
|
@@ -12794,26 +12834,21 @@ class Db extends QueryMethods {
|
|
|
12794
12834
|
);
|
|
12795
12835
|
this.columns = columns;
|
|
12796
12836
|
if (options.computed) applyComputedColumns(this, options.computed);
|
|
12797
|
-
const selectableShape = this.q.selectableShape = {};
|
|
12798
12837
|
if (prepareSelectAll) {
|
|
12838
|
+
const selectAllShape = this.q.selectAllShape = {};
|
|
12799
12839
|
const list = [];
|
|
12800
12840
|
for (const key in shape) {
|
|
12801
12841
|
const column = shape[key];
|
|
12802
|
-
if (!column.data.explicitSelect
|
|
12842
|
+
if (!column.data.explicitSelect) {
|
|
12803
12843
|
list.push(
|
|
12804
12844
|
column.data.name ? `"${column.data.name}" "${key}"` : `"${key}"`
|
|
12805
12845
|
);
|
|
12806
|
-
|
|
12846
|
+
selectAllShape[key] = column;
|
|
12807
12847
|
}
|
|
12808
12848
|
}
|
|
12809
12849
|
this.q.selectAllColumns = list;
|
|
12810
12850
|
} else {
|
|
12811
|
-
|
|
12812
|
-
const column = shape[key];
|
|
12813
|
-
if (column instanceof VirtualColumn) {
|
|
12814
|
-
selectableShape[key] = column;
|
|
12815
|
-
}
|
|
12816
|
-
}
|
|
12851
|
+
this.q.selectAllShape = shape;
|
|
12817
12852
|
}
|
|
12818
12853
|
if (modifyQuery) {
|
|
12819
12854
|
for (const cb of modifyQuery) {
|
|
@@ -13340,6 +13375,7 @@ exports.addParserForSelectItem = addParserForSelectItem;
|
|
|
13340
13375
|
exports.addQueryOn = addQueryOn;
|
|
13341
13376
|
exports.anyShape = anyShape;
|
|
13342
13377
|
exports.applyComputedColumns = applyComputedColumns;
|
|
13378
|
+
exports.assignDbDataToColumn = assignDbDataToColumn;
|
|
13343
13379
|
exports.checkIfASimpleQuery = checkIfASimpleQuery;
|
|
13344
13380
|
exports.cloneQueryBaseUnscoped = cloneQueryBaseUnscoped;
|
|
13345
13381
|
exports.columnCheckToCode = columnCheckToCode;
|
|
@@ -13375,7 +13411,6 @@ exports.handleResult = handleResult;
|
|
|
13375
13411
|
exports.identityToCode = identityToCode;
|
|
13376
13412
|
exports.indexInnerToCode = indexInnerToCode;
|
|
13377
13413
|
exports.indexToCode = indexToCode;
|
|
13378
|
-
exports.instantiateColumn = instantiateColumn;
|
|
13379
13414
|
exports.isDefaultTimeStamp = isDefaultTimeStamp;
|
|
13380
13415
|
exports.isQueryReturnsAll = isQueryReturnsAll;
|
|
13381
13416
|
exports.isSelectingCount = isSelectingCount;
|