pqb 0.45.4 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +45 -27
- package/dist/index.js +106 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -29
- 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, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, EmptyObject, QueryColumns, QueryColumn, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ValExpression, PickOutputType, QueryThen, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryCatch, TransactionState, QueryColumnOfDataType, PickQueryUniqueProperties, PickQueryMetaResult, PickQueryTableMetaResultInputType, UnionToIntersection, getValueKey, QueryThenByReturnType, PickQueryReturnType, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify,
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, EmptyObject, QueryColumns, QueryColumn, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ValExpression, PickOutputType, QueryThen, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryCatch, TransactionState, QueryColumnOfDataType, PickQueryUniqueProperties, PickQueryMetaResult, PickQueryTableMetaResultInputType, UnionToIntersection, getValueKey, QueryThenByReturnType, PickQueryReturnType, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, 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
|
|
|
@@ -1936,8 +1936,8 @@ interface QueryFnReturningSelect {
|
|
|
1936
1936
|
* Mutative {@link Where.prototype.where}
|
|
1937
1937
|
*/
|
|
1938
1938
|
declare const _queryWhere: <T extends PickQueryMetaRelations>(q: T, args: WhereArgs<T>) => WhereResult<T>;
|
|
1939
|
-
declare const _queryFindBy: <T extends
|
|
1940
|
-
declare const _queryFindByOptional: <T extends
|
|
1939
|
+
declare const _queryFindBy: <T extends PickQueryMetaRelationsResultReturnType>(q: T, args: WhereArgs<T>) => QueryTake<WhereResult<T>>;
|
|
1940
|
+
declare const _queryFindByOptional: <T extends PickQueryMetaRelationsResultReturnType>(q: T, args: WhereArgs<T>) => QueryTakeOptional<WhereResult<T>>;
|
|
1941
1941
|
/**
|
|
1942
1942
|
* Mutative {@link Where.prototype.whereSql}
|
|
1943
1943
|
*/
|
|
@@ -4323,7 +4323,7 @@ type NarrowCreateResult<T extends CreateSelf, Bt> = EmptyObject extends T['relat
|
|
|
4323
4323
|
] extends [never] ? T['result'] : {
|
|
4324
4324
|
[K in keyof T['result']]: K extends T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate'] ? QueryColumn<Exclude<T['result'][K]['type'], null>, T['result'][K]['operators']> : T['result'][K];
|
|
4325
4325
|
};
|
|
4326
|
-
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ?
|
|
4326
|
+
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? QueryTakeOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
4327
4327
|
interface CreateRawData<T extends CreateSelf> {
|
|
4328
4328
|
columns: (keyof T['shape'])[];
|
|
4329
4329
|
values: Expression;
|
|
@@ -6823,9 +6823,13 @@ type UpsertCreate<DataKey extends PropertyKey, CD> = {
|
|
|
6823
6823
|
[K in DataKey]?: K extends keyof CD ? CD[K] : never;
|
|
6824
6824
|
};
|
|
6825
6825
|
type UpsertResult<T extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? SetQueryReturnsOneKind<T, 'upsert'> : SetQueryReturnsVoidKind<T, 'upsert'>;
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6826
|
+
interface UpsertThis extends UpdateSelf, CreateSelf {
|
|
6827
|
+
meta: MetaPropHasWhere;
|
|
6828
|
+
returnType: 'one' | 'oneOrThrow' | 'value' | 'valueOrThrow' | 'void';
|
|
6829
|
+
}
|
|
6830
|
+
interface MetaPropHasWhere extends QueryMetaBase {
|
|
6831
|
+
hasWhere: true;
|
|
6832
|
+
}
|
|
6829
6833
|
declare class QueryUpsertOrCreate {
|
|
6830
6834
|
/**
|
|
6831
6835
|
* `upsert` tries to update a single record, and then it creates the record if it doesn't yet exist.
|
|
@@ -7047,7 +7051,7 @@ declare class TransformMethods {
|
|
|
7047
7051
|
*/
|
|
7048
7052
|
transform<T extends IsQuery, Result>(this: T, fn: (input: T extends {
|
|
7049
7053
|
then: QueryThen<infer Data>;
|
|
7050
|
-
} ? Data : never) => Result): {
|
|
7054
|
+
} ? Data : never, queryData: QueryData) => Result): {
|
|
7051
7055
|
[K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
7052
7056
|
value: QueryColumn<Result>;
|
|
7053
7057
|
} : K extends 'then' ? QueryThen<Result> : T[K];
|
|
@@ -7205,25 +7209,31 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7205
7209
|
*/
|
|
7206
7210
|
all<T extends PickQueryResult>(this: T): SetQueryReturnsAll<T>;
|
|
7207
7211
|
/**
|
|
7208
|
-
*
|
|
7209
|
-
* Throws when not found.
|
|
7212
|
+
* Use `take` to "take" a single record. It adds `LIMIT 1`, throws a `NotFoundError` when not found.
|
|
7210
7213
|
*
|
|
7211
7214
|
* ```ts
|
|
7212
|
-
* const
|
|
7215
|
+
* const taken: TableType = await db.table.where({ key: 'value' }).take();
|
|
7213
7216
|
* ```
|
|
7217
|
+
*
|
|
7218
|
+
* Makes no effect if the query previously has `get`, `pluck`, `exec`.
|
|
7219
|
+
*
|
|
7220
|
+
* Changes `getOptional` to `get`.
|
|
7214
7221
|
*/
|
|
7215
|
-
take<T extends
|
|
7222
|
+
take<T extends PickQueryResultReturnType>(this: T): QueryTake<T>;
|
|
7216
7223
|
/**
|
|
7217
|
-
*
|
|
7218
|
-
* Returns `undefined` when not found.
|
|
7224
|
+
* Use `takeOptional` to "take" a single record. It adds `LIMIT 1`, returns `undefined` when not found.
|
|
7219
7225
|
*
|
|
7220
7226
|
* ```ts
|
|
7221
|
-
* const
|
|
7227
|
+
* const takenOptional: TableType | undefined = await db.table
|
|
7222
7228
|
* .where({ key: 'value' })
|
|
7223
7229
|
* .takeOptional();
|
|
7224
7230
|
* ```
|
|
7231
|
+
*
|
|
7232
|
+
* Makes no effect if the query previously has `getOptional`, `pluck`, `exec`.
|
|
7233
|
+
*
|
|
7234
|
+
* Changes `get` to `getOptional`.
|
|
7225
7235
|
*/
|
|
7226
|
-
takeOptional<T extends
|
|
7236
|
+
takeOptional<T extends PickQueryResultReturnType>(this: T): QueryTakeOptional<T>;
|
|
7227
7237
|
/**
|
|
7228
7238
|
* `.rows` returns an array of arrays without field names:
|
|
7229
7239
|
*
|
|
@@ -7314,7 +7324,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7314
7324
|
*
|
|
7315
7325
|
* @param value - primary key value to find by
|
|
7316
7326
|
*/
|
|
7317
|
-
find<T extends
|
|
7327
|
+
find<T extends PickQueryShapeResultReturnTypeSinglePrimaryKey>(this: T, value: T['internal']['singlePrimaryKey'] | Expression): QueryTake<T> & QueryMetaHasWhere;
|
|
7318
7328
|
/**
|
|
7319
7329
|
* Finds a single record with a given SQL, throws {@link NotFoundError} if not found:
|
|
7320
7330
|
*
|
|
@@ -7327,7 +7337,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7327
7337
|
*
|
|
7328
7338
|
* @param args - SQL expression
|
|
7329
7339
|
*/
|
|
7330
|
-
findBySql<T extends
|
|
7340
|
+
findBySql<T extends PickQueryResultReturnType>(this: T, ...args: SQLQueryArgs): QueryTake<T> & QueryMetaHasWhere;
|
|
7331
7341
|
/**
|
|
7332
7342
|
* Finds a single record by the primary key (id), returns `undefined` when not found.
|
|
7333
7343
|
* Not available if the table has no or multiple primary keys.
|
|
@@ -7338,7 +7348,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7338
7348
|
*
|
|
7339
7349
|
* @param value - primary key value to find by, or a raw SQL
|
|
7340
7350
|
*/
|
|
7341
|
-
findOptional<T extends
|
|
7351
|
+
findOptional<T extends PickQueryShapeResultReturnTypeSinglePrimaryKey>(this: T, value: T['internal']['singlePrimaryKey'] | Expression): QueryTakeOptional<T> & QueryMetaHasWhere;
|
|
7342
7352
|
/**
|
|
7343
7353
|
* Finds a single record with a given SQL.
|
|
7344
7354
|
* Returns `undefined` when not found.
|
|
@@ -7352,7 +7362,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7352
7362
|
*
|
|
7353
7363
|
* @param args - SQL expression
|
|
7354
7364
|
*/
|
|
7355
|
-
findBySqlOptional<T extends
|
|
7365
|
+
findBySqlOptional<T extends PickQueryResultReturnType>(this: T, ...args: SQLQueryArgs): QueryTakeOptional<T> & QueryMetaHasWhere;
|
|
7356
7366
|
/**
|
|
7357
7367
|
* Finds a single unique record, throws [NotFoundError](/guide/error-handling.html) if not found.
|
|
7358
7368
|
* It accepts values of primary keys or unique indexes defined on the table.
|
|
@@ -7366,7 +7376,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7366
7376
|
*
|
|
7367
7377
|
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
7368
7378
|
*/
|
|
7369
|
-
findBy<T extends
|
|
7379
|
+
findBy<T extends PickQueryResultReturnTypeUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): QueryTake<T> & QueryMetaHasWhere;
|
|
7370
7380
|
/**
|
|
7371
7381
|
* Finds a single unique record, returns `undefined` if not found.
|
|
7372
7382
|
* It accepts values of primary keys or unique indexes defined on the table.
|
|
@@ -7380,7 +7390,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
7380
7390
|
*
|
|
7381
7391
|
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
7382
7392
|
*/
|
|
7383
|
-
findByOptional<T extends
|
|
7393
|
+
findByOptional<T extends PickQueryResultReturnTypeUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): QueryTakeOptional<T> & QueryMetaHasWhere;
|
|
7384
7394
|
/**
|
|
7385
7395
|
* Specifies the schema to be used as a prefix of a table name.
|
|
7386
7396
|
*
|
|
@@ -7875,6 +7885,8 @@ interface PickQueryMetaRelations extends PickQueryMeta, PickQueryRelations {
|
|
|
7875
7885
|
}
|
|
7876
7886
|
interface PickQueryMetaRelationsResult extends PickQueryMetaRelations, PickQueryResult {
|
|
7877
7887
|
}
|
|
7888
|
+
interface PickQueryMetaRelationsResultReturnType extends PickQueryMetaRelationsResult, PickQueryResultReturnType {
|
|
7889
|
+
}
|
|
7878
7890
|
interface PickQueryMetaResultRelations extends PickQueryResult, PickQueryMeta, PickQueryRelations {
|
|
7879
7891
|
}
|
|
7880
7892
|
interface PickQueryMetaResultRelationsWindows extends PickQueryMetaResultRelations, PickQueryWindows {
|
|
@@ -7926,6 +7938,8 @@ interface PickQueryShapeSinglePrimaryKey extends PickQueryShape, PickQuerySingle
|
|
|
7926
7938
|
}
|
|
7927
7939
|
interface PickQueryShapeResultSinglePrimaryKey extends PickQueryShapeSinglePrimaryKey, PickQueryResult {
|
|
7928
7940
|
}
|
|
7941
|
+
interface PickQueryShapeResultReturnTypeSinglePrimaryKey extends PickQueryShapeResultSinglePrimaryKey, PickQueryReturnType {
|
|
7942
|
+
}
|
|
7929
7943
|
type SelectableOfType<T extends PickQueryMeta, Type> = {
|
|
7930
7944
|
[K in keyof T['meta']['selectable']]: T['meta']['selectable'][K]['column']['type'] extends Type | null ? K : never;
|
|
7931
7945
|
}[keyof T['meta']['selectable']];
|
|
@@ -7950,10 +7964,14 @@ type SetQueryReturnsAllKindResult<T extends PickQueryMetaResult, Kind extends st
|
|
|
7950
7964
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
7951
7965
|
} : K extends 'returnType' ? 'all' : K extends 'result' ? Result : K extends 'then' ? QueryThenShallowSimplifyArr<T['result']> : T[K];
|
|
7952
7966
|
} & QueryMetaHasWhere;
|
|
7953
|
-
type
|
|
7967
|
+
type QueryTakeOptional<T extends PickQueryResultReturnType> = T['returnType'] extends 'value' | 'pluck' | 'void' ? T : T['returnType'] extends 'valueOrThrow' ? {
|
|
7968
|
+
[K in keyof T]: K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<T['result']['value']['outputType'] | undefined> : T[K];
|
|
7969
|
+
} : {
|
|
7954
7970
|
[K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnShapeOutput<T['result']>> : T[K];
|
|
7955
7971
|
};
|
|
7956
|
-
type
|
|
7972
|
+
type QueryTake<T extends PickQueryResultReturnType> = T['returnType'] extends 'valueOrThrow' | 'pluck' | 'void' ? T : T['returnType'] extends 'value' ? {
|
|
7973
|
+
[K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Exclude<T['result']['value']['outputType'], undefined>> : T[K];
|
|
7974
|
+
} : {
|
|
7957
7975
|
[K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnShapeOutput<T['result']>> : T[K];
|
|
7958
7976
|
};
|
|
7959
7977
|
type SetQueryReturnsOneKind<T extends PickQueryMetaResult, Kind extends string> = {
|
|
@@ -8678,8 +8696,8 @@ declare const saveSearchAlias: (q: IsQuery, as: string, key: 'joinedShapes' | 'w
|
|
|
8678
8696
|
declare const extendQuery: <T extends PickQueryQAndBaseQuery, Methods extends RecordUnknown>(q: T, methods: Methods) => T & Methods;
|
|
8679
8697
|
declare const getPrimaryKeys: (q: IsQuery) => string[];
|
|
8680
8698
|
declare const _queryAll: <T extends PickQueryResult>(q: T) => SetQueryReturnsAll<T>;
|
|
8681
|
-
declare const _queryTake: <T extends
|
|
8682
|
-
declare const _queryTakeOptional: <T extends
|
|
8699
|
+
declare const _queryTake: <T extends PickQueryResultReturnType>(query: T) => QueryTake<T>;
|
|
8700
|
+
declare const _queryTakeOptional: <T extends PickQueryResultReturnType>(query: T) => QueryTakeOptional<T>;
|
|
8683
8701
|
declare const _queryExec: <T extends IsQuery>(q: T) => never;
|
|
8684
8702
|
declare const _queryRows: <T extends PickQueryResult>(q: T) => SetQueryReturnsRows<T>;
|
|
8685
8703
|
declare const getFullColumnTable: (q: IsQuery, column: string, index: number, as: string | getValueKey | undefined) => string;
|
|
@@ -8806,4 +8824,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8806
8824
|
*/
|
|
8807
8825
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8808
8826
|
|
|
8809
|
-
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 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 PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOne, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsOneOptional, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1106,8 +1106,35 @@ const text = {
|
|
|
1106
1106
|
};
|
|
1107
1107
|
const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1108
1108
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${options?.vars ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
|
|
1109
|
+
const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
|
|
1110
|
+
if (arg && typeof arg === "object") {
|
|
1111
|
+
if (IN && Array.isArray(arg)) {
|
|
1112
|
+
return `(${arg.map((value) => orchidCore.addValue(ctx.values, JSON.stringify(value)) + "::jsonb").join(", ")})`;
|
|
1113
|
+
}
|
|
1114
|
+
if (orchidCore.isExpression(arg)) {
|
|
1115
|
+
return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
|
|
1116
|
+
}
|
|
1117
|
+
if ("toSQL" in arg) {
|
|
1118
|
+
return `to_jsonb((${getSqlText(
|
|
1119
|
+
arg.toSQL({ values: ctx.values })
|
|
1120
|
+
)}))`;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
return orchidCore.addValue(ctx.values, JSON.stringify(arg)) + "::jsonb";
|
|
1124
|
+
};
|
|
1109
1125
|
const json = {
|
|
1110
|
-
|
|
1126
|
+
equals: make(
|
|
1127
|
+
(key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NULL` : `${key} = ${quoteJsonValue(value, ctx, quotedAs)}`
|
|
1128
|
+
),
|
|
1129
|
+
not: make(
|
|
1130
|
+
(key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NOT NULL` : `${key} != ${quoteJsonValue(value, ctx, quotedAs)}`
|
|
1131
|
+
),
|
|
1132
|
+
in: make(
|
|
1133
|
+
(key, value, ctx, quotedAs) => `${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`
|
|
1134
|
+
),
|
|
1135
|
+
notIn: make(
|
|
1136
|
+
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`
|
|
1137
|
+
),
|
|
1111
1138
|
jsonPathQueryFirst: Object.assign(
|
|
1112
1139
|
function(path, options) {
|
|
1113
1140
|
const { q, columnTypes } = this;
|
|
@@ -1921,13 +1948,39 @@ const _queryAll = (q) => {
|
|
|
1921
1948
|
q.q.all = true;
|
|
1922
1949
|
return q;
|
|
1923
1950
|
};
|
|
1924
|
-
const _queryTake = (
|
|
1925
|
-
q
|
|
1926
|
-
|
|
1951
|
+
const _queryTake = (query) => {
|
|
1952
|
+
const q = query.q;
|
|
1953
|
+
switch (q.returnType) {
|
|
1954
|
+
case "valueOrThrow":
|
|
1955
|
+
case "pluck":
|
|
1956
|
+
case "void":
|
|
1957
|
+
break;
|
|
1958
|
+
case "value": {
|
|
1959
|
+
q.returnType = "valueOrThrow";
|
|
1960
|
+
break;
|
|
1961
|
+
}
|
|
1962
|
+
default: {
|
|
1963
|
+
q.returnType = "oneOrThrow";
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return query;
|
|
1927
1967
|
};
|
|
1928
|
-
const _queryTakeOptional = (
|
|
1929
|
-
q
|
|
1930
|
-
|
|
1968
|
+
const _queryTakeOptional = (query) => {
|
|
1969
|
+
const q = query.q;
|
|
1970
|
+
switch (q.returnType) {
|
|
1971
|
+
case "value":
|
|
1972
|
+
case "pluck":
|
|
1973
|
+
case "void":
|
|
1974
|
+
break;
|
|
1975
|
+
case "valueOrThrow": {
|
|
1976
|
+
q.returnType = "value";
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
default: {
|
|
1980
|
+
q.returnType = "one";
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
return query;
|
|
1931
1984
|
};
|
|
1932
1985
|
const _queryExec = (q) => {
|
|
1933
1986
|
q.q.returnType = "void";
|
|
@@ -2111,16 +2164,27 @@ const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
|
|
|
2111
2164
|
}
|
|
2112
2165
|
};
|
|
2113
2166
|
|
|
2167
|
+
const noneResult = (q, queryData, type) => {
|
|
2168
|
+
if (!type || type === "all" || type === "rows" || type === "pluck") {
|
|
2169
|
+
return [];
|
|
2170
|
+
} else if (type === "one" || type === "value" || type === "void") {
|
|
2171
|
+
return queryData.notFoundDefault;
|
|
2172
|
+
} else if (type === "valueOrThrow" && queryData.returning) {
|
|
2173
|
+
return 0;
|
|
2174
|
+
} else {
|
|
2175
|
+
throw new NotFoundError(q);
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2114
2178
|
const noneMethods = {
|
|
2115
|
-
// `then` resolves or rejects based on return type of the query.
|
|
2179
|
+
// `then` resolves or rejects based on a return type of the query.
|
|
2116
2180
|
// It is `async` so it returns a chainable Promise.
|
|
2117
2181
|
async then(resolve, reject) {
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
resolve?.(
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2182
|
+
try {
|
|
2183
|
+
const result = noneResult(this, this.q, this.q.returnType);
|
|
2184
|
+
resolve?.(result);
|
|
2185
|
+
} catch (err) {
|
|
2186
|
+
reject?.(err);
|
|
2187
|
+
}
|
|
2124
2188
|
},
|
|
2125
2189
|
// `catch` returns a Promise, so it is chainable with then/catch.
|
|
2126
2190
|
catch: () => new Promise(orchidCore.noop)
|
|
@@ -2129,6 +2193,11 @@ const _queryNone = (q) => {
|
|
|
2129
2193
|
if (isQueryNone(q)) return q;
|
|
2130
2194
|
q = extendQuery(q, noneMethods);
|
|
2131
2195
|
pushQueryValueImmutable(q, "and", new RawSQL("false"));
|
|
2196
|
+
pushQueryValueImmutable(
|
|
2197
|
+
q,
|
|
2198
|
+
"transform",
|
|
2199
|
+
(_, queryData) => noneResult(q, queryData, queryData.returnType)
|
|
2200
|
+
);
|
|
2132
2201
|
return q;
|
|
2133
2202
|
};
|
|
2134
2203
|
const isQueryNone = (q) => q.then === noneMethods.then;
|
|
@@ -2186,7 +2255,9 @@ const _join = (query, require, type, first, args) => {
|
|
|
2186
2255
|
args,
|
|
2187
2256
|
joinSubQuery
|
|
2188
2257
|
);
|
|
2189
|
-
if (
|
|
2258
|
+
if (require && "r" in joinArgs && isQueryNone(joinArgs.r)) {
|
|
2259
|
+
return _queryNone(query);
|
|
2260
|
+
} else if (joinKey && "s" in joinArgs && joinArgs.s) {
|
|
2190
2261
|
const j = "j" in joinArgs ? joinArgs.r ?? joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
|
|
2191
2262
|
const jq = j.q;
|
|
2192
2263
|
if (jq.select || !jq.selectAllColumns) {
|
|
@@ -2213,8 +2284,6 @@ const _join = (query, require, type, first, args) => {
|
|
|
2213
2284
|
computeds
|
|
2214
2285
|
);
|
|
2215
2286
|
}
|
|
2216
|
-
} else if (require && "r" in joinArgs && isQueryNone(joinArgs.r)) {
|
|
2217
|
-
return _queryNone(query);
|
|
2218
2287
|
} else {
|
|
2219
2288
|
addAllShapesAndParsers(
|
|
2220
2289
|
query,
|
|
@@ -2914,12 +2983,13 @@ const runAfterCommit = async (afterCommit, result) => {
|
|
|
2914
2983
|
}
|
|
2915
2984
|
};
|
|
2916
2985
|
|
|
2917
|
-
const applyBatchTransforms = (
|
|
2918
|
-
if (
|
|
2986
|
+
const applyBatchTransforms = (q, batches) => {
|
|
2987
|
+
if (q.transform) {
|
|
2919
2988
|
for (const item of batches) {
|
|
2920
2989
|
item.parent[item.key] = orchidCore.applyTransforms(
|
|
2921
|
-
|
|
2922
|
-
|
|
2990
|
+
q,
|
|
2991
|
+
q.returnType,
|
|
2992
|
+
q.transform,
|
|
2923
2993
|
item.data
|
|
2924
2994
|
);
|
|
2925
2995
|
}
|
|
@@ -3362,7 +3432,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3362
3432
|
);
|
|
3363
3433
|
}
|
|
3364
3434
|
if (query.transform) {
|
|
3365
|
-
result = orchidCore.applyTransforms(returnType, query.transform, result);
|
|
3435
|
+
result = orchidCore.applyTransforms(query, returnType, query.transform, result);
|
|
3366
3436
|
}
|
|
3367
3437
|
return resolve?.(result);
|
|
3368
3438
|
} catch (err) {
|
|
@@ -5919,7 +5989,8 @@ const skipQueryKeysForSubQuery = {
|
|
|
5919
5989
|
returnsOne: true,
|
|
5920
5990
|
aliases: true,
|
|
5921
5991
|
sqlCache: true,
|
|
5922
|
-
defaults: true
|
|
5992
|
+
defaults: true,
|
|
5993
|
+
transform: true
|
|
5923
5994
|
};
|
|
5924
5995
|
const getIsJoinSubQuery = (query) => {
|
|
5925
5996
|
const {
|
|
@@ -11691,25 +11762,31 @@ class QueryMethods {
|
|
|
11691
11762
|
return _queryAll(_clone(this));
|
|
11692
11763
|
}
|
|
11693
11764
|
/**
|
|
11694
|
-
*
|
|
11695
|
-
* Throws when not found.
|
|
11765
|
+
* Use `take` to "take" a single record. It adds `LIMIT 1`, throws a `NotFoundError` when not found.
|
|
11696
11766
|
*
|
|
11697
11767
|
* ```ts
|
|
11698
|
-
* const
|
|
11768
|
+
* const taken: TableType = await db.table.where({ key: 'value' }).take();
|
|
11699
11769
|
* ```
|
|
11770
|
+
*
|
|
11771
|
+
* Makes no effect if the query previously has `get`, `pluck`, `exec`.
|
|
11772
|
+
*
|
|
11773
|
+
* Changes `getOptional` to `get`.
|
|
11700
11774
|
*/
|
|
11701
11775
|
take() {
|
|
11702
11776
|
return _queryTake(_clone(this));
|
|
11703
11777
|
}
|
|
11704
11778
|
/**
|
|
11705
|
-
*
|
|
11706
|
-
* Returns `undefined` when not found.
|
|
11779
|
+
* Use `takeOptional` to "take" a single record. It adds `LIMIT 1`, returns `undefined` when not found.
|
|
11707
11780
|
*
|
|
11708
11781
|
* ```ts
|
|
11709
|
-
* const
|
|
11782
|
+
* const takenOptional: TableType | undefined = await db.table
|
|
11710
11783
|
* .where({ key: 'value' })
|
|
11711
11784
|
* .takeOptional();
|
|
11712
11785
|
* ```
|
|
11786
|
+
*
|
|
11787
|
+
* Makes no effect if the query previously has `getOptional`, `pluck`, `exec`.
|
|
11788
|
+
*
|
|
11789
|
+
* Changes `get` to `getOptional`.
|
|
11713
11790
|
*/
|
|
11714
11791
|
takeOptional() {
|
|
11715
11792
|
return _queryTakeOptional(_clone(this));
|