pqb 0.27.0 → 0.27.2
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 +196 -176
- package/dist/index.js +1913 -1733
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1912 -1733
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as orchid_core from 'orchid-core';
|
|
2
|
-
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryInternal, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs,
|
|
2
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryInternal, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryCatch, PickQueryMetaShape, PickQueryTableMetaResultShape, QueryColumnBooleanOrNull, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, StringTypeData, StaticSQLArgs, PickColumnBaseData, PrimaryKeyColumn, RawSQLBase, ColumnTypeBase, ForeignKeyTable, QueryColumnsInit, TimestampHelpers, ColumnNameOfTable, BaseNumberData, ColumnWithDefault, ParseColumn, EncodeColumn, PickQueryMetaResult, ColumnShapeOutput, DefaultSelectColumns, CoreQueryScopes, DbBase, TransactionState, PickQueryMetaResultWindows, CoreBaseOperators, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, PickQueryReturnType, PickType, PickOutputType, Spread, PickQueryTableMetaShape } from 'orchid-core';
|
|
3
3
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -198,17 +198,37 @@ type QuerySourceItem = {
|
|
|
198
198
|
tsQuery: string | Expression;
|
|
199
199
|
});
|
|
200
200
|
type JoinItem = SimpleJoinItem | JoinLateralItem;
|
|
201
|
+
type SimpleJoinItemNonSubQueryArgs = [Record<string, string | Expression> | Expression | true] | [leftColumn: string | Expression, rightColumn: string | Expression] | [
|
|
202
|
+
leftColumn: string | Expression,
|
|
203
|
+
op: string,
|
|
204
|
+
rightColumn: string | Expression
|
|
205
|
+
];
|
|
206
|
+
type JoinItemArgs = {
|
|
207
|
+
j: Query;
|
|
208
|
+
s: boolean;
|
|
209
|
+
r?: Query;
|
|
210
|
+
} | {
|
|
211
|
+
w: string;
|
|
212
|
+
r: Query;
|
|
213
|
+
s: boolean;
|
|
214
|
+
} | {
|
|
215
|
+
w: string;
|
|
216
|
+
a: SimpleJoinItemNonSubQueryArgs;
|
|
217
|
+
} | {
|
|
218
|
+
q: QueryWithTable;
|
|
219
|
+
s: boolean;
|
|
220
|
+
} | {
|
|
221
|
+
q: QueryWithTable;
|
|
222
|
+
r: Query;
|
|
223
|
+
s: boolean;
|
|
224
|
+
} | {
|
|
225
|
+
q: QueryWithTable;
|
|
226
|
+
a: SimpleJoinItemNonSubQueryArgs;
|
|
227
|
+
s: boolean;
|
|
228
|
+
};
|
|
201
229
|
interface SimpleJoinItem {
|
|
202
230
|
type: string;
|
|
203
|
-
|
|
204
|
-
args: [] | [
|
|
205
|
-
conditions: Record<string, string | Expression> | Expression | ((q: unknown) => QueryBase) | true
|
|
206
|
-
] | [leftColumn: string | Expression, rightColumn: string | Expression] | [
|
|
207
|
-
leftColumn: string | Expression,
|
|
208
|
-
op: string,
|
|
209
|
-
rightColumn: string | Expression
|
|
210
|
-
];
|
|
211
|
-
isSubQuery: boolean;
|
|
231
|
+
args: JoinItemArgs;
|
|
212
232
|
}
|
|
213
233
|
type JoinLateralItem = [type: string, joined: Query, as: string];
|
|
214
234
|
type WhereItem = {
|
|
@@ -217,7 +237,7 @@ type WhereItem = {
|
|
|
217
237
|
AND?: MaybeArray<WhereItem>;
|
|
218
238
|
OR?: MaybeArray<WhereItem>[];
|
|
219
239
|
IN?: MaybeArray<WhereInItem>;
|
|
220
|
-
EXISTS?: MaybeArray<
|
|
240
|
+
EXISTS?: MaybeArray<JoinItemArgs>;
|
|
221
241
|
ON?: WhereOnItem | WhereJsonPathEqualsItem;
|
|
222
242
|
SEARCH?: MaybeArray<WhereSearchItem>;
|
|
223
243
|
} | ((q: unknown) => QueryBase | RelationQuery | Expression) | Query | Expression;
|
|
@@ -263,15 +283,6 @@ type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT
|
|
|
263
283
|
type OnConflictItem = string | string[] | Expression;
|
|
264
284
|
type OnConflictMergeUpdate = string | string[] | RecordUnknown | Expression;
|
|
265
285
|
|
|
266
|
-
type BooleanQueryColumn = QueryColumn<boolean, OperatorsBoolean>;
|
|
267
|
-
declare class BooleanColumn$1<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
|
|
268
|
-
dataType: "boolean";
|
|
269
|
-
operators: OperatorsBoolean;
|
|
270
|
-
constructor(schema: Schema);
|
|
271
|
-
toCode(t: string): Code;
|
|
272
|
-
parseItem: (input: string) => boolean;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
286
|
interface Operator<Value, Column extends PickOutputTypeAndOperators = PickOutputTypeAndOperators> {
|
|
276
287
|
<T extends PickQueryResult>(this: T, arg: Value): Omit<SetQueryReturnsColumnOrThrow<T, Column>, keyof T['result']['value']['operators']> & Column['operators'];
|
|
277
288
|
_opType: Value;
|
|
@@ -576,12 +587,12 @@ type WithSelectable<T extends PickQueryWithData, W extends keyof T['withData']>
|
|
|
576
587
|
* The first argument of all `join` and `joinLateral` methods.
|
|
577
588
|
* See argument of {@link join}.
|
|
578
589
|
*/
|
|
579
|
-
type JoinFirstArg<T extends PickQueryRelationsWithData> =
|
|
590
|
+
type JoinFirstArg<T extends PickQueryRelationsWithData> = PickQueryTableMetaResult | keyof T['relations'] | keyof T['withData'] | ((q: T['relations']) => PickQueryTableMetaResult);
|
|
580
591
|
/**
|
|
581
592
|
* Arguments of `join` methods (not `joinLateral`).
|
|
582
593
|
* See {@link join}
|
|
583
594
|
*/
|
|
584
|
-
type JoinArgs<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = [JoinCallback<T, Arg>] | (Arg extends
|
|
595
|
+
type JoinArgs<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = [JoinCallback<T, Arg>] | (Arg extends PickQueryTableMetaResult ? JoinQueryArgs<T, Arg> : Arg extends keyof T['relations'] ? EmptyTuple : Arg extends keyof T['withData'] ? JoinWithArgs<T, Arg> : never);
|
|
585
596
|
/**
|
|
586
597
|
* Column names of the joined table that can be used to join.
|
|
587
598
|
* Derived from 'result', not from 'shape',
|
|
@@ -591,9 +602,11 @@ type JoinArgs<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFir
|
|
|
591
602
|
* ```
|
|
592
603
|
* And the selection becomes available to use in the `ON` and to select from the joined table.
|
|
593
604
|
*/
|
|
594
|
-
type JoinSelectable<Q extends
|
|
595
|
-
type JoinQueryArgs<T extends PickQueryMeta, Q extends
|
|
596
|
-
conditions:
|
|
605
|
+
type JoinSelectable<Q extends PickQueryTableMetaResult> = keyof Q['result'] | `${AliasOrTable<Q>}.${keyof Q['result'] & string}`;
|
|
606
|
+
type JoinQueryArgs<T extends PickQueryMeta, Q extends PickQueryTableMetaResult> = [
|
|
607
|
+
conditions: {
|
|
608
|
+
[K in JoinSelectable<Q>]: keyof T['meta']['selectable'] | Expression;
|
|
609
|
+
} | Expression | true
|
|
597
610
|
] | [
|
|
598
611
|
leftColumn: JoinSelectable<Q> | Expression,
|
|
599
612
|
rightColumn: keyof T['meta']['selectable'] | Expression
|
|
@@ -603,7 +616,9 @@ type JoinQueryArgs<T extends PickQueryMeta, Q extends Query> = [
|
|
|
603
616
|
rightColumn: keyof T['meta']['selectable'] | Expression
|
|
604
617
|
];
|
|
605
618
|
type JoinWithArgs<T extends PickQueryMetaWithData, W extends keyof T['withData']> = [
|
|
606
|
-
conditions:
|
|
619
|
+
conditions: {
|
|
620
|
+
[K in WithSelectable<T, W>]: keyof T['meta']['selectable'] | Expression;
|
|
621
|
+
} | Expression
|
|
607
622
|
] | [
|
|
608
623
|
leftColumn: WithSelectable<T, W> | Expression,
|
|
609
624
|
rightColumn: keyof T['meta']['selectable'] | Expression
|
|
@@ -621,22 +636,22 @@ type JoinWithArgs<T extends PickQueryMetaWithData, W extends keyof T['withData']
|
|
|
621
636
|
* @param RequireJoined - when false, joined table shape will be mapped to make all columns optional
|
|
622
637
|
* @param RequireMain - when false, main table shape will be mapped to make all columns optional (for right and full join)
|
|
623
638
|
*/
|
|
624
|
-
type JoinResult<T extends
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
639
|
+
type JoinResult<T extends PickQueryMetaResultReturnType, R extends PickQueryTableMetaResult, RequireJoined, RequireMain> = RequireMain extends true ? JoinAddSelectable<T, JoinResultSelectable<R['result'], AliasOrTable<R>, RequireJoined>> : JoinOptionalMain<T, JoinResultSelectable<R['result'], AliasOrTable<R>, RequireJoined>>;
|
|
640
|
+
/**
|
|
641
|
+
* Calls {@link JoinResult} with either callback result, if join has a callback,
|
|
642
|
+
* or with a query derived from the first join argument.
|
|
643
|
+
*/
|
|
644
|
+
type JoinResultFromArgs<T extends PickQueryMetaResultRelationsWithDataReturnType, Arg, Args, RequireJoined, RequireMain> = JoinResult<T, Args extends GenericJoinCallbackTuple ? ReturnType<Args[0]> : Arg extends PickQueryTableMetaResultShape ? Arg['meta']['hasSelect'] extends true ? Arg : {
|
|
629
645
|
table: Arg['table'];
|
|
630
646
|
meta: Arg['meta'];
|
|
631
|
-
|
|
632
|
-
} : Arg
|
|
647
|
+
result: Arg['shape'];
|
|
648
|
+
} : Arg extends keyof T['relations'] ? T['relations'][Arg]['relationConfig']['query'] : Arg extends GenericJoinCallback ? ReturnType<Arg> : Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? {
|
|
633
649
|
table: T['withData'][Arg]['table'];
|
|
634
|
-
shape: T['withData'][Arg]['shape'];
|
|
635
|
-
meta: QueryBase['meta'];
|
|
636
|
-
} : never : never, Selectable extends SelectableBase = JoinResultSelectable<J, RequireJoined, ReturnType<Cb>>> = RequireMain extends true ? JoinAddSelectable<T, Selectable> : JoinOptionalMain<T, Selectable>;
|
|
637
|
-
type JoinResultFromArgs<T extends PickQueryMetaResultRelationsWithDataReturnType, Arg extends JoinFirstArg<T>, Args, RequireJoined extends boolean, RequireMain extends boolean> = Args extends [(q: never) => {
|
|
638
650
|
meta: QueryMetaBase;
|
|
639
|
-
|
|
651
|
+
result: T['withData'][Arg]['shape'];
|
|
652
|
+
} : never : never, RequireJoined, RequireMain>;
|
|
653
|
+
type GenericJoinCallback = (q: never) => PickQueryTableMetaResult;
|
|
654
|
+
type GenericJoinCallbackTuple = [GenericJoinCallback];
|
|
640
655
|
/**
|
|
641
656
|
* Result of all `joinLateral` methods.
|
|
642
657
|
* Adds joined table columns from its 'result' to the 'selectable' of the query.
|
|
@@ -645,9 +660,7 @@ type JoinResultFromArgs<T extends PickQueryMetaResultRelationsWithDataReturnType
|
|
|
645
660
|
* @param Arg - first arg of join, see {@link JoinFirstArg}
|
|
646
661
|
* @param RequireJoined - when false, joined table shape will be mapped to make all columns optional
|
|
647
662
|
*/
|
|
648
|
-
type JoinLateralResult<T extends PickQueryMeta,
|
|
649
|
-
meta: QueryMetaBase;
|
|
650
|
-
}>> = JoinAddSelectable<T, Selectable>;
|
|
663
|
+
type JoinLateralResult<T extends PickQueryMeta, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns, RequireJoined> = JoinAddSelectable<T, JoinResultSelectable<Result, Meta['as'] extends string ? Meta['as'] : Table, RequireJoined>>;
|
|
651
664
|
/**
|
|
652
665
|
* Build `selectable` type for joined table.
|
|
653
666
|
*
|
|
@@ -659,30 +672,25 @@ type JoinLateralResult<T extends PickQueryMeta, R extends QueryBase, RequireJoin
|
|
|
659
672
|
* The resulting selectable receives all joined table columns prefixed with the table name or alias,
|
|
660
673
|
* and a star prefixed with the table name or alias to select all joined columns.
|
|
661
674
|
*/
|
|
662
|
-
type JoinResultSelectable<
|
|
663
|
-
table?: string;
|
|
664
|
-
meta: QueryMetaBase;
|
|
665
|
-
shape: QueryColumns;
|
|
666
|
-
}, RequireJoined extends boolean, CbResult, Result extends QueryColumns = RequireJoined extends true ? J['shape'] : {
|
|
667
|
-
[K in keyof J['shape']]: QueryColumnToNullable<J['shape'][K]>;
|
|
668
|
-
}, As extends string = CbResult extends {
|
|
669
|
-
meta: {
|
|
670
|
-
as: string;
|
|
671
|
-
};
|
|
672
|
-
} ? CbResult['meta']['as'] : AliasOrTable<J>> = {
|
|
675
|
+
type JoinResultSelectable<Result extends QueryColumns, As extends string, RequireJoined> = (RequireJoined extends true ? {
|
|
673
676
|
[K in keyof Result & string as `${As}.${K}`]: {
|
|
674
677
|
as: K;
|
|
675
678
|
column: Result[K];
|
|
676
679
|
};
|
|
677
|
-
}
|
|
680
|
+
} : {
|
|
681
|
+
[K in keyof Result & string as `${As}.${K}`]: {
|
|
682
|
+
as: K;
|
|
683
|
+
column: QueryColumnToNullable<Result[K]>;
|
|
684
|
+
};
|
|
685
|
+
}) & {
|
|
678
686
|
[K in As as `${As}.*`]: {
|
|
679
687
|
as: K;
|
|
680
|
-
column: RequireJoined extends true ? ColumnsShapeToObject<
|
|
688
|
+
column: RequireJoined extends true ? ColumnsShapeToObject<Result> : ColumnsShapeToNullableObject<Result>;
|
|
681
689
|
};
|
|
682
690
|
};
|
|
683
|
-
type JoinAddSelectable<T extends PickQueryMeta, Selectable
|
|
684
|
-
[K in keyof T]: K extends 'meta' ?
|
|
685
|
-
selectable:
|
|
691
|
+
type JoinAddSelectable<T extends PickQueryMeta, Selectable> = {
|
|
692
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
693
|
+
[K in keyof T['meta']]: K extends 'selectable' ? T['meta']['selectable'] & Selectable : T['meta'][K];
|
|
686
694
|
} : T[K];
|
|
687
695
|
};
|
|
688
696
|
type JoinOptionalMain<T extends PickQueryMetaResultReturnType, Selectable extends SelectableBase> = {
|
|
@@ -693,43 +701,27 @@ type JoinOptionalMain<T extends PickQueryMetaResultReturnType, Selectable extend
|
|
|
693
701
|
column: QueryColumnToNullable<T['meta']['selectable'][K]['column']>;
|
|
694
702
|
};
|
|
695
703
|
} & Selectable : T['meta'][K];
|
|
696
|
-
} : K extends 'result' ?
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, {
|
|
701
|
-
[K in keyof T['result']]: QueryColumnToNullable<T['result'][K]>;
|
|
702
|
-
}>> : T[K];
|
|
704
|
+
} : K extends 'result' ? NullableResult<T> : K extends 'then' ? QueryThen<GetQueryResult<T, NullableResult<T>>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, NullableResult<T>>> : T[K];
|
|
705
|
+
};
|
|
706
|
+
type NullableResult<T extends PickQueryResult> = {
|
|
707
|
+
[K in keyof T['result']]: QueryColumnToNullable<T['result'][K]>;
|
|
703
708
|
};
|
|
704
709
|
/**
|
|
705
710
|
* Map the `with` table first argument of `join` or `joinLateral` to a query type.
|
|
706
711
|
* Constructs `selectable` based on `with` table shape, and adds generic types to conform the `QueryBase` type.
|
|
707
712
|
*/
|
|
708
|
-
|
|
709
|
-
__isQuery: true;
|
|
710
|
-
q: QueryData;
|
|
713
|
+
interface JoinWithArgToQuery<With extends WithDataItem> extends Query {
|
|
711
714
|
table: With['table'];
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
[K in keyof With['shape'] & string]: {
|
|
715
|
+
meta: QueryMetaBase & {
|
|
716
|
+
selectable: {
|
|
717
|
+
[K in keyof With['shape'] & string as `${With['table']}.${K}`]: {
|
|
716
718
|
as: K;
|
|
717
719
|
column: With['shape'][K];
|
|
718
720
|
};
|
|
719
|
-
} & string as `${With['table']}.${K}`]: {
|
|
720
|
-
as: K;
|
|
721
|
-
column: With['shape'][K];
|
|
722
721
|
};
|
|
723
722
|
};
|
|
724
|
-
shape: With['shape'];
|
|
725
723
|
result: With['shape'];
|
|
726
|
-
|
|
727
|
-
relations: RelationsBase;
|
|
728
|
-
withData: WithDataBase;
|
|
729
|
-
meta: QueryBase['meta'];
|
|
730
|
-
internal: QueryInternal;
|
|
731
|
-
returnType: QueryReturnType;
|
|
732
|
-
};
|
|
724
|
+
}
|
|
733
725
|
/**
|
|
734
726
|
* Map the first argument of `join` or `joinLateral` to a query type.
|
|
735
727
|
*
|
|
@@ -737,7 +729,8 @@ type JoinWithArgToQuery<With extends WithDataItem> = {
|
|
|
737
729
|
* query arg is returned as is,
|
|
738
730
|
* relation name is replaced with a relation table.
|
|
739
731
|
*/
|
|
740
|
-
type JoinArgToQuery<T extends PickQueryRelationsWithData, Arg extends JoinFirstArg<T>> = Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? JoinWithArgToQuery<T['withData'][Arg]> : never : Arg extends
|
|
732
|
+
type JoinArgToQuery<T extends PickQueryRelationsWithData, Arg extends JoinFirstArg<T>> = Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? JoinWithArgToQuery<T['withData'][Arg]> : never : Arg extends PickQueryTableMetaResult ? Arg : Arg extends keyof T['relations'] ? T['relations'][Arg]['relationConfig']['query'] : Arg extends JoinArgToQueryCallback ? ReturnType<Arg> : never;
|
|
733
|
+
type JoinArgToQueryCallback = (...args: any[]) => PickQueryTableMetaResult;
|
|
741
734
|
/**
|
|
742
735
|
* Type of the `join` callback (not `joinLateral`).
|
|
743
736
|
*
|
|
@@ -747,7 +740,7 @@ type JoinArgToQuery<T extends PickQueryRelationsWithData, Arg extends JoinFirstA
|
|
|
747
740
|
*
|
|
748
741
|
* Callback must return a query builder.
|
|
749
742
|
*/
|
|
750
|
-
type JoinCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = (q:
|
|
743
|
+
type JoinCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => PickQueryTableMetaResult;
|
|
751
744
|
/**
|
|
752
745
|
* Type of the `joinLateral`.
|
|
753
746
|
*
|
|
@@ -758,7 +751,14 @@ type JoinCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends Joi
|
|
|
758
751
|
*
|
|
759
752
|
* The callback must return a query object. Its resulting type will become a type of the joined table.
|
|
760
753
|
*/
|
|
761
|
-
type JoinLateralCallback<T extends
|
|
754
|
+
type JoinLateralCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns> = (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => {
|
|
755
|
+
table: Table;
|
|
756
|
+
meta: Meta;
|
|
757
|
+
result: Result;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Type of {@link Join.join} query method.
|
|
761
|
+
*/
|
|
762
762
|
type JoinQueryMethod = <T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args) => JoinResultFromArgs<T, Arg, Args, true, true>;
|
|
763
763
|
declare class Join {
|
|
764
764
|
/**
|
|
@@ -922,7 +922,7 @@ declare class Join {
|
|
|
922
922
|
*
|
|
923
923
|
* Optionally, you can pass a second callback argument, it makes `on` and `orOn` methods available.
|
|
924
924
|
*
|
|
925
|
-
* But remember that when joining a relation, the
|
|
925
|
+
* But remember that when joining a relation, the relevant `ON` conditions are already handled automatically.
|
|
926
926
|
*
|
|
927
927
|
* ```ts
|
|
928
928
|
* const result = await db.user.join(
|
|
@@ -1095,8 +1095,6 @@ declare class Join {
|
|
|
1095
1095
|
* );
|
|
1096
1096
|
* ```
|
|
1097
1097
|
*
|
|
1098
|
-
* Join query builder supports all `where` methods: `.where`, `.whereIn`, `.whereExists`, and all `.or`, `.not`, and `.orNot` forms.
|
|
1099
|
-
*
|
|
1100
1098
|
* Column names in the where conditions are applied for the joined table, but you can specify a table name to add a condition for the main table.
|
|
1101
1099
|
*
|
|
1102
1100
|
* ```ts
|
|
@@ -1151,10 +1149,35 @@ declare class Join {
|
|
|
1151
1149
|
* ) "t" ON "t"."userId" = "user"."id"
|
|
1152
1150
|
* ```
|
|
1153
1151
|
*
|
|
1152
|
+
* ## implicit join lateral
|
|
1153
|
+
*
|
|
1154
|
+
* `JOIN`'s source expression that comes before `ON` cannot access other tables, but in some cases this may be needed.
|
|
1155
|
+
*
|
|
1156
|
+
* For example, let's consider joining last 10 messages of a user:
|
|
1157
|
+
*
|
|
1158
|
+
* ```ts
|
|
1159
|
+
* await db.user.join('messages', (q) => q.order({ createdAt: 'DESC' }).limit(10));
|
|
1160
|
+
* ```
|
|
1161
|
+
*
|
|
1162
|
+
* When the `join`'s callback returns a more complex query than the one that simply applies certain conditions,
|
|
1163
|
+
* it will implicitly generate a `JOIN LATERAL` SQL query, as the following:
|
|
1164
|
+
*
|
|
1165
|
+
* ```sql
|
|
1166
|
+
* SELECT *
|
|
1167
|
+
* FROM "user"
|
|
1168
|
+
* JOIN LATERAL (
|
|
1169
|
+
* SELECT *
|
|
1170
|
+
* FROM "message" AS "messages"
|
|
1171
|
+
* WHERE "message"."userId" = "user"."id"
|
|
1172
|
+
* ORDER BY "message"."createdAt" DESC
|
|
1173
|
+
* LIMIT 10
|
|
1174
|
+
* ) "messages" ON true
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1154
1177
|
* @param arg - {@link JoinFirstArg}
|
|
1155
1178
|
* @param args - {@link JoinArgs}
|
|
1156
1179
|
*/
|
|
1157
|
-
join<T extends
|
|
1180
|
+
join<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args): JoinResultFromArgs<T, Arg, Args, true, true>;
|
|
1158
1181
|
/**
|
|
1159
1182
|
* `leftJoin` is a method for SQL `LEFT JOIN`, which is equivalent to `OUTER JOIN`, `LEFT OUTER JOIN`.
|
|
1160
1183
|
*
|
|
@@ -1179,7 +1202,7 @@ declare class Join {
|
|
|
1179
1202
|
* @param arg - {@link JoinFirstArg}
|
|
1180
1203
|
* @param args - {@link JoinArgs}
|
|
1181
1204
|
*/
|
|
1182
|
-
leftJoin<T extends
|
|
1205
|
+
leftJoin<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args): JoinResultFromArgs<T, Arg, Args, false, true>;
|
|
1183
1206
|
/**
|
|
1184
1207
|
* `rightJoin` is a method for SQL `RIGHT JOIN`, which is equivalent to `RIGHT OUTER JOIN`.
|
|
1185
1208
|
*
|
|
@@ -1201,7 +1224,7 @@ declare class Join {
|
|
|
1201
1224
|
* @param arg - {@link JoinFirstArg}
|
|
1202
1225
|
* @param args - {@link JoinArgs}
|
|
1203
1226
|
*/
|
|
1204
|
-
rightJoin<T extends
|
|
1227
|
+
rightJoin<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args): JoinResultFromArgs<T, Arg, Args, true, false>;
|
|
1205
1228
|
/**
|
|
1206
1229
|
* `fullJoin` is a method for SQL `FULL JOIN`, which is equivalent to `FULL OUTER JOIN`.
|
|
1207
1230
|
*
|
|
@@ -1223,18 +1246,16 @@ declare class Join {
|
|
|
1223
1246
|
* @param arg - {@link JoinFirstArg}
|
|
1224
1247
|
* @param args - {@link JoinArgs}
|
|
1225
1248
|
*/
|
|
1226
|
-
fullJoin<T extends
|
|
1249
|
+
fullJoin<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args): JoinResultFromArgs<T, Arg, Args, false, false>;
|
|
1227
1250
|
/**
|
|
1228
1251
|
* `joinLateral` allows joining a table with a sub-query that can reference the main table of current query and the other joined tables.
|
|
1229
1252
|
*
|
|
1230
|
-
* Regular `JOIN` also can have a sub-query in its definition, but it cannot reference other tables of this query.
|
|
1231
|
-
*
|
|
1232
|
-
* `JOIN LATERAL` of Postgres can have conditions in the `ON` statement, but `Orchid ORM` decided that there are no useful use-cases for such conditions, and it is only building a sub-query.
|
|
1233
|
-
*
|
|
1234
1253
|
* First argument is the other table you want to join, or a name of relation, or a name of `with` defined table.
|
|
1235
1254
|
*
|
|
1236
1255
|
* Second argument is a callback where you can reference other tables using `on` and `orOn`, select columns, do `where` conditions, and use any other query methods to build a sub-query.
|
|
1237
1256
|
*
|
|
1257
|
+
* Note that the regular `join` will also generate `JOIN LATERAL` SQL expression when the query returned from callback is complex enough (see the bottom of {@link join} description).
|
|
1258
|
+
*
|
|
1238
1259
|
* ```ts
|
|
1239
1260
|
* // joinLateral a Message table, alias it as `m`
|
|
1240
1261
|
* // without aliasing you can refer to the message by a table name
|
|
@@ -1291,7 +1312,7 @@ declare class Join {
|
|
|
1291
1312
|
* @param arg - {@link JoinFirstArg}
|
|
1292
1313
|
* @param cb - {@link JoinLateralCallback}
|
|
1293
1314
|
*/
|
|
1294
|
-
joinLateral<T extends
|
|
1315
|
+
joinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb: JoinLateralCallback<T, Arg, Table, Meta, Result>): JoinLateralResult<T, Table, Meta, Result, true>;
|
|
1295
1316
|
/**
|
|
1296
1317
|
* The same as {@link joinLateral}, but when no records found for the join it will result in `null`:
|
|
1297
1318
|
*
|
|
@@ -1307,47 +1328,41 @@ declare class Join {
|
|
|
1307
1328
|
* @param arg - {@link JoinFirstArg}
|
|
1308
1329
|
* @param cb - {@link JoinLateralCallback}
|
|
1309
1330
|
*/
|
|
1310
|
-
leftJoinLateral<T extends
|
|
1331
|
+
leftJoinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb: JoinLateralCallback<T, Arg, Table, Meta, Result>): JoinLateralResult<T, Table, Meta, Result, false>;
|
|
1311
1332
|
}
|
|
1312
|
-
type OnArgs<
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
leftColumn: keyof
|
|
1318
|
-
rightColumn: keyof Q['meta']['selectable']
|
|
1319
|
-
] | [
|
|
1320
|
-
leftColumn: keyof Q['meta']['selectable'],
|
|
1321
|
-
op: string,
|
|
1322
|
-
rightColumn: keyof Q['meta']['selectable']
|
|
1323
|
-
];
|
|
1324
|
-
declare const pushQueryOn: <T extends QueryBase<orchid_core.EmptyObject>>(q: T, joinFrom: QueryBase, joinTo: QueryBase, ...on: OnArgs<QueryBase>) => T;
|
|
1325
|
-
declare const pushQueryOrOn: typeof pushQueryOn;
|
|
1326
|
-
declare const addQueryOn: <T extends QueryBase<orchid_core.EmptyObject>>(q: T, joinFrom: QueryBase, joinTo: QueryBase, ...args: OnArgs<QueryBase>) => T;
|
|
1327
|
-
type OnJsonPathEqualsArgs<T extends QueryBase> = [
|
|
1328
|
-
leftColumn: keyof T['meta']['selectable'],
|
|
1333
|
+
type OnArgs<S extends SelectableBase> = [leftColumn: keyof S, rightColumn: keyof S] | [leftColumn: keyof S, op: string, rightColumn: keyof S];
|
|
1334
|
+
declare const pushQueryOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => T;
|
|
1335
|
+
declare const pushQueryOrOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => PickQueryQ;
|
|
1336
|
+
declare const addQueryOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...args: OnArgs<SelectableBase>) => T;
|
|
1337
|
+
type OnJsonPathEqualsArgs<S extends SelectableBase> = [
|
|
1338
|
+
leftColumn: keyof S,
|
|
1329
1339
|
leftPath: string,
|
|
1330
|
-
rightColumn: keyof
|
|
1340
|
+
rightColumn: keyof S,
|
|
1331
1341
|
rightPath: string
|
|
1332
1342
|
];
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1343
|
+
/**
|
|
1344
|
+
* Mutative {@link OnMethods.on}
|
|
1345
|
+
*/
|
|
1346
|
+
declare const _queryJoinOn: <T extends PickQueryMeta>(q: T, args: OnArgs<T['meta']['selectable']>) => T;
|
|
1347
|
+
/**
|
|
1348
|
+
* Mutative {@link OnMethods.orOn}
|
|
1349
|
+
*/
|
|
1350
|
+
declare const _queryJoinOrOn: <T extends PickQueryMeta>(q: T, args: OnArgs<T['meta']['selectable']>) => T;
|
|
1351
|
+
/**
|
|
1352
|
+
* Mutative {@link OnMethods.onJsonPathEquals}
|
|
1353
|
+
*/
|
|
1354
|
+
declare const _queryJoinOnJsonPathEquals: <T extends PickQueryMeta>(q: T, args: OnJsonPathEqualsArgs<T["meta"]["selectable"]>) => T;
|
|
1355
|
+
/**
|
|
1356
|
+
* Argument of join callback.
|
|
1357
|
+
* It is a query object of table that you're joining, with ability to select main table's columns.
|
|
1358
|
+
* Adds {@link OnMethods.on} method and similar to the query.
|
|
1359
|
+
*/
|
|
1360
|
+
type JoinQueryBuilder<T extends PickQueryMetaShape = PickQueryMetaShape, J extends PickQueryTableMetaResult = PickQueryTableMetaResult> = {
|
|
1361
|
+
[K in keyof J]: K extends 'meta' ? {
|
|
1362
|
+
[K in keyof J['meta']]: K extends 'selectable' ? J['meta']['selectable'] & Omit<T['meta']['selectable'], keyof T['shape']> : J['meta'][K];
|
|
1363
|
+
} : J[K];
|
|
1364
|
+
} & OnMethods;
|
|
1365
|
+
declare class OnMethods {
|
|
1351
1366
|
/**
|
|
1352
1367
|
* Use `on` to specify columns to join records.
|
|
1353
1368
|
*
|
|
@@ -1367,13 +1382,13 @@ declare class OnQueryBuilder<S extends PickQueryMetaShape = QueryBase, J extends
|
|
|
1367
1382
|
*
|
|
1368
1383
|
* @param args - columns to join with
|
|
1369
1384
|
*/
|
|
1370
|
-
on<T extends
|
|
1385
|
+
on<T extends PickQueryMeta>(this: T, ...args: OnArgs<T['meta']['selectable']>): T;
|
|
1371
1386
|
/**
|
|
1372
1387
|
* Works as {@link on}, but the added conditions will be separated from previous with `OR`.
|
|
1373
1388
|
*
|
|
1374
1389
|
* @param args - columns to join with
|
|
1375
1390
|
*/
|
|
1376
|
-
orOn<T extends
|
|
1391
|
+
orOn<T extends PickQueryMeta>(this: T, ...args: OnArgs<T['meta']['selectable']>): T;
|
|
1377
1392
|
/**
|
|
1378
1393
|
* Use `onJsonPathEquals` to join record based on a field of their JSON column:
|
|
1379
1394
|
*
|
|
@@ -1386,7 +1401,7 @@ declare class OnQueryBuilder<S extends PickQueryMetaShape = QueryBase, J extends
|
|
|
1386
1401
|
*
|
|
1387
1402
|
* @param args - columns and JSON paths to join with.
|
|
1388
1403
|
*/
|
|
1389
|
-
onJsonPathEquals<T extends
|
|
1404
|
+
onJsonPathEquals<T extends PickQueryMeta>(this: T, ...args: OnJsonPathEqualsArgs<T['meta']['selectable']>): T;
|
|
1390
1405
|
}
|
|
1391
1406
|
|
|
1392
1407
|
type WhereArg<T extends PickQueryMetaRelations> = {
|
|
@@ -1394,7 +1409,7 @@ type WhereArg<T extends PickQueryMetaRelations> = {
|
|
|
1394
1409
|
columns: (keyof T['meta']['selectable'])[];
|
|
1395
1410
|
values: unknown[][] | QueryBase | Expression;
|
|
1396
1411
|
}> : T['meta']['selectable'][K]['column']['queryType'] | null | ColumnOperators<T['meta']['selectable'], K> | Expression | QueryBase;
|
|
1397
|
-
} | QueryBase | Expression<
|
|
1412
|
+
} | QueryBase | Expression<QueryColumnBooleanOrNull> | ((q: WhereQueryBuilder<T>) => QueryColumnBooleanOrNull | QueryBaseThen<boolean | null> | WhereQueryBuilder<T>);
|
|
1398
1413
|
/**
|
|
1399
1414
|
* Callback argument of `where`.
|
|
1400
1415
|
* It has `where` methods (`where`, `whereNot`, `whereExists`, etc.),
|
|
@@ -1427,41 +1442,38 @@ interface QueryMetaHasWhere {
|
|
|
1427
1442
|
hasWhere: true;
|
|
1428
1443
|
};
|
|
1429
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Mutative {@link Where.where}
|
|
1447
|
+
*/
|
|
1430
1448
|
declare const _queryWhere: <T extends PickQueryMetaRelations>(q: T, args: WhereArgs<T>) => WhereResult<T>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Mutative {@link Where.whereSql}
|
|
1451
|
+
*/
|
|
1431
1452
|
declare const _queryWhereSql: <T>(q: T, args: SQLQueryArgs) => T;
|
|
1432
1453
|
/**
|
|
1433
|
-
*
|
|
1434
|
-
* SQL template string is added as `RawSQL` object, other arguments are added as is.
|
|
1435
|
-
*
|
|
1436
|
-
* @param q - query object to add the data to
|
|
1437
|
-
* @param args - `where` arguments
|
|
1454
|
+
* Mutative {@link Where.whereNot}
|
|
1438
1455
|
*/
|
|
1439
1456
|
declare const _queryWhereNot: <T extends PickQueryMetaRelations>(q: T, args: WhereNotArgs<T>) => WhereResult<T>;
|
|
1457
|
+
/**
|
|
1458
|
+
* Mutative {@link Where.whereNotSql}
|
|
1459
|
+
*/
|
|
1440
1460
|
declare const _queryWhereNotSql: <T>(q: T, args: SQLQueryArgs) => T;
|
|
1441
1461
|
/**
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
* @param q - query object to add the data to
|
|
1445
|
-
* @param args - `where` arguments
|
|
1462
|
+
* Mutative {@link Where.orWhere}
|
|
1446
1463
|
*/
|
|
1447
1464
|
declare const _queryOr: <T extends PickQueryMetaRelations>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
1448
1465
|
/**
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1451
|
-
* @param q - query object to add the data to
|
|
1452
|
-
* @param args - `where` arguments, may be a template literal
|
|
1466
|
+
* Mutative {@link Where.orWhereNot}
|
|
1453
1467
|
*/
|
|
1454
1468
|
declare const _queryOrNot: <T extends PickQueryMetaRelations>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
1455
1469
|
/**
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1458
|
-
* @param q - query object to add the data to.
|
|
1459
|
-
* @param and - `true` to join arguments with `AND`, `false` to join them with `OR.
|
|
1460
|
-
* @param arg - `whereIn` argument: can be a single column name, tuple of column names, or object with column names and values.
|
|
1461
|
-
* @param values - if the `arg` is a column name or a tuple, `values` are the values for the column/columns. If `arg` is an object, `values` are `undefined`.
|
|
1462
|
-
* @param not - adds the `NOT` keyword.
|
|
1470
|
+
* Mutative {@link Where.whereIn}
|
|
1463
1471
|
*/
|
|
1464
1472
|
declare const _queryWhereIn: <T>(q: T, and: boolean, arg: unknown, values: unknown[] | unknown[][] | Query | Expression | undefined, not?: boolean) => WhereResult<T>;
|
|
1473
|
+
/**
|
|
1474
|
+
* Mutative {@link Where.whereExists}
|
|
1475
|
+
*/
|
|
1476
|
+
declare const _queryWhereExists: <T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>>(q: T, arg: Arg, args: JoinArgs<T, Arg>) => WhereResult<T>;
|
|
1465
1477
|
declare class Where {
|
|
1466
1478
|
/**
|
|
1467
1479
|
* Constructing `WHERE` conditions:
|
|
@@ -2036,10 +2048,6 @@ declare class Where {
|
|
|
2036
2048
|
*/
|
|
2037
2049
|
orWhereNotExists<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>>(this: T, arg: Arg, ...args: JoinArgs<T, Arg>): WhereResult<T>;
|
|
2038
2050
|
}
|
|
2039
|
-
interface WhereQueryBase extends Where, QueryBase {
|
|
2040
|
-
}
|
|
2041
|
-
declare abstract class WhereQueryBase extends QueryBase {
|
|
2042
|
-
}
|
|
2043
2051
|
|
|
2044
2052
|
interface ScopeArgumentQueryMeta<Table extends string | undefined, Shape extends QueryColumns> extends QueryMetaBase {
|
|
2045
2053
|
selectable: SelectableFromShape<Shape, Table>;
|
|
@@ -2416,6 +2424,14 @@ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseCo
|
|
|
2416
2424
|
toCode(t: string): Code;
|
|
2417
2425
|
}
|
|
2418
2426
|
|
|
2427
|
+
declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
|
|
2428
|
+
dataType: "boolean";
|
|
2429
|
+
operators: OperatorsBoolean;
|
|
2430
|
+
constructor(schema: Schema);
|
|
2431
|
+
toCode(t: string): Code;
|
|
2432
|
+
parseItem: (input: string) => boolean;
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2419
2435
|
declare class CustomTypeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, unknown, ReturnType<Schema['unknown']>, typeof Operators.any> {
|
|
2420
2436
|
dataType: string;
|
|
2421
2437
|
operators: OperatorsAny;
|
|
@@ -2507,7 +2523,7 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
|
|
|
2507
2523
|
timestamp: SchemaConfig['timestamp'];
|
|
2508
2524
|
time(precision?: number): TimeColumn<SchemaConfig>;
|
|
2509
2525
|
interval(fields?: string, precision?: number): IntervalColumn<SchemaConfig>;
|
|
2510
|
-
boolean(): BooleanColumn
|
|
2526
|
+
boolean(): BooleanColumn<SchemaConfig>;
|
|
2511
2527
|
point(): PointColumn<SchemaConfig>;
|
|
2512
2528
|
line(): LineColumn<SchemaConfig>;
|
|
2513
2529
|
lseg(): LsegColumn<SchemaConfig>;
|
|
@@ -2790,7 +2806,6 @@ interface Db<Table extends string | undefined = undefined, Shape extends QueryCo
|
|
|
2790
2806
|
new (adapter: Adapter, queryBuilder: Db<Table, Shape, Relations, ColumnTypes>, table?: Table, shape?: Shape, options?: DbTableOptions<Table, ShapeWithComputed>): this;
|
|
2791
2807
|
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
2792
2808
|
queryBuilder: Db;
|
|
2793
|
-
onQueryBuilder: Query['onQueryBuilder'];
|
|
2794
2809
|
primaryKeys: Query['primaryKeys'];
|
|
2795
2810
|
returnType: Query['returnType'];
|
|
2796
2811
|
then: QueryThen<QueryDefaultReturnData<Shape>>;
|
|
@@ -2982,9 +2997,8 @@ declare const makeSQL: (table: ToSQLQuery, options?: ToSqlOptionsInternal) => Sq
|
|
|
2982
2997
|
declare function pushLimitSQL(sql: string[], values: unknown[], q: SelectQueryData): void;
|
|
2983
2998
|
|
|
2984
2999
|
type AliasOrTable<T extends PickQueryMetaTable> = T['meta']['as'] extends string ? T['meta']['as'] : T['table'] extends string ? T['table'] : never;
|
|
2985
|
-
type SelectableOrExpression<T extends PickQueryMeta =
|
|
3000
|
+
type SelectableOrExpression<T extends PickQueryMeta = PickQueryMeta, C extends QueryColumn = QueryColumn> = '*' | keyof T['meta']['selectable'] | Expression<C>;
|
|
2986
3001
|
type ExpressionOutput<T extends PickQueryMeta, Expr extends SelectableOrExpression<T>> = Expr extends keyof T['meta']['selectable'] ? T['meta']['selectable'][Expr]['column'] : Expr extends Expression ? Expr['_type'] : never;
|
|
2987
|
-
type ExpressionOrQueryReturning<T> = Expression<QueryColumn<T>> | QueryBaseThen<T>;
|
|
2988
3002
|
declare const getClonedQueryData: (query: QueryData) => QueryData;
|
|
2989
3003
|
declare const getQueryAs: (q: {
|
|
2990
3004
|
table?: string | undefined;
|
|
@@ -3045,7 +3059,7 @@ declare class FnExpression<Q extends Query = Query, T extends QueryColumn = Quer
|
|
|
3045
3059
|
makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
|
|
3046
3060
|
}
|
|
3047
3061
|
type ColumnExpression<C extends QueryColumn, Ops extends BaseOperators = C['operators']> = Expression<C> & {
|
|
3048
|
-
[K in keyof Ops]: (arg: Ops[K]['_opType']) => ColumnExpression<
|
|
3062
|
+
[K in keyof Ops]: (arg: Ops[K]['_opType']) => ColumnExpression<QueryColumnBooleanOrNull>;
|
|
3049
3063
|
};
|
|
3050
3064
|
declare const makeExpression: <T extends Query, C extends ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>(self: T, expr: Expression) => SetQueryReturnsColumnOrThrow<T, C> & C['operators'];
|
|
3051
3065
|
declare function makeFnExpression<T extends PickQueryMetaResultRelationsWindows, C extends QueryColumn>(self: T, type: C, fn: string, args: FnExpressionArgs<Query>, options?: AggregateOptions<T>): SetQueryReturnsColumnOrThrow<T, C> & C['operators'];
|
|
@@ -3066,7 +3080,7 @@ type CountReturn<T> = QueryReturnsAgg<T, number, OperatorsNumber> & {
|
|
|
3066
3080
|
type NumberColumn = QueryColumn<number, OperatorsNumber>;
|
|
3067
3081
|
type NumberNullable = QueryColumn<number | null, OperatorsNumber>;
|
|
3068
3082
|
type NullableNumberReturn<T> = SetQueryReturnsColumnOrThrow<T, NumberNullable> & OperatorsNumber;
|
|
3069
|
-
type
|
|
3083
|
+
type BooleanQueryColumn = QueryColumn<boolean, OperatorsBoolean>;
|
|
3070
3084
|
type BooleanNullable = QueryColumn<boolean | null, OperatorsBoolean>;
|
|
3071
3085
|
type NullableBooleanReturn<T> = SetQueryReturnsColumnOrThrow<T, BooleanNullable> & OperatorsBoolean;
|
|
3072
3086
|
type NullableJSONAggReturn<T extends PickQueryMeta, Arg extends SelectableOrExpression<T>> = SetQueryReturnsColumnOrThrow<T, {
|
|
@@ -3140,7 +3154,7 @@ declare class AggregateMethods {
|
|
|
3140
3154
|
* const exists: boolean = await db.table.where(...conditions).exists();
|
|
3141
3155
|
* ```
|
|
3142
3156
|
*/
|
|
3143
|
-
exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T,
|
|
3157
|
+
exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
|
|
3144
3158
|
/**
|
|
3145
3159
|
* Count records with the `count` function:
|
|
3146
3160
|
*
|
|
@@ -3308,7 +3322,7 @@ declare class AggregateMethods {
|
|
|
3308
3322
|
* @param arg - boolean column or raw SQL
|
|
3309
3323
|
* @param options - aggregation options
|
|
3310
3324
|
*/
|
|
3311
|
-
boolAnd<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T,
|
|
3325
|
+
boolAnd<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T, BooleanQueryColumn>, options?: AggregateOptions<T>): NullableBooleanReturn<T>;
|
|
3312
3326
|
/**
|
|
3313
3327
|
* Aggregate booleans with `or` logic, it returns `boolean` or `null` if there are no records.
|
|
3314
3328
|
*
|
|
@@ -3329,11 +3343,11 @@ declare class AggregateMethods {
|
|
|
3329
3343
|
* @param arg - boolean column or raw SQL
|
|
3330
3344
|
* @param options - aggregation options
|
|
3331
3345
|
*/
|
|
3332
|
-
boolOr<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T,
|
|
3346
|
+
boolOr<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T, BooleanQueryColumn>, options?: AggregateOptions<T>): NullableBooleanReturn<T>;
|
|
3333
3347
|
/**
|
|
3334
3348
|
* Equivalent to {@link boolAnd}
|
|
3335
3349
|
*/
|
|
3336
|
-
every<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T,
|
|
3350
|
+
every<T extends PickQueryMetaResultRelationsWindows>(this: T, arg: SelectableOrExpressionOfType<T, BooleanQueryColumn>, options?: AggregateOptions<T>): NullableBooleanReturn<T>;
|
|
3337
3351
|
/**
|
|
3338
3352
|
* Aggregate values into an array by using `json_agg`. Returns array of values or `null` if there are no records.
|
|
3339
3353
|
*
|
|
@@ -4667,7 +4681,7 @@ type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = {
|
|
|
4667
4681
|
[K in Columns[number] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
|
|
4668
4682
|
}) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
|
|
4669
4683
|
} & QueryMetaHasSelect;
|
|
4670
|
-
type SelectResultObj<T extends SelectSelf, Obj
|
|
4684
|
+
type SelectResultObj<T extends SelectSelf, Obj> = {
|
|
4671
4685
|
[K in keyof T]: K extends 'meta' ? T['meta'] & {
|
|
4672
4686
|
selectable: SelectAsSelectable<Obj>;
|
|
4673
4687
|
} : K extends 'result' ? {
|
|
@@ -4678,7 +4692,7 @@ type SelectResultObj<T extends SelectSelf, Obj extends SelectAsArg<T>> = {
|
|
|
4678
4692
|
[K in keyof Obj | (T['meta']['hasSelect'] extends true ? keyof T['result'] : never)]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never;
|
|
4679
4693
|
}>> : T[K];
|
|
4680
4694
|
} & QueryMetaHasSelect;
|
|
4681
|
-
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj
|
|
4695
|
+
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = {
|
|
4682
4696
|
[K in keyof T]: K extends 'meta' ? T['meta'] & {
|
|
4683
4697
|
selectable: SelectAsSelectable<Obj>;
|
|
4684
4698
|
} : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
@@ -6497,6 +6511,13 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6497
6511
|
declare function queryJson<T>(self: T, coalesce?: boolean): SetQueryReturnsColumnOptional<T, QueryColumn<string>>;
|
|
6498
6512
|
|
|
6499
6513
|
declare function queryWrap<T extends PickQueryTableMetaResult, Q extends WrapQueryArg, As extends string = 't'>(self: T, query: Q, as?: As): SetQueryTableAlias<Q, As>;
|
|
6514
|
+
/**
|
|
6515
|
+
* This function is useful when wrapping a query,
|
|
6516
|
+
* such as when doing `SELECT json_agg(t.*) FROM (...) AS t`,
|
|
6517
|
+
* to get rid of default scope conditions (WHERE deletedAt IS NULL)
|
|
6518
|
+
* that otherwise would be duplicated inside the `FROM` and after `AS t`.
|
|
6519
|
+
*/
|
|
6520
|
+
declare function cloneQueryBaseUnscoped(query: Query): Query;
|
|
6500
6521
|
|
|
6501
6522
|
type SelectableFromShape<Shape extends QueryColumns, Table extends string | undefined> = {
|
|
6502
6523
|
[K in keyof Shape]: {
|
|
@@ -6520,7 +6541,6 @@ type WithDataBase = EmptyObject;
|
|
|
6520
6541
|
interface Query extends QueryBase, QueryMethods<unknown> {
|
|
6521
6542
|
queryBuilder: Db;
|
|
6522
6543
|
columnTypes: unknown;
|
|
6523
|
-
onQueryBuilder: typeof OnQueryBuilder;
|
|
6524
6544
|
shape: QueryColumns;
|
|
6525
6545
|
singlePrimaryKey: string;
|
|
6526
6546
|
primaryKeys: string[];
|
|
@@ -7235,4 +7255,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
7235
7255
|
*/
|
|
7236
7256
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
7237
7257
|
|
|
7238
|
-
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn
|
|
7258
|
+
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbOptions, DbResult, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DropMode, DynamicRawSQL, EnumColumn, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, ForeignKey, ForeignKeyAction, ForeignKeyMatch, ForeignKeyOptions, From, FromArg, FromArgOptions, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, IndexColumnOptions, IndexOptions, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBeforeHook, QueryData, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryResult, QueryReturnsAll, QueryScopeData, QueryScopes, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithComputed, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, RelationsChain, SearchArg, SearchMethods, SearchWeight, Select, SelectArg, SelectAs, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, SetQueryWith, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SingleColumnIndexOptions, SingleColumnIndexOptionsForColumn, SmallIntColumn, SmallSerialColumn, SortDir, StringColumn$1 as StringColumn, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertArg, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithDataItems, WithItem, WithOptions, WrapQueryArg, XMLColumn, _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, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintPropsToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getTableData, handleResult, identityToCode, indexToCode, instantiateColumn, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlQueryArgsToExpression, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|