pqb 0.54.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +26 -17
- package/dist/index.js +236 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -66
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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, PickQueryTableMetaResult, PickQueryShape, PickQueryTable, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, QueryColumn, EmptyObject, QueryColumns, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, 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, AfterCommitStandaloneHook, getValueKey, QueryThenByReturnType, QueryMetaIsSubQuery, PickQueryReturnType, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, PickQueryTableMetaShape, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, PickQueryTableMetaResult, PickQueryShape, PickQueryTable, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, QueryColumn, EmptyObject, QueryColumns, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryInputType, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, 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, AfterCommitStandaloneHook, 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
|
import { QueryResult as QueryResult$1, QueryBuilder as QueryBuilder$1, QueryInternal as QueryInternal$1, Adapter as Adapter$1, QueryData as QueryData$1 } from 'pqb';
|
|
@@ -336,7 +336,8 @@ type JoinedShapes = RecordOfColumnsShapeBase;
|
|
|
336
336
|
interface JoinedParsers {
|
|
337
337
|
[K: string]: ColumnsParsers | undefined;
|
|
338
338
|
}
|
|
339
|
-
type
|
|
339
|
+
type QueryBeforeHookInternal = (query: Query) => void | Promise<void>;
|
|
340
|
+
type QueryBeforeHook = (utils: QueryHookUtils<PickQueryInputType>) => void | Promise<void>;
|
|
340
341
|
type QueryAfterHook<Data = unknown> = (data: Data, query: Query) => unknown | Promise<unknown>;
|
|
341
342
|
interface QueryScopes {
|
|
342
343
|
[K: string]: QueryScopeData;
|
|
@@ -415,17 +416,17 @@ interface CommonQueryData {
|
|
|
415
416
|
hookSelect?: HookSelect;
|
|
416
417
|
computeds?: ComputedColumns;
|
|
417
418
|
selectedComputeds?: ComputedColumns;
|
|
418
|
-
before?:
|
|
419
|
+
before?: QueryBeforeHookInternal[];
|
|
419
420
|
after?: QueryAfterHook[];
|
|
420
|
-
beforeCreate?:
|
|
421
|
+
beforeCreate?: QueryBeforeHookInternal[];
|
|
421
422
|
afterCreate?: QueryAfterHook[];
|
|
422
423
|
afterCreateCommit?: QueryAfterHook[];
|
|
423
424
|
afterCreateSelect?: Set<string>;
|
|
424
|
-
beforeUpdate?:
|
|
425
|
+
beforeUpdate?: QueryBeforeHookInternal[];
|
|
425
426
|
afterUpdate?: QueryAfterHook[];
|
|
426
427
|
afterUpdateCommit?: QueryAfterHook[];
|
|
427
428
|
afterUpdateSelect?: Set<string>;
|
|
428
|
-
beforeDelete?:
|
|
429
|
+
beforeDelete?: QueryBeforeHookInternal[];
|
|
429
430
|
afterDelete?: QueryAfterHook[];
|
|
430
431
|
afterDeleteCommit?: QueryAfterHook[];
|
|
431
432
|
afterDeleteSelect?: Set<string>;
|
|
@@ -460,6 +461,8 @@ interface CommonQueryData {
|
|
|
460
461
|
targetHookSelect: HookSelect;
|
|
461
462
|
};
|
|
462
463
|
outerQuery?: Query;
|
|
464
|
+
hookCreateSet?: RecordUnknown[];
|
|
465
|
+
hookUpdateSet?: RecordUnknown[];
|
|
463
466
|
}
|
|
464
467
|
interface SelectQueryData extends CommonQueryData {
|
|
465
468
|
type: undefined | 'upsert';
|
|
@@ -482,15 +485,10 @@ interface SelectQueryData extends CommonQueryData {
|
|
|
482
485
|
mode?: 'NO WAIT' | 'SKIP LOCKED';
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
|
-
type CreateKind = 'object' | 'from';
|
|
486
488
|
interface InsertQueryData extends CommonQueryData {
|
|
487
489
|
type: 'insert';
|
|
488
|
-
kind: CreateKind;
|
|
489
490
|
columns: string[];
|
|
490
|
-
values:
|
|
491
|
-
from: Query;
|
|
492
|
-
values?: unknown[][];
|
|
493
|
-
};
|
|
491
|
+
values: InsertQueryDataObjectValues | InsertQueryDataFromValues;
|
|
494
492
|
join?: JoinItem[];
|
|
495
493
|
onConflict?: {
|
|
496
494
|
target?: OnConflictTarget;
|
|
@@ -498,6 +496,11 @@ interface InsertQueryData extends CommonQueryData {
|
|
|
498
496
|
merge?: OnConflictMerge;
|
|
499
497
|
};
|
|
500
498
|
}
|
|
499
|
+
type InsertQueryDataObjectValues = unknown[][];
|
|
500
|
+
type InsertQueryDataFromValues = {
|
|
501
|
+
from: Query;
|
|
502
|
+
values?: unknown[];
|
|
503
|
+
};
|
|
501
504
|
interface UpdateQueryDataObject {
|
|
502
505
|
[K: string]: Expression | {
|
|
503
506
|
op: string;
|
|
@@ -5396,7 +5399,7 @@ type AfterHook<Select extends PropertyKey[], Shape extends QueryColumns> = Query
|
|
|
5396
5399
|
}[]>;
|
|
5397
5400
|
type HookSelectArg<T extends PickQueryShape> = (keyof T['shape'] & string)[];
|
|
5398
5401
|
type HookAction = 'Create' | 'Update' | 'Delete';
|
|
5399
|
-
declare const _queryHookBeforeQuery: <T extends PickQueryShape>(q: T, cb:
|
|
5402
|
+
declare const _queryHookBeforeQuery: <T extends PickQueryShape>(q: T, cb: QueryBeforeHookInternal) => T;
|
|
5400
5403
|
declare const _queryHookAfterQuery: <T extends PickQueryShape>(q: T, cb: QueryAfterHook) => T;
|
|
5401
5404
|
declare const _queryHookBeforeCreate: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
5402
5405
|
declare const _queryHookAfterCreate: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
@@ -5407,16 +5410,22 @@ declare const _queryHookAfterUpdateCommit: <T extends PickQueryShape, S extends
|
|
|
5407
5410
|
declare const _queryHookBeforeSave: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
5408
5411
|
declare const _queryHookAfterSave: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
5409
5412
|
declare const _queryAfterSaveCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
5410
|
-
declare const _queryHookBeforeDelete: <T extends PickQueryShape>(q: T, cb:
|
|
5413
|
+
declare const _queryHookBeforeDelete: <T extends PickQueryShape>(q: T, cb: QueryBeforeHookInternal) => T;
|
|
5411
5414
|
declare const _queryHookAfterDelete: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
5412
5415
|
declare const _queryHookAfterDeleteCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
5416
|
+
declare class QueryHookUtils<T extends PickQueryInputType> {
|
|
5417
|
+
query: Query;
|
|
5418
|
+
private key;
|
|
5419
|
+
constructor(query: Query, key: 'hookCreateSet' | 'hookUpdateSet');
|
|
5420
|
+
set: (data: { [K in keyof T["inputType"]]?: T["inputType"][K] | (() => QueryOrExpression<T["inputType"][K]>) | undefined; }) => void;
|
|
5421
|
+
}
|
|
5413
5422
|
declare abstract class QueryHooks {
|
|
5414
5423
|
/**
|
|
5415
5424
|
* Run the function before any kind of query.
|
|
5416
5425
|
*
|
|
5417
5426
|
* @param cb - function to call, first argument is a query object
|
|
5418
5427
|
*/
|
|
5419
|
-
beforeQuery<T>(this: T, cb:
|
|
5428
|
+
beforeQuery<T>(this: T, cb: QueryBeforeHookInternal): T;
|
|
5420
5429
|
/**
|
|
5421
5430
|
* Run the function after any kind of query.
|
|
5422
5431
|
* Enforces wrapping the query into a transaction.
|
|
@@ -5506,7 +5515,7 @@ declare abstract class QueryHooks {
|
|
|
5506
5515
|
*
|
|
5507
5516
|
* @param cb - function to call, first argument is a query object
|
|
5508
5517
|
*/
|
|
5509
|
-
beforeDelete<T>(this: T, cb:
|
|
5518
|
+
beforeDelete<T>(this: T, cb: QueryBeforeHookInternal): T;
|
|
5510
5519
|
/**
|
|
5511
5520
|
* Run the function after a `delete` kind of query.
|
|
5512
5521
|
* Enforces wrapping the query into a transaction.
|
|
@@ -9002,4 +9011,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
9002
9011
|
*/
|
|
9003
9012
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
9004
9013
|
|
|
9005
|
-
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, 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 DbSqlQuery, type DbStructureDomainsMap, 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 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$1 as 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 PickQueryDataShapeAndJoinedShapesAndAliases, 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 PickQueryRelationQueries, 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 Queries, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryBuilder, 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 RelationConfigQuery, type RelationJoinQuery, 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 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, type WithItems, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, 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, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, performQuery, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
9014
|
+
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, 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 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 DbSqlQuery, type DbStructureDomainsMap, 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, type InsertQueryDataFromValues, type InsertQueryDataObjectValues, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, 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$1 as 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 PickQueryDataShapeAndJoinedShapesAndAliases, 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 PickQueryRelationQueries, 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 Queries, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryBeforeHookInternal, type QueryBuilder, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHookUtils, 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 RelationConfigQuery, type RelationJoinQuery, 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 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, type WithItems, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, 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, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, performQuery, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
package/dist/index.js
CHANGED
|
@@ -6240,6 +6240,8 @@ function _querySelect(q, args) {
|
|
|
6240
6240
|
q.q.returnType = q.q.returningMany ? "all" : "oneOrThrow";
|
|
6241
6241
|
} else if (returnType === "value") {
|
|
6242
6242
|
q.q.returnType = q.q.returningMany ? "all" : "one";
|
|
6243
|
+
} else if (returnType === "void") {
|
|
6244
|
+
q.q.returnType = q.q.returningMany ? "all" : "oneOrThrow";
|
|
6243
6245
|
}
|
|
6244
6246
|
const len = args.length;
|
|
6245
6247
|
if (!len) {
|
|
@@ -6429,7 +6431,22 @@ const pushWithSql = (ctx, items) => {
|
|
|
6429
6431
|
};
|
|
6430
6432
|
|
|
6431
6433
|
const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
6432
|
-
|
|
6434
|
+
let { columns } = query;
|
|
6435
|
+
const { shape, inCTE, hookCreateSet } = query;
|
|
6436
|
+
const QueryClass = ctx.qb.constructor;
|
|
6437
|
+
let values = query.values;
|
|
6438
|
+
let hookSetSql;
|
|
6439
|
+
if (hookCreateSet) {
|
|
6440
|
+
({ hookSetSql, columns, values } = processHookSet(
|
|
6441
|
+
ctx,
|
|
6442
|
+
q,
|
|
6443
|
+
values,
|
|
6444
|
+
hookCreateSet,
|
|
6445
|
+
columns,
|
|
6446
|
+
QueryClass,
|
|
6447
|
+
quotedAs
|
|
6448
|
+
));
|
|
6449
|
+
}
|
|
6433
6450
|
const quotedColumns = columns.map(
|
|
6434
6451
|
(column) => `"${shape[column]?.data.name || column}"`
|
|
6435
6452
|
);
|
|
@@ -6444,7 +6461,6 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6444
6461
|
}
|
|
6445
6462
|
}
|
|
6446
6463
|
}
|
|
6447
|
-
let values = query.values;
|
|
6448
6464
|
if (quotedColumns.length === 0) {
|
|
6449
6465
|
const key = Object.keys(q.shape)[0];
|
|
6450
6466
|
if (key) {
|
|
@@ -6456,12 +6472,11 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6456
6472
|
}
|
|
6457
6473
|
}
|
|
6458
6474
|
const insertSql = `INSERT INTO ${quotedAs}${quotedColumns.length ? "(" + quotedColumns.join(", ") + ")" : ""}`;
|
|
6459
|
-
if (
|
|
6475
|
+
if ("from" in values && query.insertWith) {
|
|
6460
6476
|
pushWithSql(ctx, Object.values(query.insertWith).flat());
|
|
6461
6477
|
}
|
|
6462
6478
|
const valuesPos = ctx.sql.length + 1;
|
|
6463
6479
|
ctx.sql.push(insertSql, null);
|
|
6464
|
-
const QueryClass = ctx.qb.constructor;
|
|
6465
6480
|
if (query.onConflict) {
|
|
6466
6481
|
ctx.sql.push("ON CONFLICT");
|
|
6467
6482
|
const { target } = query.onConflict;
|
|
@@ -6525,7 +6540,28 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6525
6540
|
returning = makeReturningSql(ctx, q, query, quotedAs, 2);
|
|
6526
6541
|
}
|
|
6527
6542
|
if (returning.select) ctx.sql.push("RETURNING", returning.select);
|
|
6528
|
-
if (
|
|
6543
|
+
if ("from" in values) {
|
|
6544
|
+
const { from, values: v } = values;
|
|
6545
|
+
const q2 = from.clone();
|
|
6546
|
+
if (v) {
|
|
6547
|
+
pushQueryValueImmutable(
|
|
6548
|
+
q2,
|
|
6549
|
+
"select",
|
|
6550
|
+
new RawSQL(
|
|
6551
|
+
encodeRow(
|
|
6552
|
+
ctx,
|
|
6553
|
+
ctx.values,
|
|
6554
|
+
q2,
|
|
6555
|
+
QueryClass,
|
|
6556
|
+
v,
|
|
6557
|
+
runtimeDefaults,
|
|
6558
|
+
quotedAs
|
|
6559
|
+
)
|
|
6560
|
+
)
|
|
6561
|
+
);
|
|
6562
|
+
}
|
|
6563
|
+
ctx.sql[valuesPos] = getSqlText(toSQL(q2, { values: ctx.values }));
|
|
6564
|
+
} else {
|
|
6529
6565
|
const valuesSql = [];
|
|
6530
6566
|
let ctxValues = ctx.values;
|
|
6531
6567
|
const restValuesLen = ctxValues.length;
|
|
@@ -6546,7 +6582,8 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6546
6582
|
QueryClass,
|
|
6547
6583
|
values[i],
|
|
6548
6584
|
runtimeDefaults,
|
|
6549
|
-
quotedAs
|
|
6585
|
+
quotedAs,
|
|
6586
|
+
hookSetSql
|
|
6550
6587
|
);
|
|
6551
6588
|
if (!inCTE) encodedRow = "(" + encodedRow + ")";
|
|
6552
6589
|
if (ctxValues.length > MAX_BINDING_PARAMS) {
|
|
@@ -6595,32 +6632,127 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
6595
6632
|
if (inCTE) {
|
|
6596
6633
|
ctx.sql[valuesPos] += ' WHERE NOT EXISTS (SELECT 1 FROM "f")';
|
|
6597
6634
|
}
|
|
6598
|
-
}
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6635
|
+
}
|
|
6636
|
+
return {
|
|
6637
|
+
hookSelect: returning.hookSelect,
|
|
6638
|
+
text: ctx.sql.join(" "),
|
|
6639
|
+
values: ctx.values
|
|
6640
|
+
};
|
|
6641
|
+
};
|
|
6642
|
+
const processHookSet = (ctx, q, values, hookCreateSet, columns, QueryClass, quotedAs) => {
|
|
6643
|
+
const hookSet = {};
|
|
6644
|
+
for (const item of hookCreateSet) {
|
|
6645
|
+
Object.assign(hookSet, item);
|
|
6646
|
+
}
|
|
6647
|
+
const addHookSetColumns = Object.keys(hookSet).filter(
|
|
6648
|
+
(key) => !columns.includes(key)
|
|
6649
|
+
);
|
|
6650
|
+
if ("from" in values) {
|
|
6651
|
+
const v = { ...values };
|
|
6652
|
+
const newColumns = [];
|
|
6653
|
+
const originalSelect = v.from.q.select;
|
|
6654
|
+
if (originalSelect) {
|
|
6655
|
+
v.from = _clone(v.from);
|
|
6656
|
+
const select = [];
|
|
6657
|
+
for (const s of originalSelect) {
|
|
6658
|
+
if (typeof s === "string" && !hookSet[s]) {
|
|
6659
|
+
select.push(s);
|
|
6660
|
+
newColumns.push(s);
|
|
6661
|
+
} else if (typeof s === "object" && "selectAs" in s) {
|
|
6662
|
+
const filtered = {};
|
|
6663
|
+
for (const key in s.selectAs) {
|
|
6664
|
+
if (!hookSet[key]) {
|
|
6665
|
+
filtered[key] = s.selectAs[key];
|
|
6666
|
+
newColumns.push(key);
|
|
6667
|
+
}
|
|
6668
|
+
}
|
|
6669
|
+
select.push({ selectAs: filtered });
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
v.from.q.select = select;
|
|
6673
|
+
}
|
|
6674
|
+
let row;
|
|
6675
|
+
if (v.values) {
|
|
6676
|
+
const originalRow = v.values;
|
|
6677
|
+
const valuesColumns = columns.slice(-originalRow.length);
|
|
6678
|
+
row = [];
|
|
6679
|
+
valuesColumns.forEach((c, i) => {
|
|
6680
|
+
if (!hookSet[c]) {
|
|
6681
|
+
newColumns.push(c);
|
|
6682
|
+
row.push(originalRow[i]);
|
|
6683
|
+
}
|
|
6684
|
+
});
|
|
6685
|
+
} else {
|
|
6686
|
+
row = [];
|
|
6687
|
+
}
|
|
6688
|
+
v.values = row;
|
|
6689
|
+
columns.forEach((column) => {
|
|
6690
|
+
if (column in hookSet) {
|
|
6691
|
+
newColumns.push(column);
|
|
6692
|
+
const fromHook = {
|
|
6693
|
+
fromHook: encodeValue(
|
|
6607
6694
|
ctx,
|
|
6608
6695
|
ctx.values,
|
|
6609
|
-
|
|
6696
|
+
q,
|
|
6610
6697
|
QueryClass,
|
|
6611
|
-
|
|
6612
|
-
runtimeDefaults,
|
|
6698
|
+
hookSet[column],
|
|
6613
6699
|
quotedAs
|
|
6614
6700
|
)
|
|
6615
|
-
|
|
6616
|
-
|
|
6701
|
+
};
|
|
6702
|
+
row.push(fromHook);
|
|
6703
|
+
}
|
|
6704
|
+
});
|
|
6705
|
+
if (addHookSetColumns) {
|
|
6706
|
+
for (const key of addHookSetColumns) {
|
|
6707
|
+
row.push({
|
|
6708
|
+
fromHook: encodeValue(
|
|
6709
|
+
ctx,
|
|
6710
|
+
ctx.values,
|
|
6711
|
+
q,
|
|
6712
|
+
QueryClass,
|
|
6713
|
+
hookSet[key],
|
|
6714
|
+
quotedAs
|
|
6715
|
+
)
|
|
6716
|
+
});
|
|
6717
|
+
}
|
|
6718
|
+
return {
|
|
6719
|
+
columns: [...newColumns, ...addHookSetColumns],
|
|
6720
|
+
values: v
|
|
6721
|
+
};
|
|
6617
6722
|
}
|
|
6618
|
-
|
|
6723
|
+
return { columns: newColumns, values: v };
|
|
6619
6724
|
}
|
|
6725
|
+
columns.forEach((column, i) => {
|
|
6726
|
+
if (column in hookSet) {
|
|
6727
|
+
const fromHook = {
|
|
6728
|
+
fromHook: encodeValue(
|
|
6729
|
+
ctx,
|
|
6730
|
+
ctx.values,
|
|
6731
|
+
q,
|
|
6732
|
+
QueryClass,
|
|
6733
|
+
hookSet[column],
|
|
6734
|
+
quotedAs
|
|
6735
|
+
)
|
|
6736
|
+
};
|
|
6737
|
+
for (const row of values) {
|
|
6738
|
+
row[i] = fromHook;
|
|
6739
|
+
}
|
|
6740
|
+
}
|
|
6741
|
+
});
|
|
6742
|
+
const hookSetSql = addHookSetColumns.map(
|
|
6743
|
+
(key) => encodeValue(
|
|
6744
|
+
ctx,
|
|
6745
|
+
ctx.values,
|
|
6746
|
+
q,
|
|
6747
|
+
QueryClass,
|
|
6748
|
+
hookSet[key],
|
|
6749
|
+
quotedAs
|
|
6750
|
+
)
|
|
6751
|
+
).join(", ");
|
|
6620
6752
|
return {
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
values
|
|
6753
|
+
hookSetSql,
|
|
6754
|
+
columns: addHookSetColumns ? [...columns, ...addHookSetColumns] : columns,
|
|
6755
|
+
values
|
|
6624
6756
|
};
|
|
6625
6757
|
};
|
|
6626
6758
|
const mergeColumnsSql = (columns, quotedColumns, target, except) => {
|
|
@@ -6644,24 +6776,30 @@ const mergeColumnsSql = (columns, quotedColumns, target, except) => {
|
|
|
6644
6776
|
`DO UPDATE SET ${quotedColumns[0]} = excluded.${quotedColumns[0]}`
|
|
6645
6777
|
);
|
|
6646
6778
|
};
|
|
6647
|
-
const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) => {
|
|
6648
|
-
const arr = row.map(
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
return value.toSQL(ctx, quotedAs);
|
|
6652
|
-
} else if (value instanceof QueryClass) {
|
|
6653
|
-
return `(${getSqlText(joinSubQuery(q, value).toSQL(ctx))})`;
|
|
6654
|
-
}
|
|
6655
|
-
}
|
|
6656
|
-
return value === void 0 ? "DEFAULT" : orchidCore.addValue(values, value);
|
|
6657
|
-
});
|
|
6779
|
+
const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs, hookSetSql) => {
|
|
6780
|
+
const arr = row.map(
|
|
6781
|
+
(value) => encodeValue(ctx, values, q, QueryClass, value, quotedAs)
|
|
6782
|
+
);
|
|
6658
6783
|
if (runtimeDefaults) {
|
|
6659
6784
|
for (const fn of runtimeDefaults) {
|
|
6660
6785
|
arr.push(orchidCore.addValue(values, fn()));
|
|
6661
6786
|
}
|
|
6662
6787
|
}
|
|
6788
|
+
if (hookSetSql) arr.push(hookSetSql);
|
|
6663
6789
|
return arr.join(", ");
|
|
6664
6790
|
};
|
|
6791
|
+
const encodeValue = (ctx, values, q, QueryClass, value, quotedAs) => {
|
|
6792
|
+
if (value && typeof value === "object") {
|
|
6793
|
+
if (value instanceof orchidCore.Expression) {
|
|
6794
|
+
return value.toSQL(ctx, quotedAs);
|
|
6795
|
+
} else if (value instanceof QueryClass) {
|
|
6796
|
+
return `(${getSqlText(joinSubQuery(q, value).toSQL(ctx))})`;
|
|
6797
|
+
} else if ("fromHook" in value) {
|
|
6798
|
+
return value.fromHook;
|
|
6799
|
+
}
|
|
6800
|
+
}
|
|
6801
|
+
return value === void 0 ? "DEFAULT" : orchidCore.addValue(values, value);
|
|
6802
|
+
};
|
|
6665
6803
|
const hookSelectKeys = [
|
|
6666
6804
|
null,
|
|
6667
6805
|
"afterUpdateSelect",
|
|
@@ -7240,8 +7378,20 @@ const pushUpdateSql = (ctx, table, query, quotedAs) => {
|
|
|
7240
7378
|
query.schema,
|
|
7241
7379
|
table.table || query.from
|
|
7242
7380
|
);
|
|
7381
|
+
let hookSet;
|
|
7382
|
+
if (query.hookUpdateSet) {
|
|
7383
|
+
hookSet = {};
|
|
7384
|
+
for (const item of query.hookUpdateSet) {
|
|
7385
|
+
Object.assign(hookSet, item);
|
|
7386
|
+
}
|
|
7387
|
+
} else {
|
|
7388
|
+
hookSet = orchidCore.emptyObject;
|
|
7389
|
+
}
|
|
7243
7390
|
const set = [];
|
|
7244
|
-
processData(ctx, table, set, query.updateData, quotedAs);
|
|
7391
|
+
processData(ctx, table, set, query.updateData, hookSet, quotedAs);
|
|
7392
|
+
if (query.hookUpdateSet) {
|
|
7393
|
+
applySet(ctx, table, set, hookSet, orchidCore.emptyObject, quotedAs);
|
|
7394
|
+
}
|
|
7245
7395
|
if (!set.length) {
|
|
7246
7396
|
if (!query.select) {
|
|
7247
7397
|
query.select = countSelect;
|
|
@@ -7281,32 +7431,35 @@ const pushUpdateReturning = (ctx, table, query, quotedAs, keyword) => {
|
|
|
7281
7431
|
if (s) ctx.sql.push(keyword, s);
|
|
7282
7432
|
return hookSelect;
|
|
7283
7433
|
};
|
|
7284
|
-
const processData = (ctx, table, set, data, quotedAs) => {
|
|
7434
|
+
const processData = (ctx, table, set, data, hookSet, quotedAs) => {
|
|
7285
7435
|
let append;
|
|
7286
|
-
const QueryClass = ctx.qb.constructor;
|
|
7287
7436
|
for (const item of data) {
|
|
7288
7437
|
if (typeof item === "function") {
|
|
7289
7438
|
const result = item(data);
|
|
7290
7439
|
if (result) append = orchidCore.pushOrNewArray(append, result);
|
|
7291
7440
|
} else {
|
|
7292
|
-
|
|
7293
|
-
for (const key in item) {
|
|
7294
|
-
const value = item[key];
|
|
7295
|
-
if (value === void 0) continue;
|
|
7296
|
-
set.push(
|
|
7297
|
-
`"${shape[key].data.name || key}" = ${processValue(
|
|
7298
|
-
ctx,
|
|
7299
|
-
table,
|
|
7300
|
-
QueryClass,
|
|
7301
|
-
key,
|
|
7302
|
-
value,
|
|
7303
|
-
quotedAs
|
|
7304
|
-
)}`
|
|
7305
|
-
);
|
|
7306
|
-
}
|
|
7441
|
+
applySet(ctx, table, set, item, hookSet, quotedAs);
|
|
7307
7442
|
}
|
|
7308
7443
|
}
|
|
7309
|
-
if (append) processData(ctx, table, set, append, quotedAs);
|
|
7444
|
+
if (append) processData(ctx, table, set, append, hookSet, quotedAs);
|
|
7445
|
+
};
|
|
7446
|
+
const applySet = (ctx, table, set, item, hookSet, quotedAs) => {
|
|
7447
|
+
const QueryClass = ctx.qb.constructor;
|
|
7448
|
+
const shape = table.q.shape;
|
|
7449
|
+
for (const key in item) {
|
|
7450
|
+
const value = item[key];
|
|
7451
|
+
if (value === void 0 || key in hookSet) continue;
|
|
7452
|
+
set.push(
|
|
7453
|
+
`"${shape[key].data.name || key}" = ${processValue(
|
|
7454
|
+
ctx,
|
|
7455
|
+
table,
|
|
7456
|
+
QueryClass,
|
|
7457
|
+
key,
|
|
7458
|
+
value,
|
|
7459
|
+
quotedAs
|
|
7460
|
+
)}`
|
|
7461
|
+
);
|
|
7462
|
+
}
|
|
7310
7463
|
};
|
|
7311
7464
|
const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
|
|
7312
7465
|
if (value && typeof value === "object") {
|
|
@@ -8747,7 +8900,7 @@ const handleManyData = (q, data, ctx) => {
|
|
|
8747
8900
|
const insert = (self, {
|
|
8748
8901
|
columns,
|
|
8749
8902
|
values
|
|
8750
|
-
},
|
|
8903
|
+
}, many) => {
|
|
8751
8904
|
const { q } = self;
|
|
8752
8905
|
if (!q.select?.length) {
|
|
8753
8906
|
q.returning = true;
|
|
@@ -8758,7 +8911,6 @@ const insert = (self, {
|
|
|
8758
8911
|
q.type = "insert";
|
|
8759
8912
|
q.columns = columns;
|
|
8760
8913
|
q.values = values;
|
|
8761
|
-
if (!q.kind) q.kind = kind;
|
|
8762
8914
|
const { select, returnType } = q;
|
|
8763
8915
|
if (!select) {
|
|
8764
8916
|
if (returnType !== "void") {
|
|
@@ -8806,9 +8958,8 @@ const insertFromQuery = (q, from, many, data) => {
|
|
|
8806
8958
|
q,
|
|
8807
8959
|
{
|
|
8808
8960
|
columns,
|
|
8809
|
-
values: { from, values: obj?.values }
|
|
8961
|
+
values: { from, values: obj?.values[0] }
|
|
8810
8962
|
},
|
|
8811
|
-
"from",
|
|
8812
8963
|
many
|
|
8813
8964
|
);
|
|
8814
8965
|
};
|
|
@@ -8822,10 +8973,10 @@ const _queryInsert = (q, data) => {
|
|
|
8822
8973
|
const values = q.q.values;
|
|
8823
8974
|
if (values && "from" in values) {
|
|
8824
8975
|
obj.columns = getFromSelectColumns(values.from, obj);
|
|
8825
|
-
values.values = obj.values;
|
|
8976
|
+
values.values = obj.values[0];
|
|
8826
8977
|
obj.values = values;
|
|
8827
8978
|
}
|
|
8828
|
-
return insert(q, obj
|
|
8979
|
+
return insert(q, obj);
|
|
8829
8980
|
};
|
|
8830
8981
|
const _queryCreateMany = (q, data) => {
|
|
8831
8982
|
createSelect(q);
|
|
@@ -8833,7 +8984,7 @@ const _queryCreateMany = (q, data) => {
|
|
|
8833
8984
|
};
|
|
8834
8985
|
const _queryInsertMany = (q, data) => {
|
|
8835
8986
|
const ctx = createCtx();
|
|
8836
|
-
let result = insert(q, handleManyData(q, data, ctx),
|
|
8987
|
+
let result = insert(q, handleManyData(q, data, ctx), true);
|
|
8837
8988
|
if (!data.length) result = result.none();
|
|
8838
8989
|
return result;
|
|
8839
8990
|
};
|
|
@@ -9566,7 +9717,7 @@ const _queryHookAfterQuery = (q, cb) => {
|
|
|
9566
9717
|
return pushQueryValueImmutable(q, "after", cb);
|
|
9567
9718
|
};
|
|
9568
9719
|
const _queryHookBeforeCreate = (q, cb) => {
|
|
9569
|
-
return before(q, "Create", cb);
|
|
9720
|
+
return before(q, "Create", (q2) => cb(new QueryHookUtils(q2, "hookCreateSet")));
|
|
9570
9721
|
};
|
|
9571
9722
|
const _queryHookAfterCreate = (q, select, cb) => {
|
|
9572
9723
|
return after(q, "Create", select, cb);
|
|
@@ -9575,7 +9726,7 @@ const _queryHookAfterCreateCommit = (q, select, cb) => {
|
|
|
9575
9726
|
return after(q, "Create", select, cb, true);
|
|
9576
9727
|
};
|
|
9577
9728
|
const _queryHookBeforeUpdate = (q, cb) => {
|
|
9578
|
-
return before(q, "Update", cb);
|
|
9729
|
+
return before(q, "Update", (q2) => cb(new QueryHookUtils(q2, "hookUpdateSet")));
|
|
9579
9730
|
};
|
|
9580
9731
|
const _queryHookAfterUpdate = (q, select, cb) => {
|
|
9581
9732
|
return after(q, "Update", select, cb);
|
|
@@ -9584,7 +9735,11 @@ const _queryHookAfterUpdateCommit = (q, select, cb) => {
|
|
|
9584
9735
|
return after(q, "Update", select, cb, true);
|
|
9585
9736
|
};
|
|
9586
9737
|
const _queryHookBeforeSave = (q, cb) => {
|
|
9587
|
-
return before(
|
|
9738
|
+
return before(
|
|
9739
|
+
before(q, "Create", (q2) => cb(new QueryHookUtils(q2, "hookCreateSet"))),
|
|
9740
|
+
"Update",
|
|
9741
|
+
(q2) => cb(new QueryHookUtils(q2, "hookUpdateSet"))
|
|
9742
|
+
);
|
|
9588
9743
|
};
|
|
9589
9744
|
const _queryHookAfterSave = (q, select, cb) => {
|
|
9590
9745
|
return after(after(q, "Create", select, cb), "Update", select, cb);
|
|
@@ -9607,6 +9762,21 @@ const _queryHookAfterDelete = (q, select, cb) => {
|
|
|
9607
9762
|
const _queryHookAfterDeleteCommit = (q, select, cb) => {
|
|
9608
9763
|
return after(q, "Delete", select, cb, true);
|
|
9609
9764
|
};
|
|
9765
|
+
class QueryHookUtils {
|
|
9766
|
+
constructor(query, key) {
|
|
9767
|
+
this.query = query;
|
|
9768
|
+
this.key = key;
|
|
9769
|
+
this.set = (data) => {
|
|
9770
|
+
const set = {};
|
|
9771
|
+
for (const key in data) {
|
|
9772
|
+
if (data[key] !== void 0) {
|
|
9773
|
+
set[key] = data[key];
|
|
9774
|
+
}
|
|
9775
|
+
}
|
|
9776
|
+
pushQueryValueImmutable(this.query, this.key, set);
|
|
9777
|
+
};
|
|
9778
|
+
}
|
|
9779
|
+
}
|
|
9610
9780
|
class QueryHooks {
|
|
9611
9781
|
/**
|
|
9612
9782
|
* Run the function before any kind of query.
|
|
@@ -11358,7 +11528,7 @@ function orCreate(query, data, updateData, mergeData) {
|
|
|
11358
11528
|
q22.q.log = q2.q.log;
|
|
11359
11529
|
q22.q.logger = q2.q.logger;
|
|
11360
11530
|
q22.q.type = "upsert";
|
|
11361
|
-
q22.q.beforeCreate = q2.q.beforeCreate;
|
|
11531
|
+
q22.q.beforeCreate = q2.q.beforeCreate?.map((cb) => () => cb(c));
|
|
11362
11532
|
if (hasAfterCallback) {
|
|
11363
11533
|
((_a = q22.q).afterCreate ?? (_a.afterCreate = [])).push(
|
|
11364
11534
|
(data2, query2) => afterHooks && Promise.all([...afterHooks].map((fn) => fn(data2, query2)))
|
|
@@ -13357,6 +13527,7 @@ exports.PolygonColumn = PolygonColumn;
|
|
|
13357
13527
|
exports.PostgisGeographyPointColumn = PostgisGeographyPointColumn;
|
|
13358
13528
|
exports.QueryError = QueryError;
|
|
13359
13529
|
exports.QueryGet = QueryGet;
|
|
13530
|
+
exports.QueryHookUtils = QueryHookUtils;
|
|
13360
13531
|
exports.QueryHooks = QueryHooks;
|
|
13361
13532
|
exports.QueryLog = QueryLog;
|
|
13362
13533
|
exports.QueryMethods = QueryMethods;
|