pqb 0.71.0 → 0.71.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 +299 -255
- package/dist/index.js +23 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +295 -251
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -737,7 +737,7 @@ declare namespace TableData$1 {
|
|
|
737
737
|
name?: string;
|
|
738
738
|
}
|
|
739
739
|
export interface ColumnIndex {
|
|
740
|
-
options: Index.
|
|
740
|
+
options: Index.ColumnOptionsData;
|
|
741
741
|
}
|
|
742
742
|
export interface ColumnExclude extends ColumnIndex {
|
|
743
743
|
with: string;
|
|
@@ -788,7 +788,11 @@ declare namespace TableData$1 {
|
|
|
788
788
|
order?: string;
|
|
789
789
|
weight?: SearchWeight$1;
|
|
790
790
|
}
|
|
791
|
-
|
|
791
|
+
/**
|
|
792
|
+
* Controls when Postgres checks a unique constraint.
|
|
793
|
+
*/
|
|
794
|
+
export type UniqueDeferrable = false | 'immediate' | 'deferred';
|
|
795
|
+
export interface BaseUniqueOptionsArg<Name extends string = string> {
|
|
792
796
|
name?: Name;
|
|
793
797
|
nullsNotDistinct?: boolean;
|
|
794
798
|
using?: string;
|
|
@@ -798,23 +802,45 @@ declare namespace TableData$1 {
|
|
|
798
802
|
where?: string;
|
|
799
803
|
dropMode?: DropMode;
|
|
800
804
|
}
|
|
801
|
-
export interface
|
|
805
|
+
export interface UniqueOptionsArg<Name extends string = string> extends BaseUniqueOptionsArg<Name> {
|
|
806
|
+
/**
|
|
807
|
+
* Makes this unique definition a deferrable Postgres constraint.
|
|
808
|
+
*/
|
|
809
|
+
deferrable?: UniqueDeferrable;
|
|
810
|
+
}
|
|
811
|
+
export interface NonUniqueIndexOptionsArg<Name extends string = string> extends BaseUniqueOptionsArg<Name> {
|
|
812
|
+
unique?: false;
|
|
813
|
+
deferrable?: never;
|
|
814
|
+
}
|
|
815
|
+
export interface UniqueIndexOptionsArg<Name extends string = string> extends UniqueOptionsArg<Name> {
|
|
816
|
+
unique: true;
|
|
817
|
+
}
|
|
818
|
+
export type OptionsArg<Name extends string = string> = NonUniqueIndexOptionsArg<Name> | UniqueIndexOptionsArg<Name>;
|
|
819
|
+
export type TsVectorArg = OptionsArg & TsVectorOptions;
|
|
820
|
+
export interface Options extends UniqueOptionsArg, TsVectorOptions {
|
|
802
821
|
unique?: boolean;
|
|
803
822
|
}
|
|
804
|
-
export interface TsVectorArg extends OptionsArg, TsVectorOptions {}
|
|
805
|
-
export type Options = TsVectorArg;
|
|
806
823
|
export interface UniqueColumnArg<Name extends string = string> extends ColumnOptions, UniqueOptionsArg<Name> {
|
|
807
824
|
expression?: string;
|
|
808
825
|
}
|
|
809
|
-
export interface
|
|
810
|
-
|
|
826
|
+
export interface NonUniqueColumnArg<Name extends string = string> extends ColumnOptions, BaseUniqueOptionsArg<Name> {
|
|
827
|
+
expression?: string;
|
|
828
|
+
unique?: false;
|
|
829
|
+
deferrable?: never;
|
|
830
|
+
}
|
|
831
|
+
export interface UniqueIndexColumnArg<Name extends string = string> extends UniqueColumnArg<Name> {
|
|
832
|
+
unique: true;
|
|
811
833
|
}
|
|
834
|
+
export interface ColumnOptionsData extends ColumnOptions, Options {
|
|
835
|
+
expression?: string;
|
|
836
|
+
}
|
|
837
|
+
export type ColumnArg<Name extends string = string> = NonUniqueColumnArg<Name> | UniqueIndexColumnArg<Name>;
|
|
812
838
|
interface TsVectorOptions {
|
|
813
839
|
language?: string;
|
|
814
840
|
languageColumn?: string;
|
|
815
841
|
tsVector?: boolean;
|
|
816
842
|
}
|
|
817
|
-
export
|
|
843
|
+
export type TsVectorColumnArg = ColumnArg & TsVectorOptions;
|
|
818
844
|
export interface ExpressionOptions extends ColumnOptions {
|
|
819
845
|
expression: string;
|
|
820
846
|
}
|
|
@@ -2058,11 +2084,11 @@ interface QueryInternal$1<SinglePrimaryKey = any, UniqueColumns = any, UniqueCol
|
|
|
2058
2084
|
nestedCreateBatchMax: number;
|
|
2059
2085
|
}
|
|
2060
2086
|
type SQLQueryArgs = TemplateLiteralArgs$1 | [RawSqlBase$1];
|
|
2061
|
-
interface RawSqlBase$1 extends Expression$1 {
|
|
2087
|
+
interface RawSqlBase$1<T extends Column$1.Pick.QueryColumn = Column$1.Pick.QueryColumn> extends Expression$1<T> {
|
|
2062
2088
|
_sql: string | TemplateLiteralArgs$1;
|
|
2063
2089
|
_values?: RawSQLValues;
|
|
2064
2090
|
}
|
|
2065
|
-
interface RawSql$1<T extends Column$1.Pick.QueryColumn, ColumnTypes> extends Expression$1<T>, RawSqlBase$1
|
|
2091
|
+
interface RawSql$1<T extends Column$1.Pick.QueryColumn, ColumnTypes> extends Expression$1<T>, RawSqlBase$1<T>, ExpressionTypeMethod {}
|
|
2066
2092
|
declare class RawSql$1<T extends Column$1.Pick.QueryColumn = Column$1.Pick.QueryColumn, ColumnTypes = DefaultColumnTypes$1<ColumnSchemaConfig$1>> extends Expression$1<T> {
|
|
2067
2093
|
result: {
|
|
2068
2094
|
value: T;
|
|
@@ -5086,6 +5112,246 @@ interface OperatorsArray$1<T> extends Ord$1<T[]> {
|
|
|
5086
5112
|
_opType: number | { [K in Exclude<keyof OperatorsNumber, '__hasSelect'>]?: OperatorsNumber[K]['_opType'] };
|
|
5087
5113
|
};
|
|
5088
5114
|
}
|
|
5115
|
+
interface ColumnsShape$1 {
|
|
5116
|
+
[K: string]: Column$1;
|
|
5117
|
+
}
|
|
5118
|
+
declare namespace ColumnsShape$1 {
|
|
5119
|
+
export type DefaultSelectKeys<S extends Column$1.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
|
|
5120
|
+
export type DefaultOutput<Set extends Column$1.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
|
|
5121
|
+
export type Input<Shape extends Column$1.QueryColumnsInit, AppReadOnly = { [K in keyof Shape]: Shape[K]['data']['appReadOnly'] extends true ? K : never }[keyof Shape], Optional extends keyof Shape = { [K in keyof Shape]: Shape[K]['data']['optional'] extends true ? K : never }[keyof Shape]> = { [K in Exclude<keyof Shape, AppReadOnly | Optional>]: Shape[K]['__inputType'] } & { [K in Exclude<Optional, AppReadOnly>]?: Shape[K]['__inputType'] };
|
|
5122
|
+
export type InputPartial<Shape extends Column$1.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
|
|
5123
|
+
export type Output<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5124
|
+
export type DefaultSelectOutput<Shape extends Column$1.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
|
|
5125
|
+
export interface MapToObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5126
|
+
dataType: 'object';
|
|
5127
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5128
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>;
|
|
5129
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
|
|
5130
|
+
operators: OperatorsAny;
|
|
5131
|
+
}
|
|
5132
|
+
export interface MapToNullableObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5133
|
+
dataType: 'object';
|
|
5134
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5135
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>> | undefined;
|
|
5136
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
|
|
5137
|
+
operators: OperatorsAny;
|
|
5138
|
+
}
|
|
5139
|
+
export interface MapToPluckColumn<Shape extends Column$1.QueryColumns> {
|
|
5140
|
+
dataType: 'array';
|
|
5141
|
+
__type: Shape['pluck']['__type'][];
|
|
5142
|
+
__outputType: Shape['pluck']['__outputType'][];
|
|
5143
|
+
__queryType: Shape['pluck']['__queryType'][];
|
|
5144
|
+
operators: OperatorsAny;
|
|
5145
|
+
}
|
|
5146
|
+
export interface MapToObjectArrayColumn<Shape extends Column$1.QueryColumns> {
|
|
5147
|
+
dataType: 'array';
|
|
5148
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] }[];
|
|
5149
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>[];
|
|
5150
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
|
|
5151
|
+
operators: OperatorsAny;
|
|
5152
|
+
}
|
|
5153
|
+
type ObjectOutput<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5154
|
+
export {};
|
|
5155
|
+
}
|
|
5156
|
+
interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape$1, PickQueryRelations$1, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
|
|
5157
|
+
type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
5158
|
+
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
5159
|
+
withData: T['withData'];
|
|
5160
|
+
}
|
|
5161
|
+
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject$1 extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? RelationQueryMaybeSingle<T['relations'][K]> & SubQueryAddition<T> : K extends keyof T ? T[K] : never };
|
|
5162
|
+
interface SelectAsArg<T extends SelectSelf> {
|
|
5163
|
+
[K: string]: keyof T['__selectable'] | Expression$1 | ((q: SelectAsFnArg<T>) => unknown);
|
|
5164
|
+
}
|
|
5165
|
+
type SelectAsFnReturnType = {
|
|
5166
|
+
result: Column$1.QueryColumns;
|
|
5167
|
+
returnType: Exclude<QueryReturnType$1, 'rows'>;
|
|
5168
|
+
} | Expression$1;
|
|
5169
|
+
interface SelectAsCheckReturnTypes {
|
|
5170
|
+
[K: string]: PropertyKey | Expression$1 | ((q: never) => SelectAsFnReturnType);
|
|
5171
|
+
}
|
|
5172
|
+
type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
|
|
5173
|
+
type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5174
|
+
type SelectResultObj<T extends SelectSelf, Obj> = Obj extends SelectAsCheckReturnTypes ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never } : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never }> : T[K] } : `Invalid return type of ${{ [K in keyof Obj]: Obj[K] extends ((...args: any[]) => any) ? ReturnType<Obj[K]> extends SelectAsFnReturnType ? never : K : never }[keyof Obj] & string}`;
|
|
5175
|
+
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
5176
|
+
{ [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5177
|
+
interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
5178
|
+
result: Column$1.QueryColumns;
|
|
5179
|
+
returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
|
|
5180
|
+
}
|
|
5181
|
+
type SelectAsSelectable<Obj> = UnionToIntersection<{ [K in keyof Obj]: Obj[K] extends ((q: never) => infer R extends AllowedRelationOneQueryForSelectable) ? { [C in R['returnType'] extends 'value' | 'valueOrThrow' ? K : keyof R['result'] as R['returnType'] extends 'value' | 'valueOrThrow' ? K : `${K & string}.${C & string}`]: {
|
|
5182
|
+
as: C;
|
|
5183
|
+
column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
|
|
5184
|
+
} } : never }[keyof Obj]>;
|
|
5185
|
+
type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery$1) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression$1) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery$1 | Expression$1) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression$1>> | Exclude<ReturnType<Arg>, IsQuery$1>['result']['value'] : never;
|
|
5186
|
+
type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape$1.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape$1.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape$1.MapToNullableObjectColumn<Arg['result']> : ColumnsShape$1.MapToObjectColumn<Arg['result']>;
|
|
5187
|
+
declare class Select {
|
|
5188
|
+
/**
|
|
5189
|
+
* Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
|
|
5190
|
+
*
|
|
5191
|
+
* The last argument can be an object. Keys of the object are column aliases, value can be a column name, sub-query, or raw SQL expression.
|
|
5192
|
+
*
|
|
5193
|
+
* ```ts
|
|
5194
|
+
* import { sql } from './baseTable'
|
|
5195
|
+
*
|
|
5196
|
+
* // select columns of the table:
|
|
5197
|
+
* db.table.select('id', 'name', { idAlias: 'id' });
|
|
5198
|
+
*
|
|
5199
|
+
* // accepts columns with table names:
|
|
5200
|
+
* db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
|
|
5201
|
+
*
|
|
5202
|
+
* // table name may refer to the current table or a joined table:
|
|
5203
|
+
* db.table
|
|
5204
|
+
* .join(db.message, 'authorId', 'user.id')
|
|
5205
|
+
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
5206
|
+
*
|
|
5207
|
+
* // select value from the sub-query,
|
|
5208
|
+
* // this sub-query should return a single record and a single column:
|
|
5209
|
+
* db.table.select({
|
|
5210
|
+
* subQueryResult: Otherdb.table.select('column').take(),
|
|
5211
|
+
* });
|
|
5212
|
+
*
|
|
5213
|
+
* // select raw SQL value, specify the returning type via <generic> syntax:
|
|
5214
|
+
* db.table.select({
|
|
5215
|
+
* raw: sql<number>`1 + 2`,
|
|
5216
|
+
* });
|
|
5217
|
+
*
|
|
5218
|
+
* // select raw SQL value, the resulting type can be set by providing a column type in such way:
|
|
5219
|
+
* db.table.select({
|
|
5220
|
+
* raw: sql`1 + 2`.type((t) => t.integer()),
|
|
5221
|
+
* });
|
|
5222
|
+
*
|
|
5223
|
+
* // same raw SQL query as above, but the sql is returned from a callback
|
|
5224
|
+
* db.table.select({
|
|
5225
|
+
* raw: () => sql`1 + 2`.type((t) => t.integer()),
|
|
5226
|
+
* });
|
|
5227
|
+
* ```
|
|
5228
|
+
*
|
|
5229
|
+
* When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
|
|
5230
|
+
*
|
|
5231
|
+
* ```ts
|
|
5232
|
+
* await db.author.select({
|
|
5233
|
+
* allBooks: (q) => q.books,
|
|
5234
|
+
* firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
|
|
5235
|
+
* booksCount: (q) => q.books.count(),
|
|
5236
|
+
* });
|
|
5237
|
+
* ```
|
|
5238
|
+
*
|
|
5239
|
+
* When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
|
|
5240
|
+
*
|
|
5241
|
+
* ```ts
|
|
5242
|
+
* // select books with their authors included, order by author name and filter by author column:
|
|
5243
|
+
* await db.books
|
|
5244
|
+
* .select({
|
|
5245
|
+
* author: (q) => q.author,
|
|
5246
|
+
* })
|
|
5247
|
+
* .order('author.name')
|
|
5248
|
+
* .where({ 'author.isPopular': true });
|
|
5249
|
+
* ```
|
|
5250
|
+
*/
|
|
5251
|
+
select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
|
|
5252
|
+
select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
5253
|
+
select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
|
|
5254
|
+
/**
|
|
5255
|
+
* When querying the table or creating records, all columns are selected by default,
|
|
5256
|
+
* but updating and deleting queries are returning affected row counts by default.
|
|
5257
|
+
*
|
|
5258
|
+
* Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
|
|
5259
|
+
*
|
|
5260
|
+
* ```ts
|
|
5261
|
+
* const selectFull = await db.table
|
|
5262
|
+
* .select('id', 'name') // discarded by `selectAll`
|
|
5263
|
+
* .selectAll();
|
|
5264
|
+
*
|
|
5265
|
+
* const updatedFull = await db.table.selectAll().where(conditions).update(data);
|
|
5266
|
+
*
|
|
5267
|
+
* const deletedFull = await db.table.selectAll().where(conditions).delete();
|
|
5268
|
+
* ```
|
|
5269
|
+
*/
|
|
5270
|
+
selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
|
|
5271
|
+
}
|
|
5272
|
+
type SelectItem = string | SelectAs | Expression$1 | undefined;
|
|
5273
|
+
interface SelectAs {
|
|
5274
|
+
selectAs: SelectAsValue;
|
|
5275
|
+
}
|
|
5276
|
+
interface SelectAsValue {
|
|
5277
|
+
[K: string]: string | Query | Expression$1 | undefined;
|
|
5278
|
+
}
|
|
5279
|
+
type QueryDataTransform = QueryDataTransformFn | {
|
|
5280
|
+
map: (record: unknown, index: number, array: unknown) => unknown;
|
|
5281
|
+
thisArg?: unknown;
|
|
5282
|
+
};
|
|
5283
|
+
interface QueryDataTransformFn {
|
|
5284
|
+
(data: unknown, queryData: unknown): unknown;
|
|
5285
|
+
}
|
|
5286
|
+
/**
|
|
5287
|
+
* See `transform` query method.
|
|
5288
|
+
* This helper applies all transform functions to a result.
|
|
5289
|
+
*
|
|
5290
|
+
* @param queryData - query data
|
|
5291
|
+
* @param returnType - return type of the query, for proper `map` handling
|
|
5292
|
+
* @param fns - array of transform functions, can be undefined
|
|
5293
|
+
* @param result - query result to transform
|
|
5294
|
+
*/
|
|
5295
|
+
declare class QueryTransform {
|
|
5296
|
+
/**
|
|
5297
|
+
* Transform the result of the query right after loading it.
|
|
5298
|
+
*
|
|
5299
|
+
* `transform` method should be called in the last order, other methods can't be chained after calling it.
|
|
5300
|
+
*
|
|
5301
|
+
* It is meant to transform the whole result of a query, for transforming individual records consider using {@link QueryMap.map}.
|
|
5302
|
+
*
|
|
5303
|
+
* The [hooks](/guide/hooks.html) that are going to run after the query will receive the query result **before** transferring.
|
|
5304
|
+
*
|
|
5305
|
+
* Consider the following example of a cursor-based pagination by `id`:
|
|
5306
|
+
*
|
|
5307
|
+
* ```ts
|
|
5308
|
+
* const lastId: number | undefined = req.query.cursor;
|
|
5309
|
+
*
|
|
5310
|
+
* type Result = {
|
|
5311
|
+
* nodes: { id: number; text: string }[];
|
|
5312
|
+
* cursor?: number;
|
|
5313
|
+
* };
|
|
5314
|
+
*
|
|
5315
|
+
* // result is only for demo, it will be inferred
|
|
5316
|
+
* const posts: Result = await db.post
|
|
5317
|
+
* .select('id', 'text')
|
|
5318
|
+
* .where({ id: { lt: lastId } })
|
|
5319
|
+
* .order({ id: 'DESC' })
|
|
5320
|
+
* .limit(100)
|
|
5321
|
+
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id }));
|
|
5322
|
+
* ```
|
|
5323
|
+
*
|
|
5324
|
+
* You can also use the `tranform` on nested sub-queries:
|
|
5325
|
+
*
|
|
5326
|
+
* ```ts
|
|
5327
|
+
* type Result = {
|
|
5328
|
+
* nodes: {
|
|
5329
|
+
* id: number;
|
|
5330
|
+
* text: string;
|
|
5331
|
+
* comments: { nodes: { id: number; text: string }[]; cursor?: number };
|
|
5332
|
+
* }[];
|
|
5333
|
+
* cursor?: number;
|
|
5334
|
+
* };
|
|
5335
|
+
*
|
|
5336
|
+
* const postsWithComments: Result = await db.post
|
|
5337
|
+
* .select('id', 'text')
|
|
5338
|
+
* .select({
|
|
5339
|
+
* comments: (q) =>
|
|
5340
|
+
* q.comments
|
|
5341
|
+
* .select('id', 'text')
|
|
5342
|
+
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id })),
|
|
5343
|
+
* })
|
|
5344
|
+
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id }));
|
|
5345
|
+
* ```
|
|
5346
|
+
*
|
|
5347
|
+
* @param fn - function to transform query result with
|
|
5348
|
+
*/
|
|
5349
|
+
transform<T extends IsQuery$1, Result>(this: T, fn: (input: T extends {
|
|
5350
|
+
then: QueryThen<infer Data>;
|
|
5351
|
+
} ? Data : never, queryData: QueryData$1) => Result): { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
5352
|
+
value: Column$1.Pick.QueryColumnOfType<Result>;
|
|
5353
|
+
} : K extends 'then' ? QueryThen<Result> : T[K] };
|
|
5354
|
+
}
|
|
5089
5355
|
type SelectableOrExpression<T extends PickQuerySelectable = PickQuerySelectable, C extends Column$1.Pick.QueryColumn = Column$1.Pick.QueryColumn> = '*' | keyof T['__selectable'] | Expression$1<C>;
|
|
5090
5356
|
type SelectableOrExpressions<T extends PickQuerySelectable = PickQuerySelectable, C extends Column$1.Pick.QueryColumn = Column$1.Pick.QueryColumn> = ('*' | keyof T['__selectable'] | Expression$1<C>)[];
|
|
5091
5357
|
type ExpressionOutput<T extends PickQuerySelectable, Expr extends SelectableOrExpression<T>> = Expr extends keyof T['__selectable'] ? T['__selectable'][Expr]['column'] : Expr extends Expression$1 ? Expr['result']['value'] : never;
|
|
@@ -5096,6 +5362,7 @@ interface ExpressionData$1 extends HasBeforeAndBeforeSet {
|
|
|
5096
5362
|
before?: QueryBeforeHook$1[];
|
|
5097
5363
|
dynamicBefore?: boolean;
|
|
5098
5364
|
getColumn?: Column$1;
|
|
5365
|
+
transform?: QueryDataTransform[];
|
|
5099
5366
|
}
|
|
5100
5367
|
declare abstract class Expression$1<T extends Column$1.Pick.QueryColumn = Column$1.Pick.QueryColumn> {
|
|
5101
5368
|
abstract result: {
|
|
@@ -5106,6 +5373,23 @@ declare abstract class Expression$1<T extends Column$1.Pick.QueryColumn = Column
|
|
|
5106
5373
|
kind: 'select';
|
|
5107
5374
|
};
|
|
5108
5375
|
toSQL(ctx: ToSqlValues$1, quotedAs?: string): string;
|
|
5376
|
+
/**
|
|
5377
|
+
* Transform the expression value after loading it.
|
|
5378
|
+
*
|
|
5379
|
+
* It is meant to transform expressions selected by a query.
|
|
5380
|
+
*
|
|
5381
|
+
* @param fn - function to transform expression value with
|
|
5382
|
+
*/
|
|
5383
|
+
transform<Self extends {
|
|
5384
|
+
result: {
|
|
5385
|
+
value: Column$1.Pick.QueryColumn;
|
|
5386
|
+
};
|
|
5387
|
+
q: ExpressionData$1;
|
|
5388
|
+
}, Result>(this: Self, fn: (input: Self['result']['value']['__type'], queryData: ExpressionData$1) => Result): Omit<Self, 'result'> & {
|
|
5389
|
+
result: {
|
|
5390
|
+
value: Column$1.Pick.QueryColumnOfType<Result>;
|
|
5391
|
+
};
|
|
5392
|
+
};
|
|
5109
5393
|
abstract makeSQL(ctx: ToSqlValues$1, quotedAs?: string): string;
|
|
5110
5394
|
}
|
|
5111
5395
|
type TemplateLiteralArgs$1 = [strings: TemplateStringsArray, ...values: unknown[]];
|
|
@@ -5650,163 +5934,6 @@ declare class FromMethods {
|
|
|
5650
5934
|
*/
|
|
5651
5935
|
only<T>(this: T, only?: boolean): T;
|
|
5652
5936
|
}
|
|
5653
|
-
interface ColumnsShape$1 {
|
|
5654
|
-
[K: string]: Column$1;
|
|
5655
|
-
}
|
|
5656
|
-
declare namespace ColumnsShape$1 {
|
|
5657
|
-
export type DefaultSelectKeys<S extends Column$1.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
|
|
5658
|
-
export type DefaultOutput<Set extends Column$1.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
|
|
5659
|
-
export type Input<Shape extends Column$1.QueryColumnsInit, AppReadOnly = { [K in keyof Shape]: Shape[K]['data']['appReadOnly'] extends true ? K : never }[keyof Shape], Optional extends keyof Shape = { [K in keyof Shape]: Shape[K]['data']['optional'] extends true ? K : never }[keyof Shape]> = { [K in Exclude<keyof Shape, AppReadOnly | Optional>]: Shape[K]['__inputType'] } & { [K in Exclude<Optional, AppReadOnly>]?: Shape[K]['__inputType'] };
|
|
5660
|
-
export type InputPartial<Shape extends Column$1.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
|
|
5661
|
-
export type Output<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5662
|
-
export type DefaultSelectOutput<Shape extends Column$1.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
|
|
5663
|
-
export interface MapToObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5664
|
-
dataType: 'object';
|
|
5665
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5666
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>;
|
|
5667
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
|
|
5668
|
-
operators: OperatorsAny;
|
|
5669
|
-
}
|
|
5670
|
-
export interface MapToNullableObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5671
|
-
dataType: 'object';
|
|
5672
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5673
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>> | undefined;
|
|
5674
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
|
|
5675
|
-
operators: OperatorsAny;
|
|
5676
|
-
}
|
|
5677
|
-
export interface MapToPluckColumn<Shape extends Column$1.QueryColumns> {
|
|
5678
|
-
dataType: 'array';
|
|
5679
|
-
__type: Shape['pluck']['__type'][];
|
|
5680
|
-
__outputType: Shape['pluck']['__outputType'][];
|
|
5681
|
-
__queryType: Shape['pluck']['__queryType'][];
|
|
5682
|
-
operators: OperatorsAny;
|
|
5683
|
-
}
|
|
5684
|
-
export interface MapToObjectArrayColumn<Shape extends Column$1.QueryColumns> {
|
|
5685
|
-
dataType: 'array';
|
|
5686
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] }[];
|
|
5687
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>[];
|
|
5688
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
|
|
5689
|
-
operators: OperatorsAny;
|
|
5690
|
-
}
|
|
5691
|
-
type ObjectOutput<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5692
|
-
export {};
|
|
5693
|
-
}
|
|
5694
|
-
interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape$1, PickQueryRelations$1, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
|
|
5695
|
-
type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
5696
|
-
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
5697
|
-
withData: T['withData'];
|
|
5698
|
-
}
|
|
5699
|
-
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject$1 extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? RelationQueryMaybeSingle<T['relations'][K]> & SubQueryAddition<T> : K extends keyof T ? T[K] : never };
|
|
5700
|
-
interface SelectAsArg<T extends SelectSelf> {
|
|
5701
|
-
[K: string]: keyof T['__selectable'] | Expression$1 | ((q: SelectAsFnArg<T>) => unknown);
|
|
5702
|
-
}
|
|
5703
|
-
type SelectAsFnReturnType = {
|
|
5704
|
-
result: Column$1.QueryColumns;
|
|
5705
|
-
returnType: Exclude<QueryReturnType$1, 'rows'>;
|
|
5706
|
-
} | Expression$1;
|
|
5707
|
-
interface SelectAsCheckReturnTypes {
|
|
5708
|
-
[K: string]: PropertyKey | Expression$1 | ((q: never) => SelectAsFnReturnType);
|
|
5709
|
-
}
|
|
5710
|
-
type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
|
|
5711
|
-
type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5712
|
-
type SelectResultObj<T extends SelectSelf, Obj> = Obj extends SelectAsCheckReturnTypes ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never } : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never }> : T[K] } : `Invalid return type of ${{ [K in keyof Obj]: Obj[K] extends ((...args: any[]) => any) ? ReturnType<Obj[K]> extends SelectAsFnReturnType ? never : K : never }[keyof Obj] & string}`;
|
|
5713
|
-
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
5714
|
-
{ [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5715
|
-
interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
5716
|
-
result: Column$1.QueryColumns;
|
|
5717
|
-
returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
|
|
5718
|
-
}
|
|
5719
|
-
type SelectAsSelectable<Obj> = UnionToIntersection<{ [K in keyof Obj]: Obj[K] extends ((q: never) => infer R extends AllowedRelationOneQueryForSelectable) ? { [C in R['returnType'] extends 'value' | 'valueOrThrow' ? K : keyof R['result'] as R['returnType'] extends 'value' | 'valueOrThrow' ? K : `${K & string}.${C & string}`]: {
|
|
5720
|
-
as: C;
|
|
5721
|
-
column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
|
|
5722
|
-
} } : never }[keyof Obj]>;
|
|
5723
|
-
type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery$1) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression$1) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery$1 | Expression$1) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression$1>> | Exclude<ReturnType<Arg>, IsQuery$1>['result']['value'] : never;
|
|
5724
|
-
type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape$1.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape$1.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape$1.MapToNullableObjectColumn<Arg['result']> : ColumnsShape$1.MapToObjectColumn<Arg['result']>;
|
|
5725
|
-
declare class Select {
|
|
5726
|
-
/**
|
|
5727
|
-
* Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
|
|
5728
|
-
*
|
|
5729
|
-
* The last argument can be an object. Keys of the object are column aliases, value can be a column name, sub-query, or raw SQL expression.
|
|
5730
|
-
*
|
|
5731
|
-
* ```ts
|
|
5732
|
-
* import { sql } from './baseTable'
|
|
5733
|
-
*
|
|
5734
|
-
* // select columns of the table:
|
|
5735
|
-
* db.table.select('id', 'name', { idAlias: 'id' });
|
|
5736
|
-
*
|
|
5737
|
-
* // accepts columns with table names:
|
|
5738
|
-
* db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
|
|
5739
|
-
*
|
|
5740
|
-
* // table name may refer to the current table or a joined table:
|
|
5741
|
-
* db.table
|
|
5742
|
-
* .join(db.message, 'authorId', 'user.id')
|
|
5743
|
-
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
5744
|
-
*
|
|
5745
|
-
* // select value from the sub-query,
|
|
5746
|
-
* // this sub-query should return a single record and a single column:
|
|
5747
|
-
* db.table.select({
|
|
5748
|
-
* subQueryResult: Otherdb.table.select('column').take(),
|
|
5749
|
-
* });
|
|
5750
|
-
*
|
|
5751
|
-
* // select raw SQL value, specify the returning type via <generic> syntax:
|
|
5752
|
-
* db.table.select({
|
|
5753
|
-
* raw: sql<number>`1 + 2`,
|
|
5754
|
-
* });
|
|
5755
|
-
*
|
|
5756
|
-
* // select raw SQL value, the resulting type can be set by providing a column type in such way:
|
|
5757
|
-
* db.table.select({
|
|
5758
|
-
* raw: sql`1 + 2`.type((t) => t.integer()),
|
|
5759
|
-
* });
|
|
5760
|
-
*
|
|
5761
|
-
* // same raw SQL query as above, but the sql is returned from a callback
|
|
5762
|
-
* db.table.select({
|
|
5763
|
-
* raw: () => sql`1 + 2`.type((t) => t.integer()),
|
|
5764
|
-
* });
|
|
5765
|
-
* ```
|
|
5766
|
-
*
|
|
5767
|
-
* When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
|
|
5768
|
-
*
|
|
5769
|
-
* ```ts
|
|
5770
|
-
* await db.author.select({
|
|
5771
|
-
* allBooks: (q) => q.books,
|
|
5772
|
-
* firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
|
|
5773
|
-
* booksCount: (q) => q.books.count(),
|
|
5774
|
-
* });
|
|
5775
|
-
* ```
|
|
5776
|
-
*
|
|
5777
|
-
* When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
|
|
5778
|
-
*
|
|
5779
|
-
* ```ts
|
|
5780
|
-
* // select books with their authors included, order by author name and filter by author column:
|
|
5781
|
-
* await db.books
|
|
5782
|
-
* .select({
|
|
5783
|
-
* author: (q) => q.author,
|
|
5784
|
-
* })
|
|
5785
|
-
* .order('author.name')
|
|
5786
|
-
* .where({ 'author.isPopular': true });
|
|
5787
|
-
* ```
|
|
5788
|
-
*/
|
|
5789
|
-
select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
|
|
5790
|
-
select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
5791
|
-
select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
|
|
5792
|
-
/**
|
|
5793
|
-
* When querying the table or creating records, all columns are selected by default,
|
|
5794
|
-
* but updating and deleting queries are returning affected row counts by default.
|
|
5795
|
-
*
|
|
5796
|
-
* Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
|
|
5797
|
-
*
|
|
5798
|
-
* ```ts
|
|
5799
|
-
* const selectFull = await db.table
|
|
5800
|
-
* .select('id', 'name') // discarded by `selectAll`
|
|
5801
|
-
* .selectAll();
|
|
5802
|
-
*
|
|
5803
|
-
* const updatedFull = await db.table.selectAll().where(conditions).update(data);
|
|
5804
|
-
*
|
|
5805
|
-
* const deletedFull = await db.table.selectAll().where(conditions).delete();
|
|
5806
|
-
* ```
|
|
5807
|
-
*/
|
|
5808
|
-
selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
|
|
5809
|
-
}
|
|
5810
5937
|
interface QueryGetSelf extends PickQuerySelectable, PickQueryRelationsWithData {}
|
|
5811
5938
|
type GetArg<T extends QueryGetSelf> = GetStringArg<T> | Expression$1 | ((q: SelectAsFnArg<T>) => Expression$1 | Query.Pick.SingleValueResult);
|
|
5812
5939
|
type GetStringArg<T extends PickQuerySelectable> = keyof T['__selectable'] & string;
|
|
@@ -6589,13 +6716,6 @@ declare class QueryOrCreate {
|
|
|
6589
6716
|
*/
|
|
6590
6717
|
orCreate<T extends UpsertThis$1>(this: T, data: OrCreateArg<CreateData$1<T>>): UpsertResult<T>;
|
|
6591
6718
|
}
|
|
6592
|
-
type SelectItem = string | SelectAs | Expression$1 | undefined;
|
|
6593
|
-
interface SelectAs {
|
|
6594
|
-
selectAs: SelectAsValue;
|
|
6595
|
-
}
|
|
6596
|
-
interface SelectAsValue {
|
|
6597
|
-
[K: string]: string | Query | Expression$1 | undefined;
|
|
6598
|
-
}
|
|
6599
6719
|
type IsolationLevel$1 = 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED' | 'READ UNCOMMITTED';
|
|
6600
6720
|
interface TransactionOptions$1 extends SqlSessionState$1 {
|
|
6601
6721
|
/**
|
|
@@ -6976,82 +7096,6 @@ type WrapQueryArg = FromQuerySelf;
|
|
|
6976
7096
|
declare class QueryWrap {
|
|
6977
7097
|
wrap<T extends IsQuery$1, Q extends WrapQueryArg, As extends string = 't'>(this: T, query: Q, as?: As): SetQueryTableAlias<Q, As>;
|
|
6978
7098
|
}
|
|
6979
|
-
type QueryDataTransform = QueryDataTransformFn | {
|
|
6980
|
-
map: (record: unknown, index: number, array: unknown) => unknown;
|
|
6981
|
-
thisArg?: unknown;
|
|
6982
|
-
};
|
|
6983
|
-
interface QueryDataTransformFn {
|
|
6984
|
-
(data: unknown, queryData: unknown): unknown;
|
|
6985
|
-
}
|
|
6986
|
-
/**
|
|
6987
|
-
* See `transform` query method.
|
|
6988
|
-
* This helper applies all transform functions to a result.
|
|
6989
|
-
*
|
|
6990
|
-
* @param queryData - query data
|
|
6991
|
-
* @param returnType - return type of the query, for proper `map` handling
|
|
6992
|
-
* @param fns - array of transform functions, can be undefined
|
|
6993
|
-
* @param result - query result to transform
|
|
6994
|
-
*/
|
|
6995
|
-
declare class QueryTransform {
|
|
6996
|
-
/**
|
|
6997
|
-
* Transform the result of the query right after loading it.
|
|
6998
|
-
*
|
|
6999
|
-
* `transform` method should be called in the last order, other methods can't be chained after calling it.
|
|
7000
|
-
*
|
|
7001
|
-
* It is meant to transform the whole result of a query, for transforming individual records consider using {@link QueryMap.map}.
|
|
7002
|
-
*
|
|
7003
|
-
* The [hooks](/guide/hooks.html) that are going to run after the query will receive the query result **before** transferring.
|
|
7004
|
-
*
|
|
7005
|
-
* Consider the following example of a cursor-based pagination by `id`:
|
|
7006
|
-
*
|
|
7007
|
-
* ```ts
|
|
7008
|
-
* const lastId: number | undefined = req.query.cursor;
|
|
7009
|
-
*
|
|
7010
|
-
* type Result = {
|
|
7011
|
-
* nodes: { id: number; text: string }[];
|
|
7012
|
-
* cursor?: number;
|
|
7013
|
-
* };
|
|
7014
|
-
*
|
|
7015
|
-
* // result is only for demo, it will be inferred
|
|
7016
|
-
* const posts: Result = await db.post
|
|
7017
|
-
* .select('id', 'text')
|
|
7018
|
-
* .where({ id: { lt: lastId } })
|
|
7019
|
-
* .order({ id: 'DESC' })
|
|
7020
|
-
* .limit(100)
|
|
7021
|
-
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id }));
|
|
7022
|
-
* ```
|
|
7023
|
-
*
|
|
7024
|
-
* You can also use the `tranform` on nested sub-queries:
|
|
7025
|
-
*
|
|
7026
|
-
* ```ts
|
|
7027
|
-
* type Result = {
|
|
7028
|
-
* nodes: {
|
|
7029
|
-
* id: number;
|
|
7030
|
-
* text: string;
|
|
7031
|
-
* comments: { nodes: { id: number; text: string }[]; cursor?: number };
|
|
7032
|
-
* }[];
|
|
7033
|
-
* cursor?: number;
|
|
7034
|
-
* };
|
|
7035
|
-
*
|
|
7036
|
-
* const postsWithComments: Result = await db.post
|
|
7037
|
-
* .select('id', 'text')
|
|
7038
|
-
* .select({
|
|
7039
|
-
* comments: (q) =>
|
|
7040
|
-
* q.comments
|
|
7041
|
-
* .select('id', 'text')
|
|
7042
|
-
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id })),
|
|
7043
|
-
* })
|
|
7044
|
-
* .transform((nodes) => ({ nodes, cursor: nodes.at(-1)?.id }));
|
|
7045
|
-
* ```
|
|
7046
|
-
*
|
|
7047
|
-
* @param fn - function to transform query result with
|
|
7048
|
-
*/
|
|
7049
|
-
transform<T extends IsQuery$1, Result>(this: T, fn: (input: T extends {
|
|
7050
|
-
then: QueryThen<infer Data>;
|
|
7051
|
-
} ? Data : never, queryData: QueryData$1) => Result): { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
7052
|
-
value: Column$1.Pick.QueryColumnOfType<Result>;
|
|
7053
|
-
} : K extends 'then' ? QueryThen<Result> : T[K] };
|
|
7054
|
-
}
|
|
7055
7099
|
type AfterHook$1<Select extends PropertyKey[], Shape extends Column$1.QueryColumns> = QueryAfterHook$1<{ [K in Select[number]]: K extends keyof Shape ? Shape[K]['__outputType'] : never }[]>;
|
|
7056
7100
|
type HookSelectArg<T extends PickQueryShape$1> = (keyof T['shape'] & string)[];
|
|
7057
7101
|
declare class QueryHookUtils$1<T extends PickQueryInputType$1> {
|
|
@@ -8231,7 +8275,7 @@ declare abstract class Column$1 {
|
|
|
8231
8275
|
data: Column['data'];
|
|
8232
8276
|
dataType: string;
|
|
8233
8277
|
}>(this: T, ...args: [options?: TableData$1.Index.TsVectorColumnArg]): T;
|
|
8234
|
-
unique<T extends Column.Pick.Data, const Options extends TableData$1.Index.
|
|
8278
|
+
unique<T extends Column.Pick.Data, const Options extends TableData$1.Index.UniqueColumnArg>(this: T, ...args: [options?: Options]): T & Column.Modifiers.IsUnique<Options['name'] & string>;
|
|
8235
8279
|
/**
|
|
8236
8280
|
* Add [EXCLUDE constraint](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE) to the column.
|
|
8237
8281
|
*
|