pqb 0.46.1 → 0.46.4
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 +15 -4
- package/dist/index.js +134 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -344,7 +344,7 @@ interface HandleResult {
|
|
|
344
344
|
}
|
|
345
345
|
interface CommonQueryData {
|
|
346
346
|
adapter: Adapter;
|
|
347
|
-
shape:
|
|
347
|
+
shape: ColumnsShape;
|
|
348
348
|
patchResult?(q: Query, hookSelect: HookSelect | undefined, queryResult: QueryResult): Promise<void>;
|
|
349
349
|
handleResult: HandleResult;
|
|
350
350
|
returnType: QueryReturnType;
|
|
@@ -368,6 +368,10 @@ interface CommonQueryData {
|
|
|
368
368
|
outerAliases?: RecordString;
|
|
369
369
|
schema?: string;
|
|
370
370
|
select?: SelectItem[];
|
|
371
|
+
selectCache?: {
|
|
372
|
+
sql: string;
|
|
373
|
+
aliases: string[];
|
|
374
|
+
};
|
|
371
375
|
selectAllColumns?: string[];
|
|
372
376
|
selectAllKeys?: RecordUnknown;
|
|
373
377
|
/**
|
|
@@ -3286,7 +3290,7 @@ declare class TsVectorColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
|
|
|
3286
3290
|
*
|
|
3287
3291
|
* @param args
|
|
3288
3292
|
*/
|
|
3289
|
-
generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): T
|
|
3293
|
+
generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): GeneratedColumn<T>;
|
|
3290
3294
|
}
|
|
3291
3295
|
declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
3292
3296
|
dataType: "tsquery";
|
|
@@ -3707,6 +3711,7 @@ declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, transa
|
|
|
3707
3711
|
|
|
3708
3712
|
interface ToSQLCtx {
|
|
3709
3713
|
queryBuilder: Db;
|
|
3714
|
+
q: QueryData;
|
|
3710
3715
|
sql: string[];
|
|
3711
3716
|
values: unknown[];
|
|
3712
3717
|
aliasValue?: true;
|
|
@@ -8102,7 +8107,13 @@ interface ColumnData extends ColumnDataBase {
|
|
|
8102
8107
|
foreignKeys?: TableData.ColumnReferences[];
|
|
8103
8108
|
identity?: TableData.Identity;
|
|
8104
8109
|
generated?: ColumnDataGenerated;
|
|
8110
|
+
readonly?: boolean;
|
|
8105
8111
|
}
|
|
8112
|
+
type GeneratedColumn<T extends PickColumnData> = {
|
|
8113
|
+
[K in keyof T]: K extends 'data' ? {
|
|
8114
|
+
[K in keyof T['data']]: K extends 'default' ? true : T['data'][K];
|
|
8115
|
+
} : K extends 'inputType' ? never : T[K];
|
|
8116
|
+
};
|
|
8106
8117
|
interface ColumnDataGenerated {
|
|
8107
8118
|
toSQL(ctx: {
|
|
8108
8119
|
values: unknown[];
|
|
@@ -8450,7 +8461,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
8450
8461
|
*
|
|
8451
8462
|
* @param args - raw SQL
|
|
8452
8463
|
*/
|
|
8453
|
-
generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs): T
|
|
8464
|
+
generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs): GeneratedColumn<T>;
|
|
8454
8465
|
}
|
|
8455
8466
|
|
|
8456
8467
|
declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
|
|
@@ -8824,4 +8835,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8824
8835
|
*/
|
|
8825
8836
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8826
8837
|
|
|
8827
|
-
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 PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultReturnTypeSinglePrimaryKey, 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, 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, makeSQL, 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 };
|
|
8838
|
+
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 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 PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultReturnTypeSinglePrimaryKey, 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, 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, makeSQL, 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
|
@@ -416,7 +416,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
416
416
|
*/
|
|
417
417
|
generated(...args) {
|
|
418
418
|
const sql = raw(...args);
|
|
419
|
-
|
|
419
|
+
const column = orchidCore.setColumnData(this, "generated", {
|
|
420
420
|
toSQL(ctx, quoted) {
|
|
421
421
|
return sql.toSQL(ctx, quoted);
|
|
422
422
|
},
|
|
@@ -431,6 +431,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
431
431
|
return sql2;
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
|
+
column.data.readonly = true;
|
|
435
|
+
return column;
|
|
434
436
|
}
|
|
435
437
|
}
|
|
436
438
|
|
|
@@ -1528,7 +1530,7 @@ class TsVectorColumn extends ColumnType {
|
|
|
1528
1530
|
let sql;
|
|
1529
1531
|
if (Array.isArray(target)) {
|
|
1530
1532
|
const columns = target.length === 1 ? `"${snakeCase ? orchidCore.toSnakeCase(target[0]) : target[0]}"` : target.map(
|
|
1531
|
-
(
|
|
1533
|
+
(column2) => `coalesce("${snakeCase ? orchidCore.toSnakeCase(column2) : column2}", '')`
|
|
1532
1534
|
).join(` || ' ' || `);
|
|
1533
1535
|
sql = `to_tsvector('${language}', ${columns})`;
|
|
1534
1536
|
} else {
|
|
@@ -1566,10 +1568,12 @@ class TsVectorColumn extends ColumnType {
|
|
|
1566
1568
|
}
|
|
1567
1569
|
return code + ")";
|
|
1568
1570
|
};
|
|
1569
|
-
|
|
1571
|
+
const column = orchidCore.setColumnData(this, "generated", {
|
|
1570
1572
|
toSQL,
|
|
1571
1573
|
toCode
|
|
1572
1574
|
});
|
|
1575
|
+
column.data.readonly = true;
|
|
1576
|
+
return column;
|
|
1573
1577
|
}
|
|
1574
1578
|
}
|
|
1575
1579
|
class TsQueryColumn extends ColumnType {
|
|
@@ -2050,7 +2054,8 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
2050
2054
|
const table = column.slice(0, index);
|
|
2051
2055
|
const key = column.slice(index + 1);
|
|
2052
2056
|
if (key === "*") {
|
|
2053
|
-
|
|
2057
|
+
const shape2 = data.joinedShapes?.[table];
|
|
2058
|
+
return shape2 ? select ? makeRowToJson(table, shape2, true) : `"${table}".*` : column;
|
|
2054
2059
|
}
|
|
2055
2060
|
const tableName = data.aliases?.[table] || table;
|
|
2056
2061
|
const quoted = `"${table}"`;
|
|
@@ -2066,7 +2071,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
2066
2071
|
}
|
|
2067
2072
|
return `"${tableName}"."${key}"`;
|
|
2068
2073
|
};
|
|
2069
|
-
const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
2074
|
+
const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList) => {
|
|
2070
2075
|
const index = column.indexOf(".");
|
|
2071
2076
|
return index !== -1 ? tableColumnToSqlWithAs(
|
|
2072
2077
|
ctx,
|
|
@@ -2075,26 +2080,18 @@ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
|
2075
2080
|
column.slice(0, index),
|
|
2076
2081
|
column.slice(index + 1),
|
|
2077
2082
|
as,
|
|
2078
|
-
quotedAs
|
|
2083
|
+
quotedAs,
|
|
2084
|
+
select,
|
|
2085
|
+
jsonList
|
|
2086
|
+
) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select, jsonList);
|
|
2079
2087
|
};
|
|
2080
|
-
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
|
|
2088
|
+
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select, jsonList) => {
|
|
2081
2089
|
if (key === "*") {
|
|
2090
|
+
if (jsonList) jsonList[as] = void 0;
|
|
2082
2091
|
const shape = data.joinedShapes?.[table];
|
|
2083
2092
|
if (shape) {
|
|
2084
2093
|
{
|
|
2085
|
-
|
|
2086
|
-
const list = [];
|
|
2087
|
-
for (const key2 in shape) {
|
|
2088
|
-
const column2 = shape[key2];
|
|
2089
|
-
if (column2.data.explicitSelect || column2 instanceof VirtualColumn) {
|
|
2090
|
-
continue;
|
|
2091
|
-
}
|
|
2092
|
-
if (column2.data.name) {
|
|
2093
|
-
isSimple = false;
|
|
2094
|
-
}
|
|
2095
|
-
list.push(`'${key2}'`, `"${table}"."${column2.data.name || key2}"`);
|
|
2096
|
-
}
|
|
2097
|
-
return (isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")") + ` "${as}"`;
|
|
2094
|
+
return makeRowToJson(table, shape, true) + ` "${as}"`;
|
|
2098
2095
|
}
|
|
2099
2096
|
}
|
|
2100
2097
|
return column;
|
|
@@ -2116,12 +2113,10 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
2116
2113
|
)} "${as}"`;
|
|
2117
2114
|
}
|
|
2118
2115
|
}
|
|
2116
|
+
if (jsonList) jsonList[as] = col;
|
|
2119
2117
|
return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
|
|
2120
2118
|
};
|
|
2121
|
-
const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
2122
|
-
if (!select && data.joinedShapes?.[column]) {
|
|
2123
|
-
return select ? `row_to_json("${column}".*) "${as}"` : `"${column}".r "${as}"`;
|
|
2124
|
-
}
|
|
2119
|
+
const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList) => {
|
|
2125
2120
|
const col = data.shape[column];
|
|
2126
2121
|
if (col) {
|
|
2127
2122
|
if (col.data.name && col.data.name !== column) {
|
|
@@ -2137,6 +2132,7 @@ const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
|
2137
2132
|
)} "${as}"`;
|
|
2138
2133
|
}
|
|
2139
2134
|
}
|
|
2135
|
+
if (jsonList) jsonList[as] = col;
|
|
2140
2136
|
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
|
|
2141
2137
|
};
|
|
2142
2138
|
const rawOrColumnToSql = (ctx, data, expr, quotedAs, shape = data.shape, select) => {
|
|
@@ -2145,6 +2141,23 @@ const rawOrColumnToSql = (ctx, data, expr, quotedAs, shape = data.shape, select)
|
|
|
2145
2141
|
const quoteSchemaAndTable = (schema, table) => {
|
|
2146
2142
|
return schema ? `"${schema}"."${table}"` : `"${table}"`;
|
|
2147
2143
|
};
|
|
2144
|
+
const makeRowToJson = (table, shape, aliasName) => {
|
|
2145
|
+
let isSimple = true;
|
|
2146
|
+
const list = [];
|
|
2147
|
+
for (const key in shape) {
|
|
2148
|
+
const column = shape[key];
|
|
2149
|
+
if (column.data.explicitSelect || column instanceof VirtualColumn) {
|
|
2150
|
+
continue;
|
|
2151
|
+
}
|
|
2152
|
+
if (aliasName && column.data.name || column.data.jsonCast) {
|
|
2153
|
+
isSimple = false;
|
|
2154
|
+
}
|
|
2155
|
+
list.push(
|
|
2156
|
+
`'${key}', "${table}"."${aliasName && column.data.name || key}"${column.data.jsonCast ? `::${column.data.jsonCast}` : ""}`
|
|
2157
|
+
);
|
|
2158
|
+
}
|
|
2159
|
+
return isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")";
|
|
2160
|
+
};
|
|
2148
2161
|
|
|
2149
2162
|
const queryTypeWithLimitOne = {
|
|
2150
2163
|
one: true,
|
|
@@ -2500,6 +2513,7 @@ class NumberAsStringBaseColumn extends ColumnType {
|
|
|
2500
2513
|
constructor(schema) {
|
|
2501
2514
|
super(schema, schema.stringSchema());
|
|
2502
2515
|
this.operators = Operators.number;
|
|
2516
|
+
this.data.jsonCast = "text";
|
|
2503
2517
|
}
|
|
2504
2518
|
}
|
|
2505
2519
|
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
@@ -3059,6 +3073,7 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3059
3073
|
const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
|
|
3060
3074
|
data.computed = item;
|
|
3061
3075
|
data.explicitSelect = true;
|
|
3076
|
+
data.readonly = true;
|
|
3062
3077
|
}
|
|
3063
3078
|
}
|
|
3064
3079
|
q.computeAtRuntime = q.computeBatchAtRuntime = void 0;
|
|
@@ -4411,15 +4426,53 @@ function cloneQueryBaseUnscoped(query) {
|
|
|
4411
4426
|
return q;
|
|
4412
4427
|
}
|
|
4413
4428
|
|
|
4429
|
+
class RowToJsonExpression extends orchidCore.Expression {
|
|
4430
|
+
constructor(from, one, coalesce) {
|
|
4431
|
+
super();
|
|
4432
|
+
this.from = from;
|
|
4433
|
+
this.one = one;
|
|
4434
|
+
this.coalesce = coalesce;
|
|
4435
|
+
this.result = { value: UnknownColumn.instance };
|
|
4436
|
+
this.q = { expr: this };
|
|
4437
|
+
}
|
|
4438
|
+
makeSQL(ctx) {
|
|
4439
|
+
const q = this.from;
|
|
4440
|
+
const aliases = [];
|
|
4441
|
+
const jsonList = {};
|
|
4442
|
+
const select = selectToSql(
|
|
4443
|
+
ctx,
|
|
4444
|
+
q,
|
|
4445
|
+
q.q,
|
|
4446
|
+
`"${getQueryAs(q)}"`,
|
|
4447
|
+
q.q.hookSelect,
|
|
4448
|
+
aliases,
|
|
4449
|
+
void 0,
|
|
4450
|
+
jsonList
|
|
4451
|
+
);
|
|
4452
|
+
q.q.selectCache = { sql: select, aliases };
|
|
4453
|
+
let rowToJson;
|
|
4454
|
+
if (Object.values(jsonList).some((x) => x?.data.jsonCast)) {
|
|
4455
|
+
rowToJson = `json_build_object(${Object.entries(jsonList).map(
|
|
4456
|
+
([key, column]) => `'${key}', t."${key}"${column?.data.jsonCast ? `::${column.data.jsonCast}` : ""}`
|
|
4457
|
+
).join(", ")})`;
|
|
4458
|
+
} else {
|
|
4459
|
+
rowToJson = "row_to_json(t.*)";
|
|
4460
|
+
}
|
|
4461
|
+
return this.one ? rowToJson : this.coalesce !== false ? `COALESCE(json_agg(${rowToJson}), '[]')` : `json_agg(${rowToJson})`;
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4414
4464
|
function queryJson(self, coalesce) {
|
|
4465
|
+
const inner = self.clone();
|
|
4415
4466
|
const q = queryWrap(
|
|
4416
|
-
|
|
4467
|
+
inner,
|
|
4417
4468
|
cloneQueryBaseUnscoped(self)
|
|
4418
4469
|
);
|
|
4419
4470
|
_queryGetOptional(
|
|
4420
4471
|
q,
|
|
4421
|
-
new
|
|
4422
|
-
|
|
4472
|
+
new RowToJsonExpression(
|
|
4473
|
+
inner,
|
|
4474
|
+
queryTypeWithLimitOne[self.q.returnType],
|
|
4475
|
+
coalesce
|
|
4423
4476
|
)
|
|
4424
4477
|
);
|
|
4425
4478
|
q.q.returnsOne = true;
|
|
@@ -4726,17 +4779,22 @@ const makeReturningSql = (ctx, q, data, quotedAs, hookSelectI, addHookSelectI) =
|
|
|
4726
4779
|
};
|
|
4727
4780
|
|
|
4728
4781
|
const pushSelectSql = (ctx, table, query, quotedAs, aliases) => {
|
|
4729
|
-
|
|
4730
|
-
ctx
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4782
|
+
if (query.selectCache) {
|
|
4783
|
+
ctx.sql.push(query.selectCache.sql);
|
|
4784
|
+
if (aliases) aliases.push(...query.selectCache.aliases);
|
|
4785
|
+
} else {
|
|
4786
|
+
const sql = selectToSql(
|
|
4787
|
+
ctx,
|
|
4788
|
+
table,
|
|
4789
|
+
query,
|
|
4790
|
+
quotedAs,
|
|
4791
|
+
query.hookSelect,
|
|
4792
|
+
aliases
|
|
4793
|
+
);
|
|
4794
|
+
if (sql) ctx.sql.push(sql);
|
|
4795
|
+
}
|
|
4738
4796
|
};
|
|
4739
|
-
const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect, aliases, skipCTE) => {
|
|
4797
|
+
const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect, aliases, skipCTE, jsonList) => {
|
|
4740
4798
|
if (query.inCTE && !skipCTE) {
|
|
4741
4799
|
const { select } = makeReturningSql(
|
|
4742
4800
|
ctx,
|
|
@@ -4759,13 +4817,15 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4759
4817
|
selected[key] = quotedAs;
|
|
4760
4818
|
}
|
|
4761
4819
|
}
|
|
4762
|
-
sql = selectAllSql(query, quotedAs);
|
|
4820
|
+
sql = selectAllSql(query, quotedAs, jsonList);
|
|
4763
4821
|
} else {
|
|
4764
4822
|
const index = item.indexOf(".");
|
|
4765
4823
|
if (index !== -1) {
|
|
4766
4824
|
const tableName = item.slice(0, index);
|
|
4767
4825
|
const key = item.slice(index + 1);
|
|
4768
|
-
if (hookSelect?.get(key))
|
|
4826
|
+
if (hookSelect?.get(key)) {
|
|
4827
|
+
(selected ?? (selected = {}))[key] = `"${tableName}"`;
|
|
4828
|
+
}
|
|
4769
4829
|
sql = tableColumnToSqlWithAs(
|
|
4770
4830
|
ctx,
|
|
4771
4831
|
table.q,
|
|
@@ -4773,7 +4833,10 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4773
4833
|
tableName,
|
|
4774
4834
|
key,
|
|
4775
4835
|
key === "*" ? tableName : key,
|
|
4776
|
-
quotedAs
|
|
4836
|
+
quotedAs,
|
|
4837
|
+
true,
|
|
4838
|
+
jsonList
|
|
4839
|
+
);
|
|
4777
4840
|
} else {
|
|
4778
4841
|
if (hookSelect?.get(item)) (selected ?? (selected = {}))[item] = quotedAs;
|
|
4779
4842
|
sql = ownColumnToSqlWithAs(
|
|
@@ -4782,7 +4845,8 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4782
4845
|
item,
|
|
4783
4846
|
item,
|
|
4784
4847
|
quotedAs,
|
|
4785
|
-
true
|
|
4848
|
+
true,
|
|
4849
|
+
jsonList
|
|
4786
4850
|
);
|
|
4787
4851
|
}
|
|
4788
4852
|
}
|
|
@@ -4797,9 +4861,15 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4797
4861
|
if (typeof value === "object") {
|
|
4798
4862
|
if (orchidCore.isExpression(value)) {
|
|
4799
4863
|
list.push(`${value.toSQL(ctx, quotedAs)} "${as}"`);
|
|
4864
|
+
if (jsonList) {
|
|
4865
|
+
jsonList[as] = value.result.value;
|
|
4866
|
+
}
|
|
4800
4867
|
aliases?.push(as);
|
|
4801
4868
|
} else {
|
|
4802
|
-
pushSubQuerySql(ctx, value, as, list, quotedAs, aliases);
|
|
4869
|
+
pushSubQuerySql(ctx, query, value, as, list, quotedAs, aliases);
|
|
4870
|
+
if (jsonList) {
|
|
4871
|
+
jsonList[as] = value.q.returnType === "value" || value.q.returnType === "valueOrThrow" ? value.q.expr?.result.value || value.result?.value : void 0;
|
|
4872
|
+
}
|
|
4803
4873
|
}
|
|
4804
4874
|
} else if (value) {
|
|
4805
4875
|
list.push(
|
|
@@ -4809,7 +4879,8 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4809
4879
|
value,
|
|
4810
4880
|
as,
|
|
4811
4881
|
quotedAs,
|
|
4812
|
-
true
|
|
4882
|
+
true,
|
|
4883
|
+
jsonList
|
|
4813
4884
|
)
|
|
4814
4885
|
);
|
|
4815
4886
|
aliases?.push(as);
|
|
@@ -4843,32 +4914,39 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4843
4914
|
col = query.shape[select];
|
|
4844
4915
|
sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
|
|
4845
4916
|
}
|
|
4917
|
+
let name = columnName;
|
|
4846
4918
|
if (selected?.[columnName]) {
|
|
4847
4919
|
if (selected?.[columnName] === quotedTable) {
|
|
4848
4920
|
hookSelect.delete(column);
|
|
4849
4921
|
continue;
|
|
4850
4922
|
}
|
|
4851
4923
|
let i = 2;
|
|
4852
|
-
let name;
|
|
4853
4924
|
while (selected[name = `${column}${i}`]) i++;
|
|
4854
4925
|
item.as = name;
|
|
4855
4926
|
sql += ` "${name}"`;
|
|
4856
4927
|
} else if (col?.data.name) {
|
|
4857
4928
|
sql += ` "${columnName}"`;
|
|
4858
4929
|
}
|
|
4930
|
+
if (jsonList) jsonList[name] = col;
|
|
4859
4931
|
list.push(sql);
|
|
4860
4932
|
}
|
|
4861
4933
|
}
|
|
4862
|
-
return list.length ? list.join(", ") : query.select ? "" : selectAllSql(query, quotedAs);
|
|
4934
|
+
return list.length ? list.join(", ") : query.select ? "" : selectAllSql(query, quotedAs, jsonList);
|
|
4863
4935
|
};
|
|
4864
4936
|
function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
4865
4937
|
const sql = item.toSQL(ctx, quotedAs);
|
|
4866
4938
|
return ctx.aliasValue ? `${sql} r` : sql;
|
|
4867
4939
|
}
|
|
4868
|
-
const selectAllSql = (query, quotedAs) => {
|
|
4940
|
+
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
4941
|
+
if (jsonList) {
|
|
4942
|
+
Object.assign(
|
|
4943
|
+
jsonList,
|
|
4944
|
+
query.selectAllKeys || query.shape
|
|
4945
|
+
);
|
|
4946
|
+
}
|
|
4869
4947
|
return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
|
|
4870
4948
|
};
|
|
4871
|
-
const pushSubQuerySql = (ctx, query, as, list, quotedAs, aliases) => {
|
|
4949
|
+
const pushSubQuerySql = (ctx, mainQuery, query, as, list, quotedAs, aliases) => {
|
|
4872
4950
|
const { returnType = "all" } = query.q;
|
|
4873
4951
|
if (isQueryNone(query)) {
|
|
4874
4952
|
let sql;
|
|
@@ -4901,9 +4979,12 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs, aliases) => {
|
|
|
4901
4979
|
let sql;
|
|
4902
4980
|
switch (returnType) {
|
|
4903
4981
|
case "one":
|
|
4904
|
-
case "oneOrThrow":
|
|
4905
|
-
|
|
4982
|
+
case "oneOrThrow": {
|
|
4983
|
+
const table = query.q.joinedForSelect;
|
|
4984
|
+
const shape = mainQuery.joinedShapes?.[as];
|
|
4985
|
+
sql = makeRowToJson(table, shape, false);
|
|
4906
4986
|
break;
|
|
4987
|
+
}
|
|
4907
4988
|
case "all":
|
|
4908
4989
|
case "pluck":
|
|
4909
4990
|
case "value":
|
|
@@ -5411,6 +5492,7 @@ const makeSQL = (table, options) => {
|
|
|
5411
5492
|
const values = options?.values || [];
|
|
5412
5493
|
const ctx = {
|
|
5413
5494
|
queryBuilder: table.queryBuilder,
|
|
5495
|
+
q: query,
|
|
5414
5496
|
sql,
|
|
5415
5497
|
values,
|
|
5416
5498
|
aliasValue: options?.aliasValue
|
|
@@ -8192,7 +8274,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
|
|
|
8192
8274
|
item[key]
|
|
8193
8275
|
);
|
|
8194
8276
|
}
|
|
8195
|
-
if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.
|
|
8277
|
+
if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.readonly || shape === anyShape) && item[key] !== void 0) {
|
|
8196
8278
|
ctx.columns.set(key, ctx.columns.size);
|
|
8197
8279
|
encoders[key] = shape[key]?.data.encode;
|
|
8198
8280
|
}
|
|
@@ -10462,7 +10544,7 @@ const _queryUpdate = (query, arg) => {
|
|
|
10462
10544
|
if (item instanceof VirtualColumn && item.update) {
|
|
10463
10545
|
item.update(query, ctx, set);
|
|
10464
10546
|
delete set[key];
|
|
10465
|
-
} else if ((!shape[key] || shape[key].data.
|
|
10547
|
+
} else if ((!shape[key] || shape[key].data.readonly) && shape !== anyShape) {
|
|
10466
10548
|
delete set[key];
|
|
10467
10549
|
} else {
|
|
10468
10550
|
let value = set[key];
|
|
@@ -12801,6 +12883,7 @@ const performQuery = async (q, args, method) => {
|
|
|
12801
12883
|
sql = {
|
|
12802
12884
|
text: templateLiteralToSQL(args, {
|
|
12803
12885
|
queryBuilder: q.queryBuilder,
|
|
12886
|
+
q: q.q,
|
|
12804
12887
|
sql: [],
|
|
12805
12888
|
values
|
|
12806
12889
|
}),
|