pqb 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1239 -1342
- package/dist/index.esm.js +482 -432
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +484 -434
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/columnType.test.ts +2 -1
- package/src/columnSchema/columnsSchema.ts +20 -60
- package/src/db.test.ts +1 -1
- package/src/db.ts +27 -20
- package/src/query.ts +36 -32
- package/src/queryDataUtils.ts +0 -7
- package/src/queryMethods/aggregate.ts +2 -3
- package/src/queryMethods/clear.ts +3 -4
- package/src/queryMethods/delete.ts +3 -3
- package/src/queryMethods/from.test.ts +2 -3
- package/src/queryMethods/get.ts +0 -1
- package/src/queryMethods/index.ts +1 -0
- package/src/queryMethods/insert.ts +14 -13
- package/src/queryMethods/json.ts +7 -3
- package/src/queryMethods/merge.test.ts +471 -0
- package/src/queryMethods/merge.ts +67 -0
- package/src/queryMethods/queryMethods.test.ts +14 -59
- package/src/queryMethods/queryMethods.ts +18 -33
- package/src/queryMethods/select.test.ts +4 -0
- package/src/queryMethods/select.ts +4 -2
- package/src/queryMethods/then.ts +3 -3
- package/src/queryMethods/update.ts +21 -14
- package/src/sql/fromAndAs.ts +2 -3
- package/src/sql/select.ts +1 -2
- package/src/sql/toSql.ts +4 -3
- package/src/sql/types.ts +7 -3
- package/src/sql/window.ts +1 -1
- package/src/sql/with.ts +25 -20
- package/src/utils.test.ts +0 -18
- package/src/utils.ts +0 -40
- package/src/columnSchema/columnsSchema.test.ts +0 -32
package/dist/index.d.ts
CHANGED
|
@@ -22,343 +22,201 @@ declare const getRawSql: (raw: RawExpression) => string;
|
|
|
22
22
|
declare const EMPTY_OBJECT: {};
|
|
23
23
|
declare const getQueryParsers: (q: Query) => ColumnsParsers | undefined;
|
|
24
24
|
|
|
25
|
-
declare type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
]
|
|
51
|
-
declare type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
25
|
+
declare type NestedInsertOneItem = {
|
|
26
|
+
create?: Record<string, unknown>;
|
|
27
|
+
connect?: WhereArg<QueryBase>;
|
|
28
|
+
connectOrCreate?: {
|
|
29
|
+
where: WhereArg<QueryBase>;
|
|
30
|
+
create: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
declare type NestedInsertManyItems = {
|
|
34
|
+
create?: Record<string, unknown>[];
|
|
35
|
+
connect?: WhereArg<QueryBase>[];
|
|
36
|
+
connectOrCreate?: {
|
|
37
|
+
where: WhereArg<QueryBase>;
|
|
38
|
+
create: Record<string, unknown>;
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
declare type NestedInsertItem = NestedInsertOneItem | NestedInsertManyItems;
|
|
42
|
+
declare type BelongsToNestedInsert = (query: Query, relationData: NestedInsertOneItem[]) => Promise<Record<string, unknown>[]>;
|
|
43
|
+
declare type HasOneNestedInsert = (query: Query, data: [
|
|
44
|
+
selfData: Record<string, unknown>,
|
|
45
|
+
relationData: NestedInsertOneItem
|
|
46
|
+
][]) => Promise<void>;
|
|
47
|
+
declare type HasManyNestedInsert = (query: Query, data: [
|
|
48
|
+
selfData: Record<string, unknown>,
|
|
49
|
+
relationData: NestedInsertManyItems
|
|
50
|
+
][]) => Promise<void>;
|
|
51
|
+
declare type NestedUpdateOneItem = {
|
|
52
|
+
disconnect?: boolean;
|
|
53
|
+
set?: WhereArg<QueryBase>;
|
|
54
|
+
delete?: boolean;
|
|
55
|
+
update?: UpdateData<Query>;
|
|
56
|
+
upsert?: {
|
|
57
|
+
update: UpdateData<Query>;
|
|
58
|
+
create: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
create: Record<string, unknown>;
|
|
61
|
+
};
|
|
62
|
+
declare type NestedUpdateManyItems = {
|
|
63
|
+
disconnect?: MaybeArray<WhereArg<QueryBase>>;
|
|
64
|
+
set?: MaybeArray<WhereArg<QueryBase>>;
|
|
65
|
+
delete?: MaybeArray<WhereArg<QueryBase>>;
|
|
66
|
+
update?: {
|
|
67
|
+
where: MaybeArray<WhereArg<QueryBase>>;
|
|
68
|
+
data: UpdateData<Query>;
|
|
69
|
+
};
|
|
70
|
+
create: Record<string, unknown>[];
|
|
71
|
+
};
|
|
72
|
+
declare type NestedUpdateItem = NestedUpdateOneItem | NestedUpdateManyItems;
|
|
73
|
+
declare type BelongsToNestedUpdate = (q: Query, update: Record<string, unknown>, params: NestedUpdateOneItem, state: {
|
|
74
|
+
updateLater?: Record<string, unknown>;
|
|
75
|
+
updateLaterPromises?: Promise<void>[];
|
|
76
|
+
}) => boolean;
|
|
77
|
+
declare type HasOneNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateOneItem) => Promise<void>;
|
|
78
|
+
declare type HasManyNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateManyItems) => Promise<void>;
|
|
79
|
+
declare type BaseRelation = {
|
|
80
|
+
type: string;
|
|
81
|
+
key: string;
|
|
82
|
+
model: QueryWithTable;
|
|
83
|
+
query: QueryWithTable;
|
|
84
|
+
joinQuery(fromQuery: QueryBase, toQuery: Query): Query;
|
|
85
|
+
nestedCreateQuery: Query;
|
|
86
|
+
nestedInsert?: BelongsToNestedInsert | HasOneNestedInsert | HasManyNestedInsert;
|
|
87
|
+
nestedUpdate?: BelongsToNestedUpdate | HasOneNestedUpdate | HasManyNestedUpdate;
|
|
88
|
+
primaryKey: string;
|
|
89
|
+
options: {
|
|
90
|
+
scope?(q: QueryWithTable): QueryWithTable;
|
|
91
|
+
required?: boolean;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
interface BelongsToRelation extends BaseRelation {
|
|
95
|
+
type: 'belongsTo';
|
|
96
|
+
returns: 'one';
|
|
97
|
+
options: BaseRelation['options'] & {
|
|
98
|
+
primaryKey: string;
|
|
99
|
+
foreignKey: string;
|
|
67
100
|
};
|
|
68
|
-
shape: T['withData'][Arg]['shape'];
|
|
69
|
-
__model: Query;
|
|
70
|
-
relations: RelationsBase;
|
|
71
|
-
withData: WithDataBase;
|
|
72
|
-
} : never : Arg extends Query ? Arg : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['model'] : never : never>) => OnQueryBuilder;
|
|
73
|
-
declare type JoinCallbackResult<T extends Query, Arg extends JoinCallbackArg<T>> = AddQueryJoinedTable<T, Arg extends Query ? Arg : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['model'] : Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? {
|
|
74
|
-
table: T['withData'][Arg]['table'];
|
|
75
|
-
tableAlias: undefined;
|
|
76
|
-
result: T['withData'][Arg]['shape'];
|
|
77
|
-
} : never : never : never>;
|
|
78
|
-
declare class Join {
|
|
79
|
-
join<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
80
|
-
join<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
81
|
-
_join<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
82
|
-
_join<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
83
|
-
innerJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
84
|
-
innerJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
85
|
-
_innerJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
86
|
-
_innerJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
87
|
-
leftJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
88
|
-
leftJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
89
|
-
_leftJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
90
|
-
_leftJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
91
|
-
leftOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
92
|
-
leftOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
93
|
-
_leftOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
94
|
-
_leftOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
95
|
-
rightJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
96
|
-
rightJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
97
|
-
_rightJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
98
|
-
_rightJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
99
|
-
rightOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
100
|
-
rightOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
101
|
-
_rightOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
102
|
-
_rightOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
103
|
-
fullOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
104
|
-
fullOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
105
|
-
_fullOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
106
|
-
_fullOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
107
101
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
constructor(q: QueryBase | string, shape: ColumnsShape, joinTo: QueryBase);
|
|
130
|
-
on<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
131
|
-
_on<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
132
|
-
orOn<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
133
|
-
_orOn<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
134
|
-
onJsonPathEquals<T extends this>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
|
|
135
|
-
_onJsonPathEquals<T extends this>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
|
|
102
|
+
interface HasOneRelation extends BaseRelation {
|
|
103
|
+
type: 'hasOne';
|
|
104
|
+
returns: 'one';
|
|
105
|
+
options: BaseRelation['options'] & ({
|
|
106
|
+
primaryKey: string;
|
|
107
|
+
foreignKey: string;
|
|
108
|
+
} | {
|
|
109
|
+
through: string;
|
|
110
|
+
source: string;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
interface HasManyRelation extends BaseRelation {
|
|
114
|
+
type: 'hasMany';
|
|
115
|
+
returns: 'many';
|
|
116
|
+
options: BaseRelation['options'] & ({
|
|
117
|
+
primaryKey: string;
|
|
118
|
+
foreignKey: string;
|
|
119
|
+
} | {
|
|
120
|
+
through: string;
|
|
121
|
+
source: string;
|
|
122
|
+
});
|
|
136
123
|
}
|
|
124
|
+
interface HasAndBelongsToManyRelation extends BaseRelation {
|
|
125
|
+
type: 'hasAndBelongsToMany';
|
|
126
|
+
returns: 'many';
|
|
127
|
+
options: BaseRelation['options'] & {
|
|
128
|
+
primaryKey: string;
|
|
129
|
+
foreignKey: string;
|
|
130
|
+
associationPrimaryKey: string;
|
|
131
|
+
associationForeignKey: string;
|
|
132
|
+
joinTable: string;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
declare type Relation = BelongsToRelation | HasOneRelation | HasManyRelation | HasAndBelongsToManyRelation;
|
|
136
|
+
declare type RelationsBase = Record<never, Relation>;
|
|
137
|
+
declare type relationQueryKey = typeof relationQueryKey;
|
|
138
|
+
declare const relationQueryKey: unique symbol;
|
|
139
|
+
declare type isRequiredRelationKey = typeof isRequiredRelationKey;
|
|
140
|
+
declare const isRequiredRelationKey: unique symbol;
|
|
141
|
+
declare type RelationQueryBase = Query & {
|
|
142
|
+
[relationQueryKey]: string;
|
|
143
|
+
[isRequiredRelationKey]: boolean;
|
|
144
|
+
};
|
|
145
|
+
declare type RelationQuery<RelationName extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, Q extends RelationQueryBase = Omit<T, 'tableAlias'> & {
|
|
146
|
+
tableAlias: RelationName extends string ? RelationName : never;
|
|
147
|
+
[isRequiredRelationKey]: Required;
|
|
148
|
+
[relationQueryKey]: string;
|
|
149
|
+
}> = ((params: Params) => Q & {
|
|
150
|
+
[defaultsKey]: Record<Populate, true>;
|
|
151
|
+
}) & Q;
|
|
137
152
|
|
|
138
|
-
|
|
139
|
-
[
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
values: unknown[][] | Query | RawExpression;
|
|
146
|
-
}>;
|
|
147
|
-
EXISTS?: MaybeArray<JoinArgs<T> | JoinCallbackArg<T>>;
|
|
148
|
-
}) | QueryBase | RawExpression | ((q: WhereQueryBuilder<T>) => WhereQueryBuilder);
|
|
149
|
-
declare type WhereInColumn<T extends QueryBase> = keyof T['selectable'] | [keyof T['selectable'], ...(keyof T['selectable'])[]];
|
|
150
|
-
declare type WhereInValues<T extends QueryBase, Column extends WhereInColumn<T>> = Column extends keyof T['selectable'] ? T['selectable'][Column]['column']['type'][] | Query | RawExpression : ({
|
|
151
|
-
[I in keyof Column]: Column[I] extends keyof T['selectable'] ? T['selectable'][Column[I]]['column']['type'] : never;
|
|
152
|
-
} & {
|
|
153
|
-
length: Column extends {
|
|
154
|
-
length: number;
|
|
155
|
-
} ? Column['length'] : never;
|
|
156
|
-
})[] | Query | RawExpression;
|
|
157
|
-
declare type WhereResult<T extends QueryBase> = T & {
|
|
158
|
-
hasWhere: true;
|
|
153
|
+
interface QueryResultRow {
|
|
154
|
+
[column: string]: any;
|
|
155
|
+
}
|
|
156
|
+
declare type TypeParsers = Record<number, (input: string) => unknown>;
|
|
157
|
+
declare type QueryInput = string | {
|
|
158
|
+
text: string;
|
|
159
|
+
values?: unknown[];
|
|
159
160
|
};
|
|
160
|
-
declare type
|
|
161
|
-
|
|
161
|
+
declare type QueryResult<T extends QueryResultRow = any> = {
|
|
162
|
+
rowCount: number;
|
|
163
|
+
rows: T[];
|
|
162
164
|
};
|
|
163
|
-
declare
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
_whereNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
182
|
-
and<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
183
|
-
_and<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
184
|
-
andNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
185
|
-
_andNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
186
|
-
or<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
187
|
-
_or<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
188
|
-
orNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
189
|
-
_orNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
190
|
-
whereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): T;
|
|
191
|
-
whereIn<T extends Where>(this: T, arg: WhereInArg<T>): T;
|
|
192
|
-
_whereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
193
|
-
_whereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
194
|
-
orWhereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
195
|
-
orWhereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
196
|
-
_orWhereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
197
|
-
_orWhereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
198
|
-
whereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
199
|
-
whereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
200
|
-
_whereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
201
|
-
_whereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
202
|
-
orWhereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
203
|
-
orWhereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
204
|
-
_orWhereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
205
|
-
_orWhereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
206
|
-
whereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
207
|
-
whereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
208
|
-
_whereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
209
|
-
_whereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
210
|
-
orWhereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
211
|
-
orWhereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
212
|
-
_orWhereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
213
|
-
_orWhereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
214
|
-
whereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
215
|
-
whereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
216
|
-
_whereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
217
|
-
_whereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
218
|
-
orWhereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
219
|
-
orWhereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
220
|
-
_orWhereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
221
|
-
_orWhereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
222
|
-
}
|
|
223
|
-
declare class WhereQueryBuilder<Q extends QueryBase = QueryBase> extends Where implements QueryBase {
|
|
224
|
-
query: QueryData;
|
|
225
|
-
selectable: Q['selectable'];
|
|
226
|
-
shape: Q['shape'];
|
|
227
|
-
relations: Q['relations'];
|
|
228
|
-
__model: Query;
|
|
229
|
-
withData: {};
|
|
230
|
-
constructor(q: QueryBase | string, shape: ColumnsShape);
|
|
231
|
-
clone<T extends this>(this: T): T;
|
|
165
|
+
declare type QueryArraysResult<R extends any[] = any[]> = {
|
|
166
|
+
rowCount: number;
|
|
167
|
+
rows: R[];
|
|
168
|
+
fields: {
|
|
169
|
+
name: string;
|
|
170
|
+
}[];
|
|
171
|
+
};
|
|
172
|
+
declare type AdapterOptions = Omit<PoolConfig, 'types'> & {
|
|
173
|
+
types?: TypeParsers;
|
|
174
|
+
};
|
|
175
|
+
declare class Adapter {
|
|
176
|
+
types: TypeParsers;
|
|
177
|
+
pool: Pool;
|
|
178
|
+
constructor({ types, ...config }: AdapterOptions);
|
|
179
|
+
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
180
|
+
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
181
|
+
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
182
|
+
close(): Promise<void>;
|
|
232
183
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
184
|
+
declare class TransactionAdapter implements Adapter {
|
|
185
|
+
pool: Pool;
|
|
186
|
+
client: PoolClient;
|
|
187
|
+
types: TypeParsers;
|
|
188
|
+
constructor(pool: Pool, client: PoolClient, types: TypeParsers);
|
|
189
|
+
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
190
|
+
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
191
|
+
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
192
|
+
close(): Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare type QueryLogObject = {
|
|
196
|
+
colors: boolean;
|
|
197
|
+
beforeQuery(sql: Sql): unknown;
|
|
198
|
+
afterQuery(sql: Sql, logData: unknown): void;
|
|
199
|
+
onError(error: Error, sql: Sql, logData: unknown): void;
|
|
243
200
|
};
|
|
244
|
-
declare type
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
min: Expression<T, C>;
|
|
248
|
-
max: Expression<T, C>;
|
|
249
|
-
sum: NumberExpression<T, C>;
|
|
250
|
-
bitAnd: NumberExpression<T, C>;
|
|
251
|
-
bitOr: NumberExpression<T, C>;
|
|
252
|
-
boolAnd: BooleanExpression<T, C>;
|
|
253
|
-
boolOr: BooleanExpression<T, C>;
|
|
254
|
-
every: BooleanExpression<T, C>;
|
|
255
|
-
jsonAgg: Expression<T, C>;
|
|
256
|
-
jsonbAgg: Expression<T, C>;
|
|
257
|
-
xmlAgg: Expression<T, C>;
|
|
201
|
+
declare type QueryLogger = {
|
|
202
|
+
log(message: string): void;
|
|
203
|
+
error(message: string): void;
|
|
258
204
|
};
|
|
259
|
-
declare
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
readonly min: "min";
|
|
263
|
-
readonly max: "max";
|
|
264
|
-
readonly sum: "sum";
|
|
265
|
-
readonly bitAnd: "bit_and";
|
|
266
|
-
readonly bitOr: "bit_or";
|
|
267
|
-
readonly boolAnd: "bool_and";
|
|
268
|
-
readonly boolOr: "bool_or";
|
|
269
|
-
readonly every: "every";
|
|
270
|
-
readonly jsonAgg: "json_agg";
|
|
271
|
-
readonly jsonbAgg: "jsonb_agg";
|
|
272
|
-
readonly xmlAgg: "xmlagg";
|
|
205
|
+
declare type QueryLogOptions = {
|
|
206
|
+
log?: boolean | Partial<QueryLogObject>;
|
|
207
|
+
logger?: QueryLogger;
|
|
273
208
|
};
|
|
274
|
-
declare
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
_selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
286
|
-
avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
287
|
-
_avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
288
|
-
selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
289
|
-
_selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
290
|
-
min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
291
|
-
_min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
292
|
-
selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
293
|
-
_selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
294
|
-
max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
295
|
-
_max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
296
|
-
selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
297
|
-
_selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
298
|
-
sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
299
|
-
_sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
300
|
-
selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
301
|
-
_selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
302
|
-
bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
303
|
-
_bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
304
|
-
selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
305
|
-
_selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
306
|
-
bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
307
|
-
_bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
308
|
-
selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
309
|
-
_selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
310
|
-
boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
311
|
-
_boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
312
|
-
selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
313
|
-
_selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
314
|
-
boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
315
|
-
_boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
316
|
-
selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
317
|
-
_selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
318
|
-
every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
319
|
-
_every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
320
|
-
selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
321
|
-
_selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
322
|
-
jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
323
|
-
_jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
324
|
-
selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
325
|
-
_selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
326
|
-
jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
327
|
-
_jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
328
|
-
selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
329
|
-
_selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
330
|
-
xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
331
|
-
_xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
332
|
-
selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
333
|
-
_selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
334
|
-
jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
335
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
336
|
-
}>>>;
|
|
337
|
-
_jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
338
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
339
|
-
}>>>;
|
|
340
|
-
selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
341
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
342
|
-
}>>>;
|
|
343
|
-
_selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
344
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
345
|
-
}>>>;
|
|
346
|
-
jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
347
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
348
|
-
}>>>;
|
|
349
|
-
_jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
350
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
351
|
-
}>>>;
|
|
352
|
-
selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
353
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
354
|
-
}>>>;
|
|
355
|
-
_selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
356
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
357
|
-
}>>>;
|
|
358
|
-
stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
359
|
-
_stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
360
|
-
selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
361
|
-
_selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
209
|
+
declare const logColors: {
|
|
210
|
+
boldCyanBright: (message: string) => string;
|
|
211
|
+
boldBlue: (message: string) => string;
|
|
212
|
+
boldYellow: (message: string) => string;
|
|
213
|
+
boldMagenta: (message: string) => string;
|
|
214
|
+
boldRed: (message: string) => string;
|
|
215
|
+
};
|
|
216
|
+
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions['log']) => QueryLogObject | undefined;
|
|
217
|
+
declare class QueryLog {
|
|
218
|
+
log<T extends Query>(this: T, log?: boolean): T;
|
|
219
|
+
_log<T extends Query>(this: T, log?: boolean): T;
|
|
362
220
|
}
|
|
363
221
|
|
|
364
222
|
declare type BeforeCallback<T extends Query = Query> = (query: T) => void | Promise<void>;
|
|
@@ -382,267 +240,333 @@ declare class QueryCallbacks {
|
|
|
382
240
|
_afterDelete<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
383
241
|
}
|
|
384
242
|
|
|
385
|
-
declare type
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
243
|
+
declare type Sql = {
|
|
244
|
+
text: string;
|
|
245
|
+
values: unknown[];
|
|
246
|
+
};
|
|
247
|
+
declare const checkIfASimpleQuery: (q: QueryData) => boolean;
|
|
248
|
+
declare type CommonQueryData = {
|
|
249
|
+
adapter: Adapter;
|
|
250
|
+
handleResult(q: Query, result: QueryResult): Promise<unknown>;
|
|
251
|
+
returnType: QueryReturnType;
|
|
252
|
+
[relationQueryKey]?: string;
|
|
253
|
+
inTransaction?: boolean;
|
|
254
|
+
wrapInTransaction?: boolean;
|
|
255
|
+
throwOnNotFound?: boolean;
|
|
256
|
+
with?: WithItem[];
|
|
257
|
+
withShapes?: Record<string, ColumnsShape>;
|
|
258
|
+
schema?: string;
|
|
259
|
+
select?: SelectItem[];
|
|
260
|
+
as?: string;
|
|
261
|
+
from?: string | Query | RawExpression;
|
|
262
|
+
and?: WhereItem[];
|
|
263
|
+
or?: WhereItem[][];
|
|
264
|
+
coalesceValue?: unknown | RawExpression;
|
|
265
|
+
parsers?: ColumnsParsers;
|
|
266
|
+
notFoundDefault?: unknown;
|
|
267
|
+
defaults?: Record<string, unknown>;
|
|
268
|
+
beforeQuery?: BeforeCallback[];
|
|
269
|
+
afterQuery?: AfterCallback[];
|
|
270
|
+
log?: QueryLogObject;
|
|
271
|
+
logger: QueryLogger;
|
|
272
|
+
[toSqlCacheKey]?: Sql;
|
|
273
|
+
};
|
|
274
|
+
declare type SelectQueryData = CommonQueryData & {
|
|
275
|
+
type: undefined;
|
|
276
|
+
distinct?: Expression[];
|
|
277
|
+
fromOnly?: boolean;
|
|
278
|
+
join?: JoinItem[];
|
|
279
|
+
joinedParsers?: Record<string, ColumnsParsers>;
|
|
280
|
+
group?: (string | RawExpression)[];
|
|
281
|
+
having?: HavingItem[];
|
|
282
|
+
havingOr?: HavingItem[][];
|
|
283
|
+
window?: WindowItem[];
|
|
284
|
+
union?: {
|
|
285
|
+
arg: UnionItem;
|
|
286
|
+
kind: UnionKind;
|
|
287
|
+
wrap?: boolean;
|
|
288
|
+
}[];
|
|
289
|
+
order?: OrderItem[];
|
|
290
|
+
limit?: number;
|
|
291
|
+
offset?: number;
|
|
292
|
+
for?: {
|
|
293
|
+
type: 'UPDATE' | 'NO KEY UPDATE' | 'SHARE' | 'KEY SHARE';
|
|
294
|
+
tableNames?: string[] | RawExpression;
|
|
295
|
+
mode?: 'NO WAIT' | 'SKIP LOCKED';
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
declare type InsertQueryData = CommonQueryData & {
|
|
299
|
+
type: 'insert';
|
|
300
|
+
columns: string[];
|
|
301
|
+
values: unknown[][] | RawExpression;
|
|
302
|
+
using?: JoinItem[];
|
|
303
|
+
join?: JoinItem[];
|
|
304
|
+
joinedParsers?: Record<string, ColumnsParsers>;
|
|
305
|
+
onConflict?: {
|
|
306
|
+
type: 'ignore';
|
|
307
|
+
expr?: OnConflictItem;
|
|
308
|
+
} | {
|
|
309
|
+
type: 'merge';
|
|
310
|
+
expr?: OnConflictItem;
|
|
311
|
+
update?: OnConflictMergeUpdate;
|
|
312
|
+
};
|
|
313
|
+
beforeInsert?: BeforeCallback[];
|
|
314
|
+
afterInsert?: AfterCallback[];
|
|
315
|
+
};
|
|
316
|
+
declare type UpdateQueryDataObject = Record<string, RawExpression | {
|
|
317
|
+
op: string;
|
|
318
|
+
arg: unknown;
|
|
319
|
+
} | unknown>;
|
|
320
|
+
declare type UpdatedAtDataInjector = (data: UpdateQueryDataItem[]) => UpdateQueryDataItem | void;
|
|
321
|
+
declare type UpdateQueryDataItem = UpdateQueryDataObject | RawExpression | UpdatedAtDataInjector;
|
|
322
|
+
declare type UpdateQueryData = CommonQueryData & {
|
|
323
|
+
type: 'update';
|
|
324
|
+
updateData: UpdateQueryDataItem[];
|
|
325
|
+
beforeUpdate?: BeforeCallback[];
|
|
326
|
+
afterUpdate?: AfterCallback[];
|
|
327
|
+
};
|
|
328
|
+
declare type DeleteQueryData = CommonQueryData & {
|
|
329
|
+
type: 'delete';
|
|
330
|
+
join?: JoinItem[];
|
|
331
|
+
joinedParsers?: Record<string, ColumnsParsers>;
|
|
332
|
+
beforeDelete?: BeforeCallback[];
|
|
333
|
+
afterDelete?: AfterCallback[];
|
|
334
|
+
};
|
|
335
|
+
declare type TruncateQueryData = CommonQueryData & {
|
|
336
|
+
type: 'truncate';
|
|
337
|
+
restartIdentity?: boolean;
|
|
338
|
+
cascade?: boolean;
|
|
339
|
+
};
|
|
340
|
+
declare type ColumnInfoQueryData = CommonQueryData & {
|
|
341
|
+
type: 'columnInfo';
|
|
342
|
+
column?: string;
|
|
343
|
+
};
|
|
344
|
+
declare type QueryData = SelectQueryData | InsertQueryData | UpdateQueryData | DeleteQueryData | TruncateQueryData | ColumnInfoQueryData;
|
|
345
|
+
declare type WithItem = [
|
|
346
|
+
as: string,
|
|
347
|
+
options: WithOptions,
|
|
348
|
+
query: Query | RawExpression
|
|
349
|
+
];
|
|
350
|
+
declare type WithOptions = {
|
|
351
|
+
columns?: string[];
|
|
352
|
+
recursive?: true;
|
|
353
|
+
materialized?: true;
|
|
354
|
+
notMaterialized?: true;
|
|
355
|
+
};
|
|
356
|
+
declare type JsonItem<As extends string = string, Type extends ColumnType = ColumnType> = {
|
|
357
|
+
__json: [
|
|
358
|
+
kind: 'set',
|
|
359
|
+
as: As,
|
|
360
|
+
type: Type,
|
|
361
|
+
column: string | JsonItem,
|
|
362
|
+
path: Array<string | number>,
|
|
363
|
+
value: unknown,
|
|
364
|
+
options?: {
|
|
365
|
+
createIfMissing?: boolean;
|
|
366
|
+
}
|
|
367
|
+
] | [
|
|
368
|
+
kind: 'insert',
|
|
369
|
+
as: As,
|
|
370
|
+
type: Type,
|
|
371
|
+
column: string | JsonItem,
|
|
372
|
+
path: Array<string | number>,
|
|
373
|
+
value: unknown,
|
|
374
|
+
options?: {
|
|
375
|
+
insertAfter?: boolean;
|
|
376
|
+
}
|
|
377
|
+
] | [
|
|
378
|
+
kind: 'remove',
|
|
379
|
+
as: As,
|
|
380
|
+
type: Type,
|
|
381
|
+
column: string | JsonItem,
|
|
382
|
+
path: Array<string | number>
|
|
383
|
+
] | [
|
|
384
|
+
kind: 'pathQuery',
|
|
385
|
+
as: As,
|
|
386
|
+
type: Type,
|
|
387
|
+
column: string | JsonItem,
|
|
388
|
+
path: string,
|
|
389
|
+
options?: {
|
|
390
|
+
vars?: string;
|
|
391
|
+
silent?: boolean;
|
|
392
|
+
}
|
|
393
|
+
];
|
|
394
|
+
};
|
|
395
|
+
declare type SelectItem = string | RelationQuery | AggregateItem | {
|
|
396
|
+
selectAs: Record<string, string | Query | RawExpression>;
|
|
397
|
+
} | SelectFunctionItem | JsonItem | RawExpression;
|
|
398
|
+
declare type SelectFunctionItem = {
|
|
399
|
+
function: string;
|
|
400
|
+
arguments: SelectItem[];
|
|
401
|
+
as?: string;
|
|
402
|
+
};
|
|
403
|
+
declare type JoinItem = {
|
|
393
404
|
type: string;
|
|
394
|
-
|
|
395
|
-
|
|
405
|
+
args: [relation: string] | [
|
|
406
|
+
arg: string | QueryWithTable,
|
|
407
|
+
conditions: Record<string, string | RawExpression> | RawExpression | ((q: unknown) => QueryBase)
|
|
408
|
+
] | [
|
|
409
|
+
arg: string | QueryWithTable,
|
|
410
|
+
leftColumn: string | RawExpression,
|
|
411
|
+
rightColumn: string | RawExpression
|
|
412
|
+
] | [
|
|
413
|
+
arg: string | QueryWithTable,
|
|
414
|
+
leftColumn: string | RawExpression,
|
|
415
|
+
op: string,
|
|
416
|
+
rightColumn: string | RawExpression
|
|
417
|
+
];
|
|
396
418
|
};
|
|
397
|
-
declare
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
_delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
declare type ForQueryBuilder<Q extends Query> = Q & {
|
|
412
|
-
noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
413
|
-
_noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
414
|
-
skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
415
|
-
_skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
419
|
+
declare type WhereItem = (Omit<Record<string, unknown | Record<string, unknown | Query | RawExpression> | RawExpression>, 'NOT' | 'AND' | 'OR' | 'IN' | 'EXISTS' | 'ON' | 'ON_JSON_PATH_EQUALS'> & {
|
|
420
|
+
NOT?: MaybeArray<WhereItem>;
|
|
421
|
+
AND?: MaybeArray<WhereItem>;
|
|
422
|
+
OR?: MaybeArray<WhereItem>[];
|
|
423
|
+
IN?: MaybeArray<WhereInItem>;
|
|
424
|
+
EXISTS?: MaybeArray<JoinItem['args']>;
|
|
425
|
+
ON?: WhereOnItem | WhereJsonPathEqualsItem;
|
|
426
|
+
}) | ((q: unknown) => QueryBase) | Query | RawExpression;
|
|
427
|
+
declare type WhereInItem = {
|
|
428
|
+
columns: string[];
|
|
429
|
+
values: unknown[][] | Query | RawExpression;
|
|
416
430
|
};
|
|
417
|
-
declare
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
423
|
-
_forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
424
|
-
forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
425
|
-
_forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
declare type FromArgs<T extends Query> = [
|
|
429
|
-
first: string | Query | RawExpression | Exclude<keyof T['withData'], symbol | number>,
|
|
430
|
-
second?: string | {
|
|
431
|
-
as?: string;
|
|
432
|
-
only?: boolean;
|
|
433
|
-
}
|
|
431
|
+
declare type WhereJsonPathEqualsItem = [
|
|
432
|
+
leftColumn: string,
|
|
433
|
+
leftPath: string,
|
|
434
|
+
rightColumn: string,
|
|
435
|
+
rightPath: string
|
|
434
436
|
];
|
|
435
|
-
declare type
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
440
|
-
_from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
declare type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
444
|
-
declare type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
445
|
-
declare type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
446
|
-
declare type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
447
|
-
declare type getValueKey = typeof getValueKey;
|
|
448
|
-
declare const getValueKey: unique symbol;
|
|
449
|
-
declare class QueryGet {
|
|
450
|
-
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
451
|
-
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
452
|
-
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
453
|
-
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
declare type HavingArgObject<T extends Query, Agg extends keyof Aggregate1ArgumentTypes<T>> = {
|
|
457
|
-
[Column in Exclude<Aggregate1ArgumentTypes<T>[Agg], RawExpression>]?: T['selectable'][Column]['column']['type'] | (ColumnOperators<T['selectable'], Column> & AggregateOptions<T>);
|
|
437
|
+
declare type WhereOnItem = {
|
|
438
|
+
joinFrom: WhereOnJoinItem;
|
|
439
|
+
joinTo: WhereOnJoinItem;
|
|
440
|
+
on: [leftFullColumn: string, rightFullColumn: string] | [leftFullColumn: string, op: string, rightFullColumn: string];
|
|
458
441
|
};
|
|
459
|
-
declare type
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}) | Query | RawExpression;
|
|
464
|
-
declare class Having {
|
|
465
|
-
having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
466
|
-
_having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
467
|
-
havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
468
|
-
_havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
declare type InsertData<T extends Query, DefaultKeys extends PropertyKey = keyof T[defaultsKey], Data = SetOptional<T['inputType'], DefaultKeys>> = [keyof T['relations']] extends [never] ? Data : OmitBelongsToForeignKeys<T['relations'], Data> & InsertRelationData<T>;
|
|
472
|
-
declare type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<Data, {
|
|
473
|
-
[K in keyof R]: R[K] extends BelongsToRelation ? R[K]['options']['foreignKey'] : never;
|
|
474
|
-
}[keyof R]>;
|
|
475
|
-
declare type InsertRelationData<T extends Query> = {
|
|
476
|
-
[K in keyof T['relations']]: T['relations'][K] extends BelongsToRelation ? InsertBelongsToData<T, K, T['relations'][K]> : T['relations'][K] extends HasOneRelation ? InsertHasOneData<T, K, T['relations'][K]> : T['relations'][K] extends HasManyRelation | HasAndBelongsToManyRelation ? InsertHasManyData<T, K, T['relations'][K]> : EmptyObject;
|
|
477
|
-
}[keyof T['relations']];
|
|
478
|
-
declare type InsertBelongsToData<T extends Query, Key extends keyof T['relations'], Rel extends BelongsToRelation> = SetOptional<{
|
|
479
|
-
[K in Rel['options']['foreignKey']]: Rel['options']['foreignKey'] extends keyof T['inputType'] ? T['inputType'][Rel['options']['foreignKey']] : never;
|
|
480
|
-
}, keyof T[defaultsKey]> | {
|
|
481
|
-
[K in Key]: {
|
|
482
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
483
|
-
connect?: never;
|
|
484
|
-
connectOrCreate?: never;
|
|
485
|
-
} | {
|
|
486
|
-
create?: never;
|
|
487
|
-
connect: WhereArg<Rel['model']>;
|
|
488
|
-
connectOrCreate?: never;
|
|
489
|
-
} | {
|
|
490
|
-
create?: never;
|
|
491
|
-
connect?: never;
|
|
492
|
-
connectOrCreate: {
|
|
493
|
-
where: WhereArg<Rel['model']>;
|
|
494
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
495
|
-
};
|
|
442
|
+
declare type WhereOnJoinItem = {
|
|
443
|
+
table?: string;
|
|
444
|
+
query: {
|
|
445
|
+
as?: string;
|
|
496
446
|
};
|
|
447
|
+
} | string;
|
|
448
|
+
declare type AggregateItemOptions = {
|
|
449
|
+
as?: string;
|
|
450
|
+
distinct?: boolean;
|
|
451
|
+
order?: OrderItem[];
|
|
452
|
+
filter?: WhereItem;
|
|
453
|
+
filterOr?: WhereItem[];
|
|
454
|
+
withinGroup?: boolean;
|
|
455
|
+
over?: string;
|
|
456
|
+
window?: WindowItem;
|
|
497
457
|
};
|
|
498
|
-
declare type
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
create?: never;
|
|
509
|
-
connect?: never;
|
|
510
|
-
connectOrCreate: {
|
|
511
|
-
where?: WhereArg<Rel['model']>;
|
|
512
|
-
create?: InsertData<Rel['nestedCreateQuery']>;
|
|
513
|
-
};
|
|
514
|
-
};
|
|
458
|
+
declare type SortDir = 'ASC' | 'DESC';
|
|
459
|
+
declare type OrderItem = string | Record<string, SortDir | {
|
|
460
|
+
dir: SortDir;
|
|
461
|
+
nulls: 'FIRST' | 'LAST';
|
|
462
|
+
}> | RawExpression;
|
|
463
|
+
declare type AggregateItemArg = Expression | Record<string, Expression> | [Expression, string];
|
|
464
|
+
declare type AggregateItem = {
|
|
465
|
+
function: string;
|
|
466
|
+
arg?: AggregateItemArg;
|
|
467
|
+
options: AggregateItemOptions;
|
|
515
468
|
};
|
|
516
|
-
declare type
|
|
517
|
-
[
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
469
|
+
declare type ColumnOperators<S extends SelectableBase, Column extends keyof S> = {
|
|
470
|
+
[O in keyof S[Column]['column']['operators']]?: S[Column]['column']['operators'][O]['type'];
|
|
471
|
+
};
|
|
472
|
+
declare type HavingItemObject = Record<string, unknown>;
|
|
473
|
+
declare type HavingItem = Record<string, HavingItemObject> | {
|
|
474
|
+
count?: number | HavingItemObject;
|
|
475
|
+
} | Query | RawExpression;
|
|
476
|
+
declare type WindowItem = Record<string, WindowDeclaration | RawExpression>;
|
|
477
|
+
declare type WindowDeclaration = {
|
|
478
|
+
partitionBy?: Expression | Expression[];
|
|
479
|
+
order?: OrderItem;
|
|
480
|
+
};
|
|
481
|
+
declare type UnionItem = Query | RawExpression;
|
|
482
|
+
declare type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT' | 'EXCEPT ALL';
|
|
483
|
+
declare type OnConflictItem = string | string[] | RawExpression;
|
|
484
|
+
declare type OnConflictMergeUpdate = string | string[] | Record<string, unknown> | RawExpression;
|
|
485
|
+
|
|
486
|
+
declare type ToSqlCtx = {
|
|
487
|
+
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
488
|
+
onQueryBuilder: typeof OnQueryBuilder;
|
|
489
|
+
sql: string[];
|
|
490
|
+
values: unknown[];
|
|
491
|
+
};
|
|
492
|
+
declare type toSqlCacheKey = typeof toSqlCacheKey;
|
|
493
|
+
declare const toSqlCacheKey: unique symbol;
|
|
494
|
+
declare type ToSqlOptions = {
|
|
495
|
+
clearCache?: boolean;
|
|
496
|
+
values?: unknown[];
|
|
525
497
|
};
|
|
526
|
-
declare
|
|
527
|
-
|
|
528
|
-
|
|
498
|
+
declare const toSql: (model: Query, options?: ToSqlOptions) => Sql;
|
|
499
|
+
|
|
500
|
+
declare type SomeIsTrue<T extends unknown[]> = T extends [
|
|
501
|
+
infer Head,
|
|
502
|
+
...infer Tail
|
|
503
|
+
] ? Head extends true ? true : SomeIsTrue<Tail> : false;
|
|
504
|
+
declare type MaybeArray<T> = T | T[];
|
|
505
|
+
declare type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
|
|
506
|
+
[P in K]?: P extends keyof T ? T[P] : never;
|
|
529
507
|
};
|
|
530
|
-
declare type
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
508
|
+
declare type OptionalPropertyNames<T> = {
|
|
509
|
+
[K in keyof T]-?: {} extends {
|
|
510
|
+
[P in K]: T[K];
|
|
511
|
+
} ? K : never;
|
|
512
|
+
}[keyof T];
|
|
513
|
+
declare type SpreadProperties<L, R, K extends keyof L & keyof R> = {
|
|
514
|
+
[P in K]: L[P] | Exclude<R[P], undefined>;
|
|
515
|
+
};
|
|
516
|
+
declare type Id<T> = T extends infer U ? {
|
|
517
|
+
[K in keyof U]: U[K];
|
|
518
|
+
} : never;
|
|
519
|
+
declare type SpreadTwo<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>;
|
|
520
|
+
declare type Spread<A extends readonly [...any]> = A extends [
|
|
521
|
+
infer L,
|
|
522
|
+
...infer R
|
|
523
|
+
] ? SpreadTwo<L, Spread<R>> : unknown;
|
|
524
|
+
declare type SimpleSpread<A extends readonly [...any]> = A extends [
|
|
525
|
+
infer L,
|
|
526
|
+
...infer R
|
|
527
|
+
] ? L & SimpleSpread<R> : {};
|
|
528
|
+
declare type FilterTuple<T extends readonly any[], E> = T extends [
|
|
529
|
+
infer F,
|
|
530
|
+
...infer R
|
|
531
|
+
] ? [F] extends [E] ? [F, ...FilterTuple<R, E>] : FilterTuple<R, E> : [];
|
|
532
|
+
declare type CoalesceString<Left extends string | undefined, Right extends string> = Left extends undefined ? Right : Left;
|
|
533
|
+
declare function applyMixins(derivedCtor: any, constructors: any[]): void;
|
|
534
|
+
declare const joinTruthy: (...strings: (string | false | undefined)[]) => string;
|
|
535
|
+
declare const getClonedQueryData: (query: QueryData) => QueryData;
|
|
536
|
+
declare const getQueryAs: (q: {
|
|
537
|
+
table?: string;
|
|
538
|
+
query: {
|
|
539
|
+
as?: string;
|
|
551
540
|
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
declare
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
merge(update?: keyof T['shape'] | (keyof T['shape'])[] | Partial<T['inputType']> | RawExpression): T;
|
|
561
|
-
}
|
|
541
|
+
}) => string;
|
|
542
|
+
declare const toArray: <T>(item: T) => T extends unknown[] ? T : [T];
|
|
543
|
+
declare const noop: () => void;
|
|
544
|
+
declare type EmptyObject = typeof emptyObject;
|
|
545
|
+
declare const emptyObject: {};
|
|
546
|
+
declare const makeRegexToFindInSql: (value: string) => RegExp;
|
|
547
|
+
declare const pushOrNewArrayToObject: <Obj extends {}, Key extends keyof Obj>(obj: Obj, key: Key, value: Exclude<Obj[Key], undefined> extends unknown[] ? Exclude<Obj[Key], undefined>[number] : never) => void;
|
|
548
|
+
declare const pushOrNewArray: <Arr extends unknown[]>(arr: Arr | undefined, value: Arr[number]) => Arr;
|
|
562
549
|
|
|
563
|
-
declare type
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
declare type JsonSetResult<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string, Type extends ColumnType = Column extends keyof T['shape'] ? T['shape'][Column] : Column extends JsonItem ? Column['__json'][2] : ColumnType> = JsonItem<As, Type> & (Type extends ColumnType ? AddQuerySelect<T, Record<As, Type>> : T);
|
|
568
|
-
declare type JsonPathQueryResult<T extends Query, As extends string, Type extends ColumnType> = JsonItem & AddQuerySelect<T, {
|
|
569
|
-
[K in As]: Type;
|
|
570
|
-
}>;
|
|
571
|
-
declare class Json {
|
|
572
|
-
json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
573
|
-
_json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
574
|
-
jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
575
|
-
as?: As;
|
|
576
|
-
createIfMissing?: boolean;
|
|
577
|
-
}): JsonSetResult<T, Column, As>;
|
|
578
|
-
_jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
579
|
-
as?: As;
|
|
580
|
-
createIfMissing?: boolean;
|
|
581
|
-
}): JsonSetResult<T, Column, As>;
|
|
582
|
-
jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
583
|
-
column: Column,
|
|
584
|
-
path: Array<string | number>,
|
|
585
|
-
value: unknown,
|
|
586
|
-
options?: {
|
|
587
|
-
as?: As;
|
|
588
|
-
insertAfter?: boolean;
|
|
589
|
-
}
|
|
590
|
-
]): JsonSetResult<T, Column, As>;
|
|
591
|
-
_jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
592
|
-
as?: As;
|
|
593
|
-
insertAfter?: boolean;
|
|
594
|
-
}): JsonSetResult<T, Column, As>;
|
|
595
|
-
jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
596
|
-
column: Column,
|
|
597
|
-
path: Array<string | number>,
|
|
598
|
-
options?: {
|
|
599
|
-
as?: As;
|
|
600
|
-
}
|
|
601
|
-
]): JsonSetResult<T, Column, As>;
|
|
602
|
-
_jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, options?: {
|
|
603
|
-
as?: As;
|
|
604
|
-
}): JsonSetResult<T, Column, As>;
|
|
605
|
-
jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, ...args: [
|
|
606
|
-
type: Type,
|
|
607
|
-
column: ColumnOrJsonMethod<T>,
|
|
608
|
-
path: string,
|
|
609
|
-
as: As,
|
|
610
|
-
options?: {
|
|
611
|
-
vars?: string;
|
|
612
|
-
silent?: boolean;
|
|
613
|
-
}
|
|
614
|
-
]): JsonPathQueryResult<T, As, Type>;
|
|
615
|
-
_jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, type: Type, column: ColumnOrJsonMethod<T>, path: string, as: As, options?: {
|
|
616
|
-
vars?: string;
|
|
617
|
-
silent?: boolean;
|
|
618
|
-
}): JsonPathQueryResult<T, As, Type>;
|
|
550
|
+
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
551
|
+
declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
|
|
552
|
+
declare class Then {
|
|
553
|
+
then(this: Query, resolve?: (result: any) => any, reject?: (error: any) => any): Promise<any>;
|
|
619
554
|
}
|
|
555
|
+
declare const handleResult: CommonQueryData['handleResult'];
|
|
556
|
+
declare const parseResult: (q: Query, returnType: QueryReturnType | undefined, result: QueryResult) => unknown;
|
|
557
|
+
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
620
558
|
|
|
621
|
-
declare type
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
declare
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
log?: boolean | Partial<QueryLogObject>;
|
|
633
|
-
logger?: QueryLogger;
|
|
634
|
-
};
|
|
635
|
-
declare const logColors: {
|
|
636
|
-
boldCyanBright: (message: string) => string;
|
|
637
|
-
boldBlue: (message: string) => string;
|
|
638
|
-
boldYellow: (message: string) => string;
|
|
639
|
-
boldMagenta: (message: string) => string;
|
|
640
|
-
boldRed: (message: string) => string;
|
|
641
|
-
};
|
|
642
|
-
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions['log']) => QueryLogObject | undefined;
|
|
643
|
-
declare class QueryLog {
|
|
644
|
-
log<T extends Query>(this: T, log?: boolean): T;
|
|
645
|
-
_log<T extends Query>(this: T, log?: boolean): T;
|
|
559
|
+
declare type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
560
|
+
declare type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
561
|
+
declare type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
562
|
+
declare type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
563
|
+
declare type getValueKey = typeof getValueKey;
|
|
564
|
+
declare const getValueKey: unique symbol;
|
|
565
|
+
declare class QueryGet {
|
|
566
|
+
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
567
|
+
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
568
|
+
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
569
|
+
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
646
570
|
}
|
|
647
571
|
|
|
648
572
|
declare type SelectArg<T extends QueryBase> = StringKey<keyof T['selectable']> | (T['relations'] extends Record<string, Relation> ? StringKey<keyof T['relations']> : never) | SelectAsArg<T>;
|
|
@@ -654,7 +578,7 @@ declare type SelectResult<T extends Query, Args extends SelectArg<T>[], SelectAs
|
|
|
654
578
|
}>;
|
|
655
579
|
declare type SelectSubQueryResult<Arg extends Query & {
|
|
656
580
|
[isRequiredRelationKey]?: boolean;
|
|
657
|
-
}> = Arg['returnType'] extends
|
|
581
|
+
}> = QueryReturnsAll<Arg['returnType']> extends true ? ArrayOfColumnsObjects<Arg['result']> : Arg['returnType'] extends 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? PluckResultColumnType<Arg['result']['pluck']> : Arg[isRequiredRelationKey] extends true ? ColumnsObject<Arg['result']> : NullableColumn<ColumnsObject<Arg['result']>>;
|
|
658
582
|
declare const addParserForRawExpression: (q: Query, key: string | getValueKey, raw: RawExpression) => void;
|
|
659
583
|
declare const addParserForSelectItem: <T extends Query>(q: T, as: string | getValueKey | undefined, key: string, arg: RawExpression<ColumnType<unknown, Operators, unknown>> | Exclude<keyof T["selectable"], number | symbol> | ((q: T) => Query)) => string | RawExpression | Query;
|
|
660
584
|
declare const addParserToQuery: (query: QueryData, key: string | getValueKey, parser: ColumnParser) => void;
|
|
@@ -665,204 +589,250 @@ declare class Select {
|
|
|
665
589
|
selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
666
590
|
_selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
667
591
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
rowCount: number;
|
|
683
|
-
rows: R[];
|
|
684
|
-
fields: {
|
|
685
|
-
name: string;
|
|
686
|
-
}[];
|
|
687
|
-
};
|
|
688
|
-
declare type AdapterOptions = Omit<PoolConfig, 'types'> & {
|
|
689
|
-
types?: TypeParsers;
|
|
690
|
-
};
|
|
691
|
-
declare class Adapter {
|
|
692
|
-
types: TypeParsers;
|
|
693
|
-
pool: Pool;
|
|
694
|
-
constructor({ types, ...config }: AdapterOptions);
|
|
695
|
-
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
696
|
-
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
697
|
-
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
698
|
-
close(): Promise<void>;
|
|
699
|
-
}
|
|
700
|
-
declare class TransactionAdapter implements Adapter {
|
|
701
|
-
pool: Pool;
|
|
702
|
-
client: PoolClient;
|
|
703
|
-
types: TypeParsers;
|
|
704
|
-
constructor(pool: Pool, client: PoolClient, types: TypeParsers);
|
|
705
|
-
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
706
|
-
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
707
|
-
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
708
|
-
close(): Promise<void>;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
712
|
-
declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
|
|
713
|
-
declare class Then {
|
|
714
|
-
then(this: Query, resolve?: (result: any) => any, reject?: (error: any) => any): Promise<any>;
|
|
715
|
-
}
|
|
716
|
-
declare const handleResult: CommonQueryData['handleResult'];
|
|
717
|
-
declare const parseResult: (q: Query, returnType: QueryReturnType, result: QueryResult) => unknown;
|
|
718
|
-
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
719
|
-
|
|
720
|
-
declare class Transaction {
|
|
721
|
-
transaction<T extends Query, Result>(this: T, cb: (query: T) => Promise<Result>): Promise<Result>;
|
|
722
|
-
transacting<T extends Query>(this: T, query: Query): T;
|
|
723
|
-
_transacting<T extends Query>(this: T, query: Query): T;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
declare type UnionArg<T extends Query> = (Omit<Query, 'result'> & {
|
|
727
|
-
result: T['result'];
|
|
728
|
-
}) | RawExpression;
|
|
729
|
-
declare class Union {
|
|
730
|
-
union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
731
|
-
_union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
732
|
-
unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
733
|
-
_unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
734
|
-
intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
735
|
-
_intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
736
|
-
intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
737
|
-
_intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
738
|
-
except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
739
|
-
_except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
740
|
-
exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
741
|
-
_exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
592
|
+
|
|
593
|
+
declare type FromArgs<T extends Query> = [
|
|
594
|
+
first: string | Query | RawExpression | Exclude<keyof T['withData'], symbol | number>,
|
|
595
|
+
second?: string | {
|
|
596
|
+
as?: string;
|
|
597
|
+
only?: boolean;
|
|
598
|
+
}
|
|
599
|
+
];
|
|
600
|
+
declare type FromResult<T extends Query, Args extends FromArgs<T>> = Args[1] extends string ? SetQueryTableAlias<T, Args[1]> : Args[1] extends {
|
|
601
|
+
as: string;
|
|
602
|
+
} ? SetQueryTableAlias<T, Args[1]['as']> : Args[0] extends string ? SetQueryTableAlias<T, Args[0]> : Args[0] extends Query ? SetQueryTableAlias<T, AliasOrTable<Args[0]>> : T;
|
|
603
|
+
declare class From {
|
|
604
|
+
from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
605
|
+
_from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
742
606
|
}
|
|
743
607
|
|
|
744
|
-
declare type
|
|
745
|
-
[K in keyof T['
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
608
|
+
declare type WhereArg<T extends QueryBase> = (Omit<{
|
|
609
|
+
[K in keyof T['selectable']]?: T['selectable'][K]['column']['type'] | null | ColumnOperators<T['selectable'], K> | RawExpression;
|
|
610
|
+
}, 'NOT' | 'OR' | 'IN' | 'EXISTS'> & {
|
|
611
|
+
NOT?: MaybeArray<WhereArg<T>>;
|
|
612
|
+
OR?: MaybeArray<WhereArg<T>>[];
|
|
613
|
+
IN?: MaybeArray<{
|
|
614
|
+
columns: (keyof T['selectable'])[];
|
|
615
|
+
values: unknown[][] | Query | RawExpression;
|
|
616
|
+
}>;
|
|
617
|
+
EXISTS?: MaybeArray<JoinArgs<T> | JoinCallbackArg<T>>;
|
|
618
|
+
}) | QueryBase | RawExpression | ((q: WhereQueryBuilder<T>) => WhereQueryBuilder);
|
|
619
|
+
declare type WhereInColumn<T extends QueryBase> = keyof T['selectable'] | [keyof T['selectable'], ...(keyof T['selectable'])[]];
|
|
620
|
+
declare type WhereInValues<T extends QueryBase, Column extends WhereInColumn<T>> = Column extends keyof T['selectable'] ? T['selectable'][Column]['column']['type'][] | Query | RawExpression : ({
|
|
621
|
+
[I in keyof Column]: Column[I] extends keyof T['selectable'] ? T['selectable'][Column[I]]['column']['type'] : never;
|
|
622
|
+
} & {
|
|
623
|
+
length: Column extends {
|
|
624
|
+
length: number;
|
|
625
|
+
} ? Column['length'] : never;
|
|
626
|
+
})[] | Query | RawExpression;
|
|
627
|
+
declare type WhereResult<T extends QueryBase> = T & {
|
|
628
|
+
hasWhere: true;
|
|
750
629
|
};
|
|
751
|
-
declare type
|
|
752
|
-
|
|
753
|
-
} | {
|
|
754
|
-
set: WhereArg<Rel['model']>;
|
|
755
|
-
} | {
|
|
756
|
-
delete: boolean;
|
|
757
|
-
} | {
|
|
758
|
-
update: UpdateData<Rel['model']>;
|
|
759
|
-
} | {
|
|
760
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
761
|
-
} | (T['returnType'] extends 'all' ? never : {
|
|
762
|
-
upsert: {
|
|
763
|
-
update: UpdateData<Rel['model']>;
|
|
764
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
765
|
-
};
|
|
766
|
-
});
|
|
767
|
-
declare type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> = {
|
|
768
|
-
disconnect: boolean;
|
|
769
|
-
} | {
|
|
770
|
-
delete: boolean;
|
|
771
|
-
} | {
|
|
772
|
-
update: UpdateData<Rel['model']>;
|
|
773
|
-
} | (T['returnType'] extends 'all' ? never : {
|
|
774
|
-
set: WhereArg<Rel['model']>;
|
|
775
|
-
} | {
|
|
776
|
-
upsert: {
|
|
777
|
-
update: UpdateData<Rel['model']>;
|
|
778
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
779
|
-
};
|
|
780
|
-
} | {
|
|
781
|
-
create: InsertData<Rel['nestedCreateQuery']>;
|
|
782
|
-
});
|
|
783
|
-
declare type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
|
|
784
|
-
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
785
|
-
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
786
|
-
update?: {
|
|
787
|
-
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
788
|
-
data: UpdateData<Rel['model']>;
|
|
789
|
-
};
|
|
790
|
-
} & (T['returnType'] extends 'all' ? EmptyObject : {
|
|
791
|
-
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
792
|
-
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
793
|
-
});
|
|
794
|
-
declare type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
|
|
795
|
-
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
796
|
-
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
797
|
-
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
798
|
-
update?: {
|
|
799
|
-
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
800
|
-
data: UpdateData<Rel['model']>;
|
|
801
|
-
};
|
|
802
|
-
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
630
|
+
declare type WhereInArg<T extends Pick<Query, 'selectable'>> = {
|
|
631
|
+
[K in keyof T['selectable']]?: T['selectable'][K]['column']['type'][] | Query | RawExpression;
|
|
803
632
|
};
|
|
804
|
-
declare
|
|
805
|
-
declare
|
|
806
|
-
declare
|
|
807
|
-
declare
|
|
808
|
-
declare
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
633
|
+
declare const addWhere: <T extends Where>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
634
|
+
declare const addWhereNot: <T extends QueryBase>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
635
|
+
declare const addOr: <T extends QueryBase>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
636
|
+
declare const addOrNot: <T extends QueryBase>(q: T, args: WhereArg<T>[]) => WhereResult<T>;
|
|
637
|
+
declare const addWhereIn: <T extends QueryBase>(q: T, and: boolean, arg: unknown, values: unknown[] | unknown[][] | Query | RawExpression | undefined, not?: boolean) => WhereResult<T>;
|
|
638
|
+
declare abstract class Where implements QueryBase {
|
|
639
|
+
abstract clone<T extends this>(this: T): T;
|
|
640
|
+
abstract selectable: SelectableBase;
|
|
641
|
+
abstract shape: ColumnsShape;
|
|
642
|
+
abstract relations: RelationsBase;
|
|
643
|
+
abstract withData: WithDataBase;
|
|
644
|
+
abstract __model: Query;
|
|
645
|
+
query: QueryData;
|
|
646
|
+
table?: string;
|
|
647
|
+
tableAlias?: string;
|
|
648
|
+
where<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
649
|
+
_where<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
650
|
+
whereNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
651
|
+
_whereNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
652
|
+
and<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
653
|
+
_and<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
654
|
+
andNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
655
|
+
_andNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
656
|
+
or<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
657
|
+
_or<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
658
|
+
orNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
659
|
+
_orNot<T extends Where>(this: T, ...args: WhereArg<T>[]): WhereResult<T>;
|
|
660
|
+
whereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): T;
|
|
661
|
+
whereIn<T extends Where>(this: T, arg: WhereInArg<T>): T;
|
|
662
|
+
_whereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
663
|
+
_whereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
664
|
+
orWhereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
665
|
+
orWhereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
666
|
+
_orWhereIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
667
|
+
_orWhereIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
668
|
+
whereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
669
|
+
whereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
670
|
+
_whereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
671
|
+
_whereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
672
|
+
orWhereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
673
|
+
orWhereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
674
|
+
_orWhereNotIn<T extends Where, Column extends WhereInColumn<T>>(this: T, column: Column, values: WhereInValues<T, Column>): WhereResult<T>;
|
|
675
|
+
_orWhereNotIn<T extends Where>(this: T, arg: WhereInArg<T>): WhereResult<T>;
|
|
676
|
+
whereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
677
|
+
whereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
678
|
+
_whereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
679
|
+
_whereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
680
|
+
orWhereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
681
|
+
orWhereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
682
|
+
_orWhereExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
683
|
+
_orWhereExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
684
|
+
whereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
685
|
+
whereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
686
|
+
_whereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
687
|
+
_whereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
688
|
+
orWhereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
689
|
+
orWhereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
690
|
+
_orWhereNotExists<T extends Where, Args extends JoinArgs<T>>(this: T, ...args: Args): WhereResult<T>;
|
|
691
|
+
_orWhereNotExists<T extends Where, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): WhereResult<T>;
|
|
692
|
+
}
|
|
693
|
+
declare class WhereQueryBuilder<Q extends QueryBase = QueryBase> extends Where implements QueryBase {
|
|
694
|
+
query: QueryData;
|
|
695
|
+
selectable: Q['selectable'];
|
|
696
|
+
shape: Q['shape'];
|
|
697
|
+
relations: Q['relations'];
|
|
698
|
+
__model: Query;
|
|
699
|
+
withData: {};
|
|
700
|
+
constructor(q: QueryBase | string, shape: ColumnsShape);
|
|
701
|
+
clone<T extends this>(this: T): T;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
declare type WithSelectable<T extends QueryBase, W extends keyof T['withData']> = T['withData'][W] extends WithDataItem ? StringKey<keyof T['withData'][W]['shape']> | `${T['withData'][W]['table']}.${StringKey<keyof T['withData'][W]['shape']>}` : never;
|
|
705
|
+
declare type JoinArgs<T extends QueryBase, Q extends Query = Query, R extends keyof T['relations'] = keyof T['relations'], W extends keyof T['withData'] = keyof T['withData']> = [relation: R] | [
|
|
706
|
+
query: Q,
|
|
707
|
+
conditions: Record<Selectable<Q>, Selectable<T> | RawExpression> | RawExpression
|
|
708
|
+
] | [
|
|
709
|
+
withAlias: W,
|
|
710
|
+
conditions: Record<WithSelectable<T, W>, Selectable<T> | RawExpression> | RawExpression
|
|
711
|
+
] | [
|
|
712
|
+
query: Q,
|
|
713
|
+
leftColumn: Selectable<Q> | RawExpression,
|
|
714
|
+
rightColumn: Selectable<T> | RawExpression
|
|
715
|
+
] | [
|
|
716
|
+
withAlias: W,
|
|
717
|
+
leftColumn: WithSelectable<T, W> | RawExpression,
|
|
718
|
+
rightColumn: Selectable<T> | RawExpression
|
|
719
|
+
] | [
|
|
720
|
+
query: Q,
|
|
721
|
+
leftColumn: Selectable<Q> | RawExpression,
|
|
722
|
+
op: string,
|
|
723
|
+
rightColumn: Selectable<T> | RawExpression
|
|
724
|
+
] | [
|
|
725
|
+
withAlias: W,
|
|
726
|
+
leftColumn: WithSelectable<T, W> | RawExpression,
|
|
727
|
+
op: string,
|
|
728
|
+
rightColumn: Selectable<T> | RawExpression
|
|
729
|
+
];
|
|
730
|
+
declare type JoinResult<T extends Query, Args extends JoinArgs<T>, A extends Query | keyof T['relations'] = Args[0]> = AddQueryJoinedTable<T, A extends Query ? A : T['relations'] extends Record<string, Relation> ? A extends keyof T['relations'] ? T['relations'][A]['model'] : A extends keyof T['withData'] ? T['withData'][A] extends WithDataItem ? {
|
|
731
|
+
table: T['withData'][A]['table'];
|
|
732
|
+
tableAlias: undefined;
|
|
733
|
+
result: T['withData'][A]['shape'];
|
|
734
|
+
} : never : never : never>;
|
|
735
|
+
declare type JoinCallbackArg<T extends QueryBase> = Query | keyof T['withData'] | keyof T['relations'];
|
|
736
|
+
declare type JoinCallback<T extends QueryBase, Arg extends JoinCallbackArg<T>> = (q: OnQueryBuilder<T, Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? {
|
|
737
|
+
query: QueryData;
|
|
738
|
+
table: T['withData'][Arg]['table'];
|
|
739
|
+
tableAlias: undefined;
|
|
740
|
+
clone(): QueryBase;
|
|
741
|
+
selectable: {
|
|
742
|
+
[K in keyof T['withData'][Arg]['shape'] as `${T['withData'][Arg]['table']}.${StringKey<K>}`]: {
|
|
743
|
+
as: StringKey<K>;
|
|
744
|
+
column: T['withData'][Arg]['shape'][K];
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
shape: T['withData'][Arg]['shape'];
|
|
748
|
+
__model: Query;
|
|
749
|
+
relations: RelationsBase;
|
|
750
|
+
withData: WithDataBase;
|
|
751
|
+
} : never : Arg extends Query ? Arg : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['model'] : never : never>) => OnQueryBuilder;
|
|
752
|
+
declare type JoinCallbackResult<T extends Query, Arg extends JoinCallbackArg<T>> = AddQueryJoinedTable<T, Arg extends Query ? Arg : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['model'] : Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? {
|
|
753
|
+
table: T['withData'][Arg]['table'];
|
|
754
|
+
tableAlias: undefined;
|
|
755
|
+
result: T['withData'][Arg]['shape'];
|
|
756
|
+
} : never : never : never>;
|
|
757
|
+
declare class Join {
|
|
758
|
+
join<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
759
|
+
join<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
760
|
+
_join<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
761
|
+
_join<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
762
|
+
innerJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
763
|
+
innerJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
764
|
+
_innerJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
765
|
+
_innerJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
766
|
+
leftJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
767
|
+
leftJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
768
|
+
_leftJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
769
|
+
_leftJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
770
|
+
leftOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
771
|
+
leftOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
772
|
+
_leftOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
773
|
+
_leftOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
774
|
+
rightJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
775
|
+
rightJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
776
|
+
_rightJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
777
|
+
_rightJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
778
|
+
rightOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
779
|
+
rightOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
780
|
+
_rightOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
781
|
+
_rightOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
782
|
+
fullOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
783
|
+
fullOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
784
|
+
_fullOuterJoin<T extends Query, Args extends JoinArgs<T>>(this: T, ...args: Args): JoinResult<T, Args>;
|
|
785
|
+
_fullOuterJoin<T extends Query, Arg extends JoinCallbackArg<T>>(this: T, arg: Arg, cb: JoinCallback<T, Arg>): JoinCallbackResult<T, Arg>;
|
|
819
786
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
declare
|
|
830
|
-
|
|
831
|
-
|
|
787
|
+
declare type OnArgs<Q extends {
|
|
788
|
+
selectable: SelectableBase;
|
|
789
|
+
}> = [leftColumn: keyof Q['selectable'], rightColumn: keyof Q['selectable']] | [
|
|
790
|
+
leftColumn: keyof Q['selectable'],
|
|
791
|
+
op: string,
|
|
792
|
+
rightColumn: keyof Q['selectable']
|
|
793
|
+
];
|
|
794
|
+
declare const pushQueryOn: <T extends QueryBase>(q: T, joinFrom: QueryBase | string, joinTo: QueryBase | string, ...on: OnArgs<QueryBase>) => T;
|
|
795
|
+
declare const pushQueryOrOn: typeof pushQueryOn;
|
|
796
|
+
declare const addQueryOn: typeof pushQueryOrOn;
|
|
797
|
+
declare const addQueryOrOn: typeof pushQueryOrOn;
|
|
798
|
+
declare type OnJsonPathEqualsArgs<T extends QueryBase> = [
|
|
799
|
+
leftColumn: keyof T['selectable'],
|
|
800
|
+
leftPath: string,
|
|
801
|
+
rightColumn: keyof T['selectable'],
|
|
802
|
+
rightPath: string
|
|
803
|
+
];
|
|
804
|
+
declare class OnQueryBuilder<S extends QueryBase = QueryBase, J extends QueryBase = QueryBase> extends WhereQueryBuilder<Omit<J, 'selectable'> & {
|
|
805
|
+
selectable: Omit<S['selectable'], keyof S['shape']> & J['selectable'];
|
|
806
|
+
}> implements QueryBase {
|
|
807
|
+
joinTo: QueryBase;
|
|
808
|
+
constructor(q: QueryBase | string, shape: ColumnsShape, joinTo: QueryBase);
|
|
809
|
+
on<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
810
|
+
_on<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
811
|
+
orOn<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
812
|
+
_orOn<T extends this>(this: T, ...args: OnArgs<T>): T;
|
|
813
|
+
onJsonPathEquals<T extends this>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
|
|
814
|
+
_onJsonPathEquals<T extends this>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
|
|
832
815
|
}
|
|
833
816
|
|
|
834
|
-
declare function timestamps<T extends ColumnType>(this: {
|
|
835
|
-
timestamp(): T;
|
|
836
|
-
}): {
|
|
837
|
-
createdAt: T & {
|
|
838
|
-
hasDefault: true;
|
|
839
|
-
};
|
|
840
|
-
updatedAt: T & {
|
|
841
|
-
hasDefault: true;
|
|
842
|
-
};
|
|
843
|
-
};
|
|
844
|
-
|
|
845
817
|
declare type DbTableOptions = {
|
|
846
818
|
schema?: string;
|
|
847
819
|
} & QueryLogOptions;
|
|
848
820
|
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> extends QueryMethods {
|
|
849
821
|
new (adapter: Adapter, queryBuilder: Db, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
850
822
|
adapter: Adapter;
|
|
823
|
+
columns: (keyof ColumnShapeOutput<Shape>)[];
|
|
851
824
|
queryBuilder: Db;
|
|
852
825
|
whereQueryBuilder: Query['whereQueryBuilder'];
|
|
826
|
+
onQueryBuilder: Query['onQueryBuilder'];
|
|
853
827
|
table: Table;
|
|
854
828
|
shape: Shape;
|
|
855
|
-
|
|
829
|
+
singlePrimaryKey: SinglePrimaryKey<Shape>;
|
|
830
|
+
primaryKeys: Query['primaryKeys'];
|
|
856
831
|
type: ColumnShapeOutput<Shape>;
|
|
857
832
|
inputType: ColumnShapeInput<Shape>;
|
|
858
|
-
returnType: 'all';
|
|
859
|
-
then: ThenResult<Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[]>;
|
|
860
833
|
query: QueryData;
|
|
861
|
-
columns: (keyof ColumnShapeOutput<Shape>)[];
|
|
862
|
-
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
863
|
-
columnsParsers?: ColumnsParsers;
|
|
864
834
|
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
865
|
-
hasSelect:
|
|
835
|
+
hasSelect: Query['hasSelect'];
|
|
866
836
|
hasWhere: boolean;
|
|
867
837
|
selectable: {
|
|
868
838
|
[K in keyof Shape]: {
|
|
@@ -875,588 +845,363 @@ interface Db<Table extends string | undefined = undefined, Shape extends Columns
|
|
|
875
845
|
column: Shape[K];
|
|
876
846
|
};
|
|
877
847
|
};
|
|
848
|
+
returnType: Query['returnType'];
|
|
849
|
+
then: ThenResult<Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[]>;
|
|
878
850
|
tableAlias: undefined;
|
|
879
|
-
windows: PropertyKey[];
|
|
880
|
-
withData: Query['withData'];
|
|
881
851
|
joinedTables: Query['joinedTables'];
|
|
852
|
+
windows: Query['windows'];
|
|
853
|
+
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
854
|
+
columnsParsers?: ColumnsParsers;
|
|
882
855
|
relations: Relations;
|
|
856
|
+
withData: Query['withData'];
|
|
883
857
|
[defaultsKey]: Record<{
|
|
884
858
|
[K in keyof Shape]: Shape[K]['hasDefault'] extends true ? K : never;
|
|
885
|
-
}[keyof Shape], true>;
|
|
886
|
-
}
|
|
887
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> implements Query {
|
|
888
|
-
adapter: Adapter;
|
|
889
|
-
queryBuilder: Db;
|
|
890
|
-
table: Table;
|
|
891
|
-
shape: Shape;
|
|
892
|
-
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
893
|
-
onQueryBuilder: typeof OnQueryBuilder;
|
|
894
|
-
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, options: DbTableOptions);
|
|
895
|
-
}
|
|
896
|
-
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
897
|
-
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
898
|
-
adapter: Adapter;
|
|
899
|
-
close: Adapter['close'];
|
|
900
|
-
};
|
|
901
|
-
declare type DbOptions<CT extends ColumnTypesBase = ColumnTypes> = ({
|
|
902
|
-
adapter: Adapter;
|
|
903
|
-
} | Omit<AdapterOptions, 'log'>) & QueryLogOptions & {
|
|
904
|
-
columnTypes?: CT;
|
|
905
|
-
};
|
|
906
|
-
declare const createDb: <CT extends ColumnTypesBase = {
|
|
907
|
-
smallint: () => SmallIntColumn;
|
|
908
|
-
integer: () => IntegerColumn;
|
|
909
|
-
bigint: () => BigIntColumn;
|
|
910
|
-
numeric: <Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(precision?: Precision | undefined, scale?: Scale | undefined) => DecimalColumn<Precision, Scale>;
|
|
911
|
-
decimal: <Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(precision?: Precision_1 | undefined, scale?: Scale_1 | undefined) => DecimalColumn<Precision_1, Scale_1>;
|
|
912
|
-
real: () => RealColumn;
|
|
913
|
-
doublePrecision: () => DoublePrecisionColumn;
|
|
914
|
-
smallSerial: () => SmallSerialColumn;
|
|
915
|
-
serial: () => SerialColumn;
|
|
916
|
-
bigSerial: () => BigSerialColumn;
|
|
917
|
-
money: () => MoneyColumn;
|
|
918
|
-
varchar: <Limit extends number | undefined = undefined>(limit?: Limit | undefined) => VarCharColumn<Limit>;
|
|
919
|
-
char: <Limit_1 extends number | undefined = undefined>(limit?: Limit_1 | undefined) => CharColumn<Limit_1>;
|
|
920
|
-
text: () => TextColumn;
|
|
921
|
-
string: () => TextColumn;
|
|
922
|
-
bytea: () => ByteaColumn;
|
|
923
|
-
date: () => DateColumn;
|
|
924
|
-
timestamp: <Precision_2 extends number | undefined = undefined>(precision?: Precision_2 | undefined) => TimestampColumn<Precision_2>;
|
|
925
|
-
timestampWithTimeZone: <Precision_3 extends number | undefined = undefined>(precision?: Precision_3 | undefined) => TimestampWithTimeZoneColumn<Precision_3>;
|
|
926
|
-
time: <Precision_4 extends number | undefined = undefined>(precision?: Precision_4 | undefined) => TimeColumn<Precision_4>;
|
|
927
|
-
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => TimeWithTimeZoneColumn<Precision_5>;
|
|
928
|
-
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => IntervalColumn<Fields, Precision_6>;
|
|
929
|
-
boolean: () => BooleanColumn;
|
|
930
|
-
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
931
|
-
point: () => PointColumn;
|
|
932
|
-
line: () => LineColumn;
|
|
933
|
-
lseg: () => LsegColumn;
|
|
934
|
-
box: () => BoxColumn;
|
|
935
|
-
path: () => PathColumn;
|
|
936
|
-
polygon: () => PolygonColumn;
|
|
937
|
-
circle: () => CircleColumn;
|
|
938
|
-
cidr: () => CidrColumn;
|
|
939
|
-
inet: () => InetColumn;
|
|
940
|
-
macaddr: () => MacAddrColumn;
|
|
941
|
-
macaddr8: () => MacAddr8Column;
|
|
942
|
-
bit: <Length extends number>(length: Length) => BitColumn<Length>;
|
|
943
|
-
bitVarying: <Length_1 extends number | undefined = undefined>(length?: Length_1 | undefined) => BitVaryingColumn<Length_1 | undefined>;
|
|
944
|
-
tsvector: () => TsVectorColumn;
|
|
945
|
-
tsquery: () => TsQueryColumn;
|
|
946
|
-
uuid: () => UUIDColumn;
|
|
947
|
-
xml: () => XMLColumn;
|
|
948
|
-
json: <Type extends JSONTypeAny>(schemaOrFn: Type | ((j: {
|
|
949
|
-
set: <Value extends JSONTypeAny>(valueType: Value) => JSONSet<Value>;
|
|
950
|
-
tuple: <T_1 extends [] | JSONTupleItems, Rest extends JSONTypeAny | null = null>(items: T_1, rest?: Rest) => JSONTuple<T_1, Rest>;
|
|
951
|
-
union: <T_2 extends [JSONTypeAny, JSONTypeAny, ...JSONTypeAny[]]>(types: T_2) => JSONUnion<T_2>;
|
|
952
|
-
any: () => JSONAny;
|
|
953
|
-
bigint: () => JSONBigInt;
|
|
954
|
-
boolean: () => JSONBoolean;
|
|
955
|
-
date: () => JSONDate;
|
|
956
|
-
nan: () => JSONNaN;
|
|
957
|
-
never: () => JSONNever;
|
|
958
|
-
null: () => JSONNull;
|
|
959
|
-
number: () => JSONNumber;
|
|
960
|
-
string: () => JSONString;
|
|
961
|
-
undefined: () => JSONUndefined;
|
|
962
|
-
unknown: () => JSONUnknown;
|
|
963
|
-
void: () => JSONVoid;
|
|
964
|
-
array: <Type_1 extends JSONTypeAny>(element: Type_1) => JSONArray<Type_1, "many">;
|
|
965
|
-
discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends Primitive, Types extends [JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
|
|
966
|
-
enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => JSONEnum<U_1, T_3>;
|
|
967
|
-
instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => JSONInstanceOf<T_4>;
|
|
968
|
-
intersection: <Left extends JSONTypeAny, Right extends JSONTypeAny>(left: Left, right: Right) => JSONIntersection<Left, Right>;
|
|
969
|
-
lazy: <T_5 extends JSONTypeAny>(fn: () => T_5) => JSONLazy<T_5>;
|
|
970
|
-
literal: <T_6 extends Primitive>(value: T_6) => JSONLiteral<T_6>;
|
|
971
|
-
map: <Key extends JSONTypeAny, Value_1 extends JSONTypeAny>(keyType: Key, valueType: Value_1) => JSONMap<Key, Value_1>;
|
|
972
|
-
nativeEnum: <T_7 extends EnumLike>(givenEnum: T_7) => JSONNativeEnum<T_7>;
|
|
973
|
-
nullable: <T_8 extends JSONTypeAny>(type: T_8) => JSONNullable<T_8>;
|
|
974
|
-
nullish: <T_9 extends JSONTypeAny>(type: T_9) => JSONNullish<T_9>;
|
|
975
|
-
object: <T_10 extends JSONObjectShape, UnknownKeys extends UnknownKeysParam = "strip", Catchall extends JSONTypeAny = JSONTypeAny>(shape: T_10) => JSONObject<T_10, UnknownKeys, Catchall, JSONTypeAny extends Catchall ? addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
976
|
-
[k: string]: Catchall["type"];
|
|
977
|
-
} extends infer T_12 ? { [k_2 in keyof T_12]: ((addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
978
|
-
[k: string]: Catchall["type"];
|
|
979
|
-
})[k_2]; } : never>;
|
|
980
|
-
optional: <T_13 extends JSONTypeAny>(type: T_13) => JSONOptional<T_13>;
|
|
981
|
-
record: typeof record;
|
|
982
|
-
}) => Type)) => JSONColumn<Type>;
|
|
983
|
-
jsonText: () => JSONTextColumn;
|
|
984
|
-
array: <Item extends ColumnType<unknown, Operators, unknown>>(item: Item) => ArrayColumn<Item>;
|
|
985
|
-
timestamps: typeof timestamps;
|
|
986
|
-
primaryKey(columns: string[], options?: {
|
|
987
|
-
name?: string | undefined;
|
|
988
|
-
} | undefined): {};
|
|
989
|
-
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
990
|
-
unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
991
|
-
foreignKey: {
|
|
992
|
-
<Model extends ForeignKeyModelWithColumns, Columns extends [Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Model, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
|
|
993
|
-
<Table extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
|
|
994
|
-
};
|
|
995
|
-
}>({ log, logger, columnTypes: ct, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
996
|
-
|
|
997
|
-
declare type WithArgsOptions = Omit<WithOptions, 'columns'> & {
|
|
998
|
-
columns?: boolean | string[];
|
|
999
|
-
};
|
|
1000
|
-
declare type WithArgs = [string, ColumnsShape, RawExpression] | [string, WithArgsOptions, ColumnsShape, RawExpression] | [string, Query | ((qb: Db) => Query)] | [string, WithArgsOptions, Query | ((qb: Db) => Query)];
|
|
1001
|
-
declare type WithShape<Args extends WithArgs> = Args[1] extends Query ? Args[1]['result'] : Args[1] extends (qb: Db) => Query ? ReturnType<Args[1]>['result'] : Args[2] extends Query ? Args[2]['result'] : Args[2] extends (qb: Db) => Query ? ReturnType<Args[2]>['result'] : Args[1] extends ColumnsShape ? Args[1] : Args[2] extends ColumnsShape ? Args[2] : Args[2] extends (t: ColumnTypes) => ColumnsShape ? ReturnType<Args[2]> : never;
|
|
1002
|
-
declare type WithResult<T extends Query, Args extends WithArgs, Shape extends ColumnsShape> = AddQueryWith<T, {
|
|
1003
|
-
table: Args[0];
|
|
1004
|
-
shape: Shape;
|
|
1005
|
-
type: ColumnShapeOutput<Shape>;
|
|
1006
|
-
}>;
|
|
1007
|
-
declare class With {
|
|
1008
|
-
with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1009
|
-
_with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
declare type NestedInsertOneItem = {
|
|
1013
|
-
create?: Record<string, unknown>;
|
|
1014
|
-
connect?: WhereArg<QueryBase>;
|
|
1015
|
-
connectOrCreate?: {
|
|
1016
|
-
where: WhereArg<QueryBase>;
|
|
1017
|
-
create: Record<string, unknown>;
|
|
1018
|
-
};
|
|
1019
|
-
};
|
|
1020
|
-
declare type NestedInsertManyItems = {
|
|
1021
|
-
create?: Record<string, unknown>[];
|
|
1022
|
-
connect?: WhereArg<QueryBase>[];
|
|
1023
|
-
connectOrCreate?: {
|
|
1024
|
-
where: WhereArg<QueryBase>;
|
|
1025
|
-
create: Record<string, unknown>;
|
|
1026
|
-
}[];
|
|
1027
|
-
};
|
|
1028
|
-
declare type NestedInsertItem = NestedInsertOneItem | NestedInsertManyItems;
|
|
1029
|
-
declare type BelongsToNestedInsert = (query: Query, relationData: NestedInsertOneItem[]) => Promise<Record<string, unknown>[]>;
|
|
1030
|
-
declare type HasOneNestedInsert = (query: Query, data: [
|
|
1031
|
-
selfData: Record<string, unknown>,
|
|
1032
|
-
relationData: NestedInsertOneItem
|
|
1033
|
-
][]) => Promise<void>;
|
|
1034
|
-
declare type HasManyNestedInsert = (query: Query, data: [
|
|
1035
|
-
selfData: Record<string, unknown>,
|
|
1036
|
-
relationData: NestedInsertManyItems
|
|
1037
|
-
][]) => Promise<void>;
|
|
1038
|
-
declare type NestedUpdateOneItem = {
|
|
1039
|
-
disconnect?: boolean;
|
|
1040
|
-
set?: WhereArg<QueryBase>;
|
|
1041
|
-
delete?: boolean;
|
|
1042
|
-
update?: UpdateData<Query>;
|
|
1043
|
-
upsert?: {
|
|
1044
|
-
update: UpdateData<Query>;
|
|
1045
|
-
create: Record<string, unknown>;
|
|
1046
|
-
};
|
|
1047
|
-
create: Record<string, unknown>;
|
|
1048
|
-
};
|
|
1049
|
-
declare type NestedUpdateManyItems = {
|
|
1050
|
-
disconnect?: MaybeArray<WhereArg<QueryBase>>;
|
|
1051
|
-
set?: MaybeArray<WhereArg<QueryBase>>;
|
|
1052
|
-
delete?: MaybeArray<WhereArg<QueryBase>>;
|
|
1053
|
-
update?: {
|
|
1054
|
-
where: MaybeArray<WhereArg<QueryBase>>;
|
|
1055
|
-
data: UpdateData<Query>;
|
|
1056
|
-
};
|
|
1057
|
-
create: Record<string, unknown>[];
|
|
1058
|
-
};
|
|
1059
|
-
declare type NestedUpdateItem = NestedUpdateOneItem | NestedUpdateManyItems;
|
|
1060
|
-
declare type BelongsToNestedUpdate = (q: Query, update: Record<string, unknown>, params: NestedUpdateOneItem, state: {
|
|
1061
|
-
updateLater?: Record<string, unknown>;
|
|
1062
|
-
updateLaterPromises?: Promise<void>[];
|
|
1063
|
-
}) => boolean;
|
|
1064
|
-
declare type HasOneNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateOneItem) => Promise<void>;
|
|
1065
|
-
declare type HasManyNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateManyItems) => Promise<void>;
|
|
1066
|
-
declare type BaseRelation = {
|
|
1067
|
-
type: string;
|
|
1068
|
-
key: string;
|
|
1069
|
-
model: QueryWithTable;
|
|
1070
|
-
query: QueryWithTable;
|
|
1071
|
-
joinQuery(fromQuery: QueryBase, toQuery: Query): Query;
|
|
1072
|
-
nestedCreateQuery: Query;
|
|
1073
|
-
nestedInsert?: BelongsToNestedInsert | HasOneNestedInsert | HasManyNestedInsert;
|
|
1074
|
-
nestedUpdate?: BelongsToNestedUpdate | HasOneNestedUpdate | HasManyNestedUpdate;
|
|
1075
|
-
primaryKey: string;
|
|
1076
|
-
options: {
|
|
1077
|
-
scope?(q: QueryWithTable): QueryWithTable;
|
|
1078
|
-
required?: boolean;
|
|
1079
|
-
};
|
|
1080
|
-
};
|
|
1081
|
-
interface BelongsToRelation extends BaseRelation {
|
|
1082
|
-
type: 'belongsTo';
|
|
1083
|
-
returns: 'one';
|
|
1084
|
-
options: BaseRelation['options'] & {
|
|
1085
|
-
primaryKey: string;
|
|
1086
|
-
foreignKey: string;
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
interface HasOneRelation extends BaseRelation {
|
|
1090
|
-
type: 'hasOne';
|
|
1091
|
-
returns: 'one';
|
|
1092
|
-
options: BaseRelation['options'] & ({
|
|
1093
|
-
primaryKey: string;
|
|
1094
|
-
foreignKey: string;
|
|
1095
|
-
} | {
|
|
1096
|
-
through: string;
|
|
1097
|
-
source: string;
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
interface HasManyRelation extends BaseRelation {
|
|
1101
|
-
type: 'hasMany';
|
|
1102
|
-
returns: 'many';
|
|
1103
|
-
options: BaseRelation['options'] & ({
|
|
1104
|
-
primaryKey: string;
|
|
1105
|
-
foreignKey: string;
|
|
1106
|
-
} | {
|
|
1107
|
-
through: string;
|
|
1108
|
-
source: string;
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
interface HasAndBelongsToManyRelation extends BaseRelation {
|
|
1112
|
-
type: 'hasAndBelongsToMany';
|
|
1113
|
-
returns: 'many';
|
|
1114
|
-
options: BaseRelation['options'] & {
|
|
1115
|
-
primaryKey: string;
|
|
1116
|
-
foreignKey: string;
|
|
1117
|
-
associationPrimaryKey: string;
|
|
1118
|
-
associationForeignKey: string;
|
|
1119
|
-
joinTable: string;
|
|
1120
|
-
};
|
|
859
|
+
}[keyof Shape], true>;
|
|
1121
860
|
}
|
|
1122
|
-
declare
|
|
1123
|
-
declare type RelationsBase = Record<never, Relation>;
|
|
1124
|
-
declare type relationQueryKey = typeof relationQueryKey;
|
|
1125
|
-
declare const relationQueryKey: unique symbol;
|
|
1126
|
-
declare type isRequiredRelationKey = typeof isRequiredRelationKey;
|
|
1127
|
-
declare const isRequiredRelationKey: unique symbol;
|
|
1128
|
-
declare type RelationQueryBase = Query & {
|
|
1129
|
-
[relationQueryKey]: string;
|
|
1130
|
-
[isRequiredRelationKey]: boolean;
|
|
1131
|
-
};
|
|
1132
|
-
declare type RelationQuery<RelationName extends PropertyKey = string, Params extends Record<string, unknown> = never, Populate extends string = never, T extends Query = Query, Required extends boolean = boolean, Q extends RelationQueryBase = Omit<T, 'tableAlias'> & {
|
|
1133
|
-
tableAlias: RelationName extends string ? RelationName : never;
|
|
1134
|
-
[isRequiredRelationKey]: Required;
|
|
1135
|
-
[relationQueryKey]: string;
|
|
1136
|
-
}> = ((params: Params) => Q & {
|
|
1137
|
-
[defaultsKey]: Record<Populate, true>;
|
|
1138
|
-
}) & Q;
|
|
1139
|
-
|
|
1140
|
-
declare type Sql = {
|
|
1141
|
-
text: string;
|
|
1142
|
-
values: unknown[];
|
|
1143
|
-
};
|
|
1144
|
-
declare const queryKeysOfNotSimpleQuery: (keyof SelectQueryData)[];
|
|
1145
|
-
declare type CommonQueryData = {
|
|
861
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> implements Query {
|
|
1146
862
|
adapter: Adapter;
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
as?: string;
|
|
1159
|
-
from?: string | Query | RawExpression;
|
|
1160
|
-
and?: WhereItem[];
|
|
1161
|
-
or?: WhereItem[][];
|
|
1162
|
-
coalesceValue?: unknown | RawExpression;
|
|
1163
|
-
parsers?: ColumnsParsers;
|
|
1164
|
-
notFoundDefault?: unknown;
|
|
1165
|
-
defaults?: Record<string, unknown>;
|
|
1166
|
-
beforeQuery?: BeforeCallback[];
|
|
1167
|
-
afterQuery?: AfterCallback[];
|
|
1168
|
-
log?: QueryLogObject;
|
|
1169
|
-
logger: QueryLogger;
|
|
1170
|
-
[toSqlCacheKey]?: Sql;
|
|
1171
|
-
};
|
|
1172
|
-
declare type SelectQueryData = CommonQueryData & {
|
|
1173
|
-
type: undefined;
|
|
1174
|
-
distinct?: Expression[];
|
|
1175
|
-
fromOnly?: boolean;
|
|
1176
|
-
join?: JoinItem[];
|
|
1177
|
-
joinedParsers?: Record<string, ColumnsParsers>;
|
|
1178
|
-
group?: (string | RawExpression)[];
|
|
1179
|
-
having?: HavingItem[];
|
|
1180
|
-
havingOr?: HavingItem[][];
|
|
1181
|
-
window?: WindowItem[];
|
|
1182
|
-
union?: {
|
|
1183
|
-
arg: UnionItem;
|
|
1184
|
-
kind: UnionKind;
|
|
1185
|
-
wrap?: boolean;
|
|
1186
|
-
}[];
|
|
1187
|
-
order?: OrderItem[];
|
|
1188
|
-
limit?: number;
|
|
1189
|
-
offset?: number;
|
|
1190
|
-
for?: {
|
|
1191
|
-
type: 'UPDATE' | 'NO KEY UPDATE' | 'SHARE' | 'KEY SHARE';
|
|
1192
|
-
tableNames?: string[] | RawExpression;
|
|
1193
|
-
mode?: 'NO WAIT' | 'SKIP LOCKED';
|
|
1194
|
-
};
|
|
1195
|
-
};
|
|
1196
|
-
declare type InsertQueryData = CommonQueryData & {
|
|
1197
|
-
type: 'insert';
|
|
1198
|
-
columns: string[];
|
|
1199
|
-
values: unknown[][] | RawExpression;
|
|
1200
|
-
using?: JoinItem[];
|
|
1201
|
-
join?: JoinItem[];
|
|
1202
|
-
joinedParsers?: Record<string, ColumnsParsers>;
|
|
1203
|
-
onConflict?: {
|
|
1204
|
-
type: 'ignore';
|
|
1205
|
-
expr?: OnConflictItem;
|
|
1206
|
-
} | {
|
|
1207
|
-
type: 'merge';
|
|
1208
|
-
expr?: OnConflictItem;
|
|
1209
|
-
update?: OnConflictMergeUpdate;
|
|
1210
|
-
};
|
|
1211
|
-
beforeInsert?: BeforeCallback[];
|
|
1212
|
-
afterInsert?: AfterCallback[];
|
|
1213
|
-
};
|
|
1214
|
-
declare type UpdateQueryDataObject = Record<string, RawExpression | {
|
|
1215
|
-
op: string;
|
|
1216
|
-
arg: unknown;
|
|
1217
|
-
} | unknown>;
|
|
1218
|
-
declare type UpdatedAtDataInjector = (data: UpdateQueryDataItem[]) => UpdateQueryDataItem | void;
|
|
1219
|
-
declare type UpdateQueryDataItem = UpdateQueryDataObject | RawExpression | UpdatedAtDataInjector;
|
|
1220
|
-
declare type UpdateQueryData = CommonQueryData & {
|
|
1221
|
-
type: 'update';
|
|
1222
|
-
updateData: UpdateQueryDataItem[];
|
|
1223
|
-
beforeUpdate?: BeforeCallback[];
|
|
1224
|
-
afterUpdate?: AfterCallback[];
|
|
1225
|
-
};
|
|
1226
|
-
declare type DeleteQueryData = CommonQueryData & {
|
|
1227
|
-
type: 'delete';
|
|
1228
|
-
join?: JoinItem[];
|
|
1229
|
-
joinedParsers?: Record<string, ColumnsParsers>;
|
|
1230
|
-
beforeDelete?: BeforeCallback[];
|
|
1231
|
-
afterDelete?: AfterCallback[];
|
|
1232
|
-
};
|
|
1233
|
-
declare type TruncateQueryData = CommonQueryData & {
|
|
1234
|
-
type: 'truncate';
|
|
1235
|
-
restartIdentity?: boolean;
|
|
1236
|
-
cascade?: boolean;
|
|
863
|
+
queryBuilder: Db;
|
|
864
|
+
table: Table;
|
|
865
|
+
shape: Shape;
|
|
866
|
+
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
867
|
+
onQueryBuilder: typeof OnQueryBuilder;
|
|
868
|
+
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, options: DbTableOptions);
|
|
869
|
+
}
|
|
870
|
+
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
871
|
+
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
872
|
+
adapter: Adapter;
|
|
873
|
+
close: Adapter['close'];
|
|
1237
874
|
};
|
|
1238
|
-
declare type
|
|
1239
|
-
|
|
1240
|
-
|
|
875
|
+
declare type DbOptions<CT extends ColumnTypesBase> = ({
|
|
876
|
+
adapter: Adapter;
|
|
877
|
+
} | Omit<AdapterOptions, 'log'>) & QueryLogOptions & {
|
|
878
|
+
columnTypes: CT;
|
|
1241
879
|
};
|
|
1242
|
-
declare
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
query: Query | RawExpression
|
|
1247
|
-
];
|
|
1248
|
-
declare type WithOptions = {
|
|
1249
|
-
columns?: string[];
|
|
1250
|
-
recursive?: true;
|
|
1251
|
-
materialized?: true;
|
|
1252
|
-
notMaterialized?: true;
|
|
880
|
+
declare const createDb: <CT extends ColumnTypesBase>({ log, logger, columnTypes: ct, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
881
|
+
|
|
882
|
+
declare type WithArgsOptions = Omit<WithOptions, 'columns'> & {
|
|
883
|
+
columns?: boolean | string[];
|
|
1253
884
|
};
|
|
1254
|
-
declare type
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
885
|
+
declare type WithArgs = [string, ColumnsShape, RawExpression] | [string, WithArgsOptions, ColumnsShape, RawExpression] | [string, Query | ((qb: Db) => Query)] | [string, WithArgsOptions, Query | ((qb: Db) => Query)];
|
|
886
|
+
declare type WithShape<Args extends WithArgs> = Args[1] extends Query ? Args[1]['result'] : Args[1] extends (qb: Db) => Query ? ReturnType<Args[1]>['result'] : Args[2] extends Query ? Args[2]['result'] : Args[2] extends (qb: Db) => Query ? ReturnType<Args[2]>['result'] : Args[1] extends ColumnsShape ? Args[1] : Args[2] extends ColumnsShape ? Args[2] : Args[2] extends (t: ColumnTypes) => ColumnsShape ? ReturnType<Args[2]> : never;
|
|
887
|
+
declare type WithResult<T extends Query, Args extends WithArgs, Shape extends ColumnsShape> = AddQueryWith<T, {
|
|
888
|
+
table: Args[0];
|
|
889
|
+
shape: Shape;
|
|
890
|
+
type: ColumnShapeOutput<Shape>;
|
|
891
|
+
}>;
|
|
892
|
+
declare class With {
|
|
893
|
+
with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
894
|
+
_with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
declare type UnionArg<T extends Query> = (Omit<Query, 'result'> & {
|
|
898
|
+
result: T['result'];
|
|
899
|
+
}) | RawExpression;
|
|
900
|
+
declare class Union {
|
|
901
|
+
union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
902
|
+
_union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
903
|
+
unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
904
|
+
_unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
905
|
+
intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
906
|
+
_intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
907
|
+
intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
908
|
+
_intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
909
|
+
except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
910
|
+
_except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
911
|
+
exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
912
|
+
_exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
declare type JsonColumnName<T extends Pick<Query, 'selectable'>> = StringKey<{
|
|
916
|
+
[K in keyof T['selectable']]: T['selectable'][K]['column']['dataType'] extends 'jsonb' ? K : never;
|
|
917
|
+
}[keyof T['selectable']]>;
|
|
918
|
+
declare type ColumnOrJsonMethod<T extends Query> = JsonColumnName<T> | JsonItem;
|
|
919
|
+
declare type JsonSetResult<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string, Type extends ColumnType = Column extends keyof T['shape'] ? T['shape'][Column] : Column extends JsonItem ? Column['__json'][2] : ColumnType> = JsonItem<As, Type> & (Type extends ColumnType ? AddQuerySelect<T, Record<As, Type>> : T);
|
|
920
|
+
declare type JsonPathQueryResult<T extends Query, As extends string, Type extends ColumnType> = JsonItem & AddQuerySelect<T, {
|
|
921
|
+
[K in As]: Type;
|
|
922
|
+
}>;
|
|
923
|
+
declare class Json {
|
|
924
|
+
json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
925
|
+
_json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
926
|
+
jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
927
|
+
as?: As;
|
|
928
|
+
createIfMissing?: boolean;
|
|
929
|
+
}): JsonSetResult<T, Column, As>;
|
|
930
|
+
_jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
931
|
+
as?: As;
|
|
932
|
+
createIfMissing?: boolean;
|
|
933
|
+
}): JsonSetResult<T, Column, As>;
|
|
934
|
+
jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
935
|
+
column: Column,
|
|
1260
936
|
path: Array<string | number>,
|
|
1261
937
|
value: unknown,
|
|
1262
938
|
options?: {
|
|
1263
|
-
|
|
939
|
+
as?: As;
|
|
940
|
+
insertAfter?: boolean;
|
|
1264
941
|
}
|
|
1265
|
-
]
|
|
1266
|
-
|
|
1267
|
-
as
|
|
1268
|
-
|
|
1269
|
-
|
|
942
|
+
]): JsonSetResult<T, Column, As>;
|
|
943
|
+
_jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
944
|
+
as?: As;
|
|
945
|
+
insertAfter?: boolean;
|
|
946
|
+
}): JsonSetResult<T, Column, As>;
|
|
947
|
+
jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
948
|
+
column: Column,
|
|
1270
949
|
path: Array<string | number>,
|
|
1271
|
-
value: unknown,
|
|
1272
950
|
options?: {
|
|
1273
|
-
|
|
951
|
+
as?: As;
|
|
1274
952
|
}
|
|
1275
|
-
]
|
|
1276
|
-
|
|
1277
|
-
as
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
path: Array<string | number>
|
|
1281
|
-
] | [
|
|
1282
|
-
kind: 'pathQuery',
|
|
1283
|
-
as: As,
|
|
953
|
+
]): JsonSetResult<T, Column, As>;
|
|
954
|
+
_jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, options?: {
|
|
955
|
+
as?: As;
|
|
956
|
+
}): JsonSetResult<T, Column, As>;
|
|
957
|
+
jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, ...args: [
|
|
1284
958
|
type: Type,
|
|
1285
|
-
column:
|
|
959
|
+
column: ColumnOrJsonMethod<T>,
|
|
1286
960
|
path: string,
|
|
961
|
+
as: As,
|
|
1287
962
|
options?: {
|
|
1288
963
|
vars?: string;
|
|
1289
964
|
silent?: boolean;
|
|
1290
965
|
}
|
|
1291
|
-
]
|
|
966
|
+
]): JsonPathQueryResult<T, As, Type>;
|
|
967
|
+
_jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, type: Type, column: ColumnOrJsonMethod<T>, path: string, as: As, options?: {
|
|
968
|
+
vars?: string;
|
|
969
|
+
silent?: boolean;
|
|
970
|
+
}): JsonPathQueryResult<T, As, Type>;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
declare type InsertData<T extends Query, DefaultKeys extends PropertyKey = keyof T[defaultsKey], Data = SetOptional<T['inputType'], DefaultKeys>> = [keyof T['relations']] extends [never] ? Data : OmitBelongsToForeignKeys<T['relations'], Data> & InsertRelationData<T>;
|
|
974
|
+
declare type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<Data, {
|
|
975
|
+
[K in keyof R]: R[K] extends BelongsToRelation ? R[K]['options']['foreignKey'] : never;
|
|
976
|
+
}[keyof R]>;
|
|
977
|
+
declare type InsertRelationData<T extends Query> = {
|
|
978
|
+
[K in keyof T['relations']]: T['relations'][K] extends BelongsToRelation ? InsertBelongsToData<T, K, T['relations'][K]> : T['relations'][K] extends HasOneRelation ? InsertHasOneData<T, K, T['relations'][K]> : T['relations'][K] extends HasManyRelation | HasAndBelongsToManyRelation ? InsertHasManyData<T, K, T['relations'][K]> : EmptyObject;
|
|
979
|
+
}[keyof T['relations']];
|
|
980
|
+
declare type InsertBelongsToData<T extends Query, Key extends keyof T['relations'], Rel extends BelongsToRelation> = SetOptional<{
|
|
981
|
+
[K in Rel['options']['foreignKey']]: Rel['options']['foreignKey'] extends keyof T['inputType'] ? T['inputType'][Rel['options']['foreignKey']] : never;
|
|
982
|
+
}, keyof T[defaultsKey]> | {
|
|
983
|
+
[K in Key]: {
|
|
984
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
985
|
+
connect?: never;
|
|
986
|
+
connectOrCreate?: never;
|
|
987
|
+
} | {
|
|
988
|
+
create?: never;
|
|
989
|
+
connect: WhereArg<Rel['model']>;
|
|
990
|
+
connectOrCreate?: never;
|
|
991
|
+
} | {
|
|
992
|
+
create?: never;
|
|
993
|
+
connect?: never;
|
|
994
|
+
connectOrCreate: {
|
|
995
|
+
where: WhereArg<Rel['model']>;
|
|
996
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
997
|
+
};
|
|
998
|
+
};
|
|
1292
999
|
};
|
|
1293
|
-
declare type
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1000
|
+
declare type InsertHasOneData<T extends Query, Key extends keyof T['relations'], Rel extends HasOneRelation> = 'through' extends Rel['options'] ? {} : {
|
|
1001
|
+
[K in Key]?: {
|
|
1002
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1003
|
+
connect?: never;
|
|
1004
|
+
connectOrCreate?: never;
|
|
1005
|
+
} | {
|
|
1006
|
+
create?: never;
|
|
1007
|
+
connect: WhereArg<Rel['model']>;
|
|
1008
|
+
connectOrCreate?: never;
|
|
1009
|
+
} | {
|
|
1010
|
+
create?: never;
|
|
1011
|
+
connect?: never;
|
|
1012
|
+
connectOrCreate: {
|
|
1013
|
+
where?: WhereArg<Rel['model']>;
|
|
1014
|
+
create?: InsertData<Rel['nestedCreateQuery']>;
|
|
1015
|
+
};
|
|
1016
|
+
};
|
|
1300
1017
|
};
|
|
1301
|
-
declare type
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
] | [
|
|
1311
|
-
arg: string | QueryWithTable,
|
|
1312
|
-
leftColumn: string | RawExpression,
|
|
1313
|
-
op: string,
|
|
1314
|
-
rightColumn: string | RawExpression
|
|
1315
|
-
];
|
|
1018
|
+
declare type InsertHasManyData<T extends Query, Key extends keyof T['relations'], Rel extends HasManyRelation | HasAndBelongsToManyRelation> = 'through' extends Rel['options'] ? {} : {
|
|
1019
|
+
[K in Key]?: {
|
|
1020
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
1021
|
+
connect?: WhereArg<Rel['model']>[];
|
|
1022
|
+
connectOrCreate?: {
|
|
1023
|
+
where: WhereArg<Rel['model']>;
|
|
1024
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1025
|
+
}[];
|
|
1026
|
+
};
|
|
1316
1027
|
};
|
|
1317
|
-
declare type
|
|
1318
|
-
NOT?: MaybeArray<WhereItem>;
|
|
1319
|
-
AND?: MaybeArray<WhereItem>;
|
|
1320
|
-
OR?: MaybeArray<WhereItem>[];
|
|
1321
|
-
IN?: MaybeArray<WhereInItem>;
|
|
1322
|
-
EXISTS?: MaybeArray<JoinItem['args']>;
|
|
1323
|
-
ON?: WhereOnItem | WhereJsonPathEqualsItem;
|
|
1324
|
-
}) | ((q: unknown) => QueryBase) | Query | RawExpression;
|
|
1325
|
-
declare type WhereInItem = {
|
|
1028
|
+
declare type InsertRawData = {
|
|
1326
1029
|
columns: string[];
|
|
1327
|
-
values:
|
|
1328
|
-
};
|
|
1329
|
-
declare type WhereJsonPathEqualsItem = [
|
|
1330
|
-
leftColumn: string,
|
|
1331
|
-
leftPath: string,
|
|
1332
|
-
rightColumn: string,
|
|
1333
|
-
rightPath: string
|
|
1334
|
-
];
|
|
1335
|
-
declare type WhereOnItem = {
|
|
1336
|
-
joinFrom: WhereOnJoinItem;
|
|
1337
|
-
joinTo: WhereOnJoinItem;
|
|
1338
|
-
on: [leftFullColumn: string, rightFullColumn: string] | [leftFullColumn: string, op: string, rightFullColumn: string];
|
|
1030
|
+
values: RawExpression;
|
|
1339
1031
|
};
|
|
1340
|
-
declare type
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1032
|
+
declare type InsertOneResult<T extends Query> = T['hasSelect'] extends true ? QueryReturnsAll<T['returnType']> extends true ? SetQueryReturnsOne<T> : T['returnType'] extends 'one' ? SetQueryReturnsOne<T> : T : SetQueryReturnsRowCount<T>;
|
|
1033
|
+
declare type InsertManyResult<T extends Query> = T['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAll<T> : T : SetQueryReturnsRowCount<T>;
|
|
1034
|
+
declare type OnConflictArg<T extends Query> = keyof T['shape'] | (keyof T['shape'])[] | RawExpression;
|
|
1035
|
+
declare class Insert {
|
|
1036
|
+
insert<T extends Query>(this: T, data: InsertData<T>): InsertOneResult<T>;
|
|
1037
|
+
_insert<T extends Query>(this: T, data: InsertData<T>): InsertOneResult<T>;
|
|
1038
|
+
insertMany<T extends Query>(this: T, data: InsertData<T>[]): InsertManyResult<T>;
|
|
1039
|
+
_insertMany<T extends Query>(this: T, data: InsertData<T>[]): InsertManyResult<T>;
|
|
1040
|
+
insertRaw<T extends Query>(this: T, data: InsertRawData): InsertManyResult<T>;
|
|
1041
|
+
_insertRaw<T extends Query>(this: T, data: InsertRawData): InsertManyResult<T>;
|
|
1042
|
+
create<T extends Query>(this: T, data: InsertData<T>): SetQueryReturnsOne<T>;
|
|
1043
|
+
_create<T extends Query>(this: T, data: InsertData<T>): SetQueryReturnsOne<T>;
|
|
1044
|
+
createMany<T extends Query>(this: T, data: InsertData<T>[]): SetQueryReturnsAll<T>;
|
|
1045
|
+
_createMany<T extends Query>(this: T, data: InsertData<T>[]): SetQueryReturnsAll<T>;
|
|
1046
|
+
createRaw<T extends Query>(this: T, data: InsertRawData): SetQueryReturnsAll<T>;
|
|
1047
|
+
_createRaw<T extends Query>(this: T, data: InsertRawData): SetQueryReturnsAll<T>;
|
|
1048
|
+
defaults<T extends Query, Data extends Partial<InsertData<T>>>(this: T, data: Data): T & {
|
|
1049
|
+
[defaultsKey]: Record<keyof Data, true>;
|
|
1344
1050
|
};
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
options: AggregateItemOptions;
|
|
1366
|
-
};
|
|
1367
|
-
declare type ColumnOperators<S extends SelectableBase, Column extends keyof S> = {
|
|
1368
|
-
[O in keyof S[Column]['column']['operators']]?: S[Column]['column']['operators'][O]['type'];
|
|
1051
|
+
_defaults<T extends Query, Data extends Partial<InsertData<T>>>(this: T, data: Data): T & {
|
|
1052
|
+
[defaultsKey]: Record<keyof Data, true>;
|
|
1053
|
+
};
|
|
1054
|
+
onConflict<T extends Query, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): OnConflictQueryBuilder<T, Arg>;
|
|
1055
|
+
_onConflict<T extends Query, Arg extends OnConflictArg<T> | undefined = undefined>(this: T, arg?: Arg): OnConflictQueryBuilder<T, Arg>;
|
|
1056
|
+
}
|
|
1057
|
+
declare class OnConflictQueryBuilder<T extends Query, Arg extends OnConflictArg<T> | undefined> {
|
|
1058
|
+
private query;
|
|
1059
|
+
private onConflict;
|
|
1060
|
+
constructor(query: T, onConflict: Arg);
|
|
1061
|
+
ignore(): T;
|
|
1062
|
+
merge(update?: keyof T['shape'] | (keyof T['shape'])[] | Partial<T['inputType']> | RawExpression): T;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
declare type UpdateData<T extends Query> = {
|
|
1066
|
+
[K in keyof T['type']]?: T['type'][K] | RawExpression;
|
|
1067
|
+
} & (T['relations'] extends Record<string, Relation> ? {
|
|
1068
|
+
[K in keyof T['relations']]?: T['relations'][K] extends BelongsToRelation ? UpdateBelongsToData<T, T['relations'][K]> : T['relations'][K] extends HasOneRelation ? UpdateHasOneData<T, T['relations'][K]> : T['relations'][K] extends HasManyRelation ? UpdateHasManyData<T, T['relations'][K]> : T['relations'][K] extends HasAndBelongsToManyRelation ? UpdateHasAndBelongsToManyData<T['relations'][K]> : never;
|
|
1069
|
+
} : EmptyObject) & {
|
|
1070
|
+
__raw?: never;
|
|
1369
1071
|
};
|
|
1370
|
-
declare type
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1072
|
+
declare type UpdateBelongsToData<T extends Query, Rel extends BelongsToRelation> = {
|
|
1073
|
+
disconnect: boolean;
|
|
1074
|
+
} | {
|
|
1075
|
+
set: WhereArg<Rel['model']>;
|
|
1076
|
+
} | {
|
|
1077
|
+
delete: boolean;
|
|
1078
|
+
} | {
|
|
1079
|
+
update: UpdateData<Rel['model']>;
|
|
1080
|
+
} | {
|
|
1081
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1082
|
+
} | (QueryReturnsAll<T['returnType']> extends true ? never : {
|
|
1083
|
+
upsert: {
|
|
1084
|
+
update: UpdateData<Rel['model']>;
|
|
1085
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1086
|
+
};
|
|
1087
|
+
});
|
|
1088
|
+
declare type UpdateHasOneData<T extends Query, Rel extends HasOneRelation> = {
|
|
1089
|
+
disconnect: boolean;
|
|
1090
|
+
} | {
|
|
1091
|
+
delete: boolean;
|
|
1092
|
+
} | {
|
|
1093
|
+
update: UpdateData<Rel['model']>;
|
|
1094
|
+
} | (QueryReturnsAll<T['returnType']> extends true ? never : {
|
|
1095
|
+
set: WhereArg<Rel['model']>;
|
|
1096
|
+
} | {
|
|
1097
|
+
upsert: {
|
|
1098
|
+
update: UpdateData<Rel['model']>;
|
|
1099
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1100
|
+
};
|
|
1101
|
+
} | {
|
|
1102
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
1103
|
+
});
|
|
1104
|
+
declare type UpdateHasManyData<T extends Query, Rel extends HasManyRelation> = {
|
|
1105
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1106
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1107
|
+
update?: {
|
|
1108
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
1109
|
+
data: UpdateData<Rel['model']>;
|
|
1110
|
+
};
|
|
1111
|
+
} & (QueryReturnsAll<T['returnType']> extends true ? EmptyObject : {
|
|
1112
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1113
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
1114
|
+
});
|
|
1115
|
+
declare type UpdateHasAndBelongsToManyData<Rel extends HasAndBelongsToManyRelation> = {
|
|
1116
|
+
disconnect?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1117
|
+
set?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1118
|
+
delete?: MaybeArray<WhereArg<Rel['model']>>;
|
|
1119
|
+
update?: {
|
|
1120
|
+
where: MaybeArray<WhereArg<Rel['model']>>;
|
|
1121
|
+
data: UpdateData<Rel['model']>;
|
|
1122
|
+
};
|
|
1123
|
+
create?: InsertData<Rel['nestedCreateQuery']>[];
|
|
1378
1124
|
};
|
|
1379
|
-
declare type
|
|
1380
|
-
declare type
|
|
1381
|
-
declare type
|
|
1382
|
-
declare type
|
|
1125
|
+
declare type UpdateArgs<T extends Query, ForceAll extends boolean> = (T['hasWhere'] extends true ? true : ForceAll) extends true ? [update: UpdateData<T>] : [update: UpdateData<T>, forceAll: true];
|
|
1126
|
+
declare type UpdateRawArgs<T extends Query, ForceAll extends boolean> = (T['hasWhere'] extends true ? true : ForceAll) extends true ? [update: RawExpression] : [update: RawExpression, forceAll: true];
|
|
1127
|
+
declare type UpdateResult<T extends Query> = T['hasSelect'] extends true ? T : SetQueryReturnsRowCount<T>;
|
|
1128
|
+
declare type ChangeCountArg<T extends Query> = keyof T['shape'] | Partial<Record<keyof T['shape'], number>>;
|
|
1129
|
+
declare class Update {
|
|
1130
|
+
update<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateArgs<T, ForceAll>): UpdateResult<T>;
|
|
1131
|
+
_update<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateArgs<T, ForceAll>): UpdateResult<T>;
|
|
1132
|
+
updateRaw<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateRawArgs<T, ForceAll>): UpdateResult<T>;
|
|
1133
|
+
_updateRaw<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateRawArgs<T, ForceAll>): UpdateResult<T>;
|
|
1134
|
+
updateOrThrow<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateArgs<T, ForceAll>): UpdateResult<T>;
|
|
1135
|
+
_updateOrThrow<T extends Query, ForceAll extends boolean = false>(this: T, ...args: UpdateArgs<T, ForceAll>): UpdateResult<T>;
|
|
1136
|
+
increment<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
1137
|
+
_increment<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
1138
|
+
decrement<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
1139
|
+
_decrement<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
1140
|
+
}
|
|
1383
1141
|
|
|
1384
|
-
declare type
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1142
|
+
declare type DeleteArgs<T extends Query> = T['hasWhere'] extends true ? [forceAll?: boolean] : [true];
|
|
1143
|
+
declare type DeleteResult<T extends Query> = T['hasSelect'] extends true ? T : SetQueryReturnsRowCount<T>;
|
|
1144
|
+
declare class Delete {
|
|
1145
|
+
del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
1146
|
+
_del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
1147
|
+
delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
1148
|
+
_delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
declare class Transaction {
|
|
1152
|
+
transaction<T extends Query, Result>(this: T, cb: (query: T) => Promise<Result>): Promise<Result>;
|
|
1153
|
+
transacting<T extends Query>(this: T, query: Query): T;
|
|
1154
|
+
_transacting<T extends Query>(this: T, query: Query): T;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
declare type ForQueryBuilder<Q extends Query> = Q & {
|
|
1158
|
+
noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
1159
|
+
_noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
1160
|
+
skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
1161
|
+
_skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
1395
1162
|
};
|
|
1396
|
-
declare
|
|
1163
|
+
declare class For {
|
|
1164
|
+
forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1165
|
+
_forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1166
|
+
forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1167
|
+
_forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1168
|
+
forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1169
|
+
_forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1170
|
+
forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1171
|
+
_forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
1172
|
+
}
|
|
1397
1173
|
|
|
1398
|
-
declare type
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
declare type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
|
|
1404
|
-
[P in K]?: P extends keyof T ? T[P] : never;
|
|
1174
|
+
declare type ColumnInfo = {
|
|
1175
|
+
defaultValue: unknown;
|
|
1176
|
+
type: string;
|
|
1177
|
+
maxLength: number | null;
|
|
1178
|
+
nullable: boolean;
|
|
1405
1179
|
};
|
|
1406
|
-
declare
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
declare type
|
|
1412
|
-
declare
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
]>
|
|
1419
|
-
declare type OptionalPropertyNames<T> = {
|
|
1420
|
-
[K in keyof T]-?: {} extends {
|
|
1421
|
-
[P in K]: T[K];
|
|
1422
|
-
} ? K : never;
|
|
1423
|
-
}[keyof T];
|
|
1424
|
-
declare type SpreadProperties<L, R, K extends keyof L & keyof R> = {
|
|
1425
|
-
[P in K]: L[P] | Exclude<R[P], undefined>;
|
|
1180
|
+
declare class ColumnInfoMethods {
|
|
1181
|
+
columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
1182
|
+
_columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
declare type ClearStatement = 'with' | 'select' | 'where' | 'union' | 'using' | 'join' | 'group' | 'order' | 'having' | 'limit' | 'offset' | 'counters';
|
|
1186
|
+
declare class Clear {
|
|
1187
|
+
clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
1188
|
+
_clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
declare type HavingArgObject<T extends Query, Agg extends keyof Aggregate1ArgumentTypes<T>> = {
|
|
1192
|
+
[Column in Exclude<Aggregate1ArgumentTypes<T>[Agg], RawExpression>]?: T['selectable'][Column]['column']['type'] | (ColumnOperators<T['selectable'], Column> & AggregateOptions<T>);
|
|
1426
1193
|
};
|
|
1427
|
-
declare type
|
|
1428
|
-
[
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
...
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
] ? L & SimpleSpread<R> : {};
|
|
1439
|
-
declare type FilterTuple<T extends readonly any[], E> = T extends [
|
|
1440
|
-
infer F,
|
|
1441
|
-
...infer R
|
|
1442
|
-
] ? [F] extends [E] ? [F, ...FilterTuple<R, E>] : FilterTuple<R, E> : [];
|
|
1443
|
-
declare type CoalesceString<Left extends string | undefined, Right extends string> = Left extends undefined ? Right : Left;
|
|
1444
|
-
declare function applyMixins(derivedCtor: any, constructors: any[]): void;
|
|
1445
|
-
declare const joinTruthy: (...strings: (string | false | undefined)[]) => string;
|
|
1446
|
-
declare const getClonedQueryData: (query: QueryData) => QueryData;
|
|
1447
|
-
declare const getQueryAs: (q: {
|
|
1448
|
-
table?: string;
|
|
1449
|
-
query: {
|
|
1450
|
-
as?: string;
|
|
1451
|
-
};
|
|
1452
|
-
}) => string;
|
|
1453
|
-
declare const toArray: <T>(item: T) => T extends unknown[] ? T : [T];
|
|
1454
|
-
declare const noop: () => void;
|
|
1455
|
-
declare type EmptyObject = typeof emptyObject;
|
|
1456
|
-
declare const emptyObject: {};
|
|
1457
|
-
declare const makeRegexToFindInSql: (value: string) => RegExp;
|
|
1458
|
-
declare const pushOrNewArrayToObject: <Obj extends {}, Key extends keyof Obj>(obj: Obj, key: Key, value: Exclude<Obj[Key], undefined> extends unknown[] ? Exclude<Obj[Key], undefined>[number] : never) => void;
|
|
1459
|
-
declare const pushOrNewArray: <Arr extends unknown[]>(arr: Arr | undefined, value: Arr[number]) => Arr;
|
|
1194
|
+
declare type HavingArg<T extends Query = Query> = ({
|
|
1195
|
+
[Agg in keyof Aggregate1ArgumentTypes<T>]?: HavingArgObject<T, Agg>;
|
|
1196
|
+
} & {
|
|
1197
|
+
count?: number | HavingArgObject<T, 'count'>;
|
|
1198
|
+
}) | Query | RawExpression;
|
|
1199
|
+
declare class Having {
|
|
1200
|
+
having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1201
|
+
_having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1202
|
+
havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1203
|
+
_havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1204
|
+
}
|
|
1460
1205
|
|
|
1461
1206
|
declare class Window {
|
|
1462
1207
|
selectRowNumber<T extends Query, As extends string | undefined = undefined>(this: T, options: WindowFunctionOptions<T, As>): SelectAgg<T, 'row_number', As, IntegerColumn>;
|
|
@@ -1471,22 +1216,51 @@ declare class Window {
|
|
|
1471
1216
|
_selectCumeDist<T extends Query, As extends string | undefined = undefined>(this: T, options: WindowFunctionOptions<T, As>): SelectAgg<T, 'cume_dist', As, IntegerColumn>;
|
|
1472
1217
|
}
|
|
1473
1218
|
|
|
1219
|
+
declare type UpsertData<T extends Query> = {
|
|
1220
|
+
update: UpdateData<T>;
|
|
1221
|
+
create: InsertData<T>;
|
|
1222
|
+
};
|
|
1223
|
+
declare type UpsertResult<T extends Query> = T['hasSelect'] extends true ? SetQueryReturnsOne<T> : SetQueryReturnsVoid<T>;
|
|
1224
|
+
declare type UpsertThis = WhereResult<Query> & {
|
|
1225
|
+
returnType: 'one' | 'oneOrThrow';
|
|
1226
|
+
};
|
|
1227
|
+
declare class QueryUpsert {
|
|
1228
|
+
upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
1229
|
+
_upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
declare type MergeQuery<T extends Query, Q extends Query, ReturnType extends QueryReturnType = QueryReturnType extends Q['returnType'] ? T['returnType'] : Q['returnType']> = Omit<T, 'result' | 'returnType' | 'then'> & {
|
|
1233
|
+
hasSelect: Q['hasSelect'] extends true ? true : T['hasSelect'];
|
|
1234
|
+
hasWhere: Q['hasWhere'] extends true ? true : T['hasWhere'];
|
|
1235
|
+
result: T['hasSelect'] extends true ? Spread<[T['result'], Q['result']]> : Q['result'];
|
|
1236
|
+
returnType: ReturnType;
|
|
1237
|
+
then: T['hasSelect'] extends true ? QueryThen<ReturnType, Spread<[T['result'], Q['result']]>> : QueryThen<ReturnType, Q['result']>;
|
|
1238
|
+
selectable: T['selectable'] & Q['selectable'];
|
|
1239
|
+
joinedTables: T['joinedTables'] & Q['joinedTables'];
|
|
1240
|
+
windows: T['windows'] & Q['windows'];
|
|
1241
|
+
withData: T['withData'] & Q['withData'];
|
|
1242
|
+
};
|
|
1243
|
+
declare class MergeQueryMethods {
|
|
1244
|
+
merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
|
|
1245
|
+
_merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1474
1248
|
declare type WindowArg<T extends Query> = Record<string, WindowArgDeclaration<T> | RawExpression>;
|
|
1475
1249
|
declare type WindowArgDeclaration<T extends Query = Query> = {
|
|
1476
1250
|
partitionBy?: Expression<T> | Expression<T>[];
|
|
1477
1251
|
order?: OrderArg<T>;
|
|
1478
1252
|
};
|
|
1479
|
-
declare type WindowResult<T extends Query, W extends WindowArg<T>> = SetQueryWindows<T,
|
|
1253
|
+
declare type WindowResult<T extends Query, W extends WindowArg<T>> = SetQueryWindows<T, Record<keyof W, true>>;
|
|
1480
1254
|
declare type OrderArg<T extends Query> = keyof T['selectable'] | {
|
|
1481
1255
|
[K in Selectable<T>]?: SortDir | {
|
|
1482
1256
|
dir: SortDir;
|
|
1483
1257
|
nulls: 'FIRST' | 'LAST';
|
|
1484
1258
|
};
|
|
1485
1259
|
} | RawExpression;
|
|
1486
|
-
interface QueryMethods extends Aggregate, Select, From, Join, With, Union, Json, Insert, Update, Delete, Transaction, For, ColumnInfoMethods, Where, Clear, Having, Window, Then, QueryLog, QueryCallbacks, QueryUpsert, QueryGet {
|
|
1260
|
+
interface QueryMethods extends Aggregate, Select, From, Join, With, Union, Json, Insert, Update, Delete, Transaction, For, ColumnInfoMethods, Where, Clear, Having, Window, Then, QueryLog, QueryCallbacks, QueryUpsert, QueryGet, MergeQueryMethods {
|
|
1487
1261
|
}
|
|
1488
1262
|
declare class QueryMethods {
|
|
1489
|
-
windows:
|
|
1263
|
+
windows: EmptyObject;
|
|
1490
1264
|
__model: Query;
|
|
1491
1265
|
all<T extends Query>(this: T): SetQueryReturnsAll<T>;
|
|
1492
1266
|
_all<T extends Query>(this: T): SetQueryReturnsAll<T>;
|
|
@@ -1504,10 +1278,10 @@ declare class QueryMethods {
|
|
|
1504
1278
|
toSql(this: Query, options?: ToSqlOptions): Sql;
|
|
1505
1279
|
distinct<T extends Query>(this: T, ...columns: Expression<T>[]): T;
|
|
1506
1280
|
_distinct<T extends Query>(this: T, ...columns: Expression<T>[]): T;
|
|
1507
|
-
find<T extends Query>(this: T,
|
|
1508
|
-
_find<T extends Query>(this: T,
|
|
1509
|
-
findOptional<T extends Query>(this: T,
|
|
1510
|
-
_findOptional<T extends Query>(this: T,
|
|
1281
|
+
find<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOne<WhereResult<T>>;
|
|
1282
|
+
_find<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOne<WhereResult<T>>;
|
|
1283
|
+
findOptional<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
1284
|
+
_findOptional<T extends Query>(this: T, value: T['shape'][T['singlePrimaryKey']]['type'] | RawExpression): SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
1511
1285
|
findBy<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
|
|
1512
1286
|
_findBy<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
|
|
1513
1287
|
findByOptional<T extends Query>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
@@ -1540,6 +1314,136 @@ declare class QueryMethods {
|
|
|
1540
1314
|
}): SetQueryReturnsVoid<T>;
|
|
1541
1315
|
}
|
|
1542
1316
|
|
|
1317
|
+
declare type AggregateArg<T extends Query> = Expression<T> | Record<string, Expression<T>> | [Expression<T>, string];
|
|
1318
|
+
declare type AggregateOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
1319
|
+
as?: As;
|
|
1320
|
+
distinct?: boolean;
|
|
1321
|
+
order?: OrderArg<T> | OrderArg<T>[];
|
|
1322
|
+
filter?: WhereArg<T>;
|
|
1323
|
+
filterOr?: WhereArg<T>[];
|
|
1324
|
+
withinGroup?: boolean;
|
|
1325
|
+
over?: keyof T['windows'] | WindowArgDeclaration<T>;
|
|
1326
|
+
};
|
|
1327
|
+
declare type Aggregate1ArgumentTypes<T extends Query = Query, C extends ColumnType = ColumnType> = {
|
|
1328
|
+
count: Expression<T, C>;
|
|
1329
|
+
avg: NumberExpression<T, C>;
|
|
1330
|
+
min: Expression<T, C>;
|
|
1331
|
+
max: Expression<T, C>;
|
|
1332
|
+
sum: NumberExpression<T, C>;
|
|
1333
|
+
bitAnd: NumberExpression<T, C>;
|
|
1334
|
+
bitOr: NumberExpression<T, C>;
|
|
1335
|
+
boolAnd: BooleanExpression<T, C>;
|
|
1336
|
+
boolOr: BooleanExpression<T, C>;
|
|
1337
|
+
every: BooleanExpression<T, C>;
|
|
1338
|
+
jsonAgg: Expression<T, C>;
|
|
1339
|
+
jsonbAgg: Expression<T, C>;
|
|
1340
|
+
xmlAgg: Expression<T, C>;
|
|
1341
|
+
};
|
|
1342
|
+
declare const aggregate1FunctionNames: {
|
|
1343
|
+
readonly count: "count";
|
|
1344
|
+
readonly avg: "avg";
|
|
1345
|
+
readonly min: "min";
|
|
1346
|
+
readonly max: "max";
|
|
1347
|
+
readonly sum: "sum";
|
|
1348
|
+
readonly bitAnd: "bit_and";
|
|
1349
|
+
readonly bitOr: "bit_or";
|
|
1350
|
+
readonly boolAnd: "bool_and";
|
|
1351
|
+
readonly boolOr: "bool_or";
|
|
1352
|
+
readonly every: "every";
|
|
1353
|
+
readonly jsonAgg: "json_agg";
|
|
1354
|
+
readonly jsonbAgg: "jsonb_agg";
|
|
1355
|
+
readonly xmlAgg: "xmlagg";
|
|
1356
|
+
};
|
|
1357
|
+
declare type SelectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType> = AddQuerySelect<T, Record<CoalesceString<As, Func>, Value>>;
|
|
1358
|
+
declare type AT1<T extends Query> = Aggregate1ArgumentTypes<T>;
|
|
1359
|
+
declare type WindowFunctionOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
1360
|
+
as?: As;
|
|
1361
|
+
} & WindowArgDeclaration<T>;
|
|
1362
|
+
declare class Aggregate {
|
|
1363
|
+
selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>): SelectAgg<T, Func, As, Value>;
|
|
1364
|
+
_selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>, columnType?: ColumnType): SelectAgg<T, Func, As, Value>;
|
|
1365
|
+
count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
1366
|
+
_count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
1367
|
+
selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
1368
|
+
_selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
1369
|
+
avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1370
|
+
_avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1371
|
+
selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
1372
|
+
_selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
1373
|
+
min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1374
|
+
_min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1375
|
+
selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
1376
|
+
_selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
1377
|
+
max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1378
|
+
_max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1379
|
+
selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
1380
|
+
_selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
1381
|
+
sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1382
|
+
_sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1383
|
+
selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
1384
|
+
_selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
1385
|
+
bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1386
|
+
_bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1387
|
+
selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
1388
|
+
_selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
1389
|
+
bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1390
|
+
_bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
1391
|
+
selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
1392
|
+
_selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
1393
|
+
boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1394
|
+
_boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1395
|
+
selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
1396
|
+
_selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
1397
|
+
boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1398
|
+
_boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1399
|
+
selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
1400
|
+
_selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
1401
|
+
every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1402
|
+
_every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
1403
|
+
selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
1404
|
+
_selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
1405
|
+
jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1406
|
+
_jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1407
|
+
selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1408
|
+
_selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1409
|
+
jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1410
|
+
_jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1411
|
+
selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1412
|
+
_selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
1413
|
+
xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
1414
|
+
_xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
1415
|
+
selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
1416
|
+
_selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
1417
|
+
jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
1418
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1419
|
+
}>>>;
|
|
1420
|
+
_jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
1421
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1422
|
+
}>>>;
|
|
1423
|
+
selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
1424
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1425
|
+
}>>>;
|
|
1426
|
+
_selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
1427
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1428
|
+
}>>>;
|
|
1429
|
+
jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
1430
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1431
|
+
}>>>;
|
|
1432
|
+
_jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
1433
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1434
|
+
}>>>;
|
|
1435
|
+
selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
1436
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1437
|
+
}>>>;
|
|
1438
|
+
_selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
1439
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
1440
|
+
}>>>;
|
|
1441
|
+
stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
1442
|
+
_stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
1443
|
+
selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
1444
|
+
_selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1543
1447
|
declare type ColumnParser = (input: unknown) => unknown;
|
|
1544
1448
|
declare type ColumnsParsers = Record<string | getValueKey, ColumnParser>;
|
|
1545
1449
|
declare type SelectableBase = Record<PropertyKey, {
|
|
@@ -1570,10 +1474,8 @@ declare type Query = QueryMethods & {
|
|
|
1570
1474
|
onQueryBuilder: typeof OnQueryBuilder;
|
|
1571
1475
|
table?: string;
|
|
1572
1476
|
shape: ColumnsShape;
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
primaryTypes: any[];
|
|
1576
|
-
};
|
|
1477
|
+
singlePrimaryKey: string;
|
|
1478
|
+
primaryKeys: string[];
|
|
1577
1479
|
type: Record<string, unknown>;
|
|
1578
1480
|
inputType: Record<string, unknown>;
|
|
1579
1481
|
query: QueryData;
|
|
@@ -1585,7 +1487,7 @@ declare type Query = QueryMethods & {
|
|
|
1585
1487
|
then: ThenResult<unknown>;
|
|
1586
1488
|
tableAlias: string | undefined;
|
|
1587
1489
|
joinedTables: Record<string, Pick<Query, 'result' | 'tableAlias' | 'table'>>;
|
|
1588
|
-
windows:
|
|
1490
|
+
windows: EmptyObject;
|
|
1589
1491
|
defaultSelectColumns: string[];
|
|
1590
1492
|
columnsParsers?: ColumnsParsers;
|
|
1591
1493
|
relations: RelationsBase;
|
|
@@ -1600,21 +1502,23 @@ declare type DefaultSelectColumns<S extends ColumnsShape> = {
|
|
|
1600
1502
|
[K in keyof S]: S[K]['isHidden'] extends true ? never : K;
|
|
1601
1503
|
}[StringKey<keyof S>][];
|
|
1602
1504
|
declare type QueryReturnType = 'all' | 'one' | 'oneOrThrow' | 'rows' | 'pluck' | 'value' | 'valueOrThrow' | 'rowCount' | 'void';
|
|
1505
|
+
declare const queryTypeWithLimitOne: Record<QueryReturnType, true | undefined>;
|
|
1603
1506
|
declare type JoinedTablesBase = Record<string, Pick<Query, 'result' | 'tableAlias' | 'table'>>;
|
|
1604
|
-
declare type
|
|
1507
|
+
declare type QueryReturnsAll<T extends QueryReturnType> = (QueryReturnType extends T ? 'all' : T) extends 'all' ? true : false;
|
|
1508
|
+
declare type QueryThen<ReturnType extends QueryReturnType, Result extends ColumnsShape> = QueryReturnsAll<ReturnType> extends true ? ThenResult<ColumnShapeOutput<Result>[]> : ReturnType extends 'one' ? ThenResult<ColumnShapeOutput<Result> | undefined> : ReturnType extends 'oneOrThrow' ? ThenResult<ColumnShapeOutput<Result>> : ReturnType extends 'value' ? Result extends {
|
|
1605
1509
|
value: ColumnType;
|
|
1606
1510
|
} ? ThenResult<Result['value']['type'] | undefined> : never : ReturnType extends 'valueOrThrow' ? Result extends {
|
|
1607
1511
|
value: ColumnType;
|
|
1608
1512
|
} ? ThenResult<Result['value']['type']> : never : ReturnType extends 'rows' ? ThenResult<ColumnShapeOutput<Result>[keyof Result][][]> : ReturnType extends 'pluck' ? Result extends {
|
|
1609
1513
|
pluck: ColumnType;
|
|
1610
1514
|
} ? ThenResult<Result['pluck']['type'][]> : never : ReturnType extends 'rowCount' ? ThenResult<number> : ReturnType extends 'void' ? ThenResult<void> : never;
|
|
1611
|
-
declare type AddQuerySelect<T extends Pick<Query, 'hasSelect' | 'result' | 'then' | 'returnType'>, Result extends ColumnsShape> = T['hasSelect'] extends
|
|
1515
|
+
declare type AddQuerySelect<T extends Pick<Query, 'hasSelect' | 'result' | 'then' | 'returnType'>, Result extends ColumnsShape> = T['hasSelect'] extends true ? Omit<T, 'result' | 'then'> & {
|
|
1516
|
+
result: Spread<[T['result'], Result]>;
|
|
1517
|
+
then: QueryThen<T['returnType'], Spread<[T['result'], Result]>>;
|
|
1518
|
+
} : Omit<T, 'result' | 'then'> & {
|
|
1612
1519
|
hasSelect: true;
|
|
1613
1520
|
result: Result;
|
|
1614
1521
|
then: QueryThen<T['returnType'], Result>;
|
|
1615
|
-
} : Omit<T, 'result' | 'then'> & {
|
|
1616
|
-
result: Spread<[T['result'], Result]>;
|
|
1617
|
-
then: QueryThen<T['returnType'], Spread<[T['result'], Result]>>;
|
|
1618
1522
|
};
|
|
1619
1523
|
declare type QuerySelectAll<T extends Query> = Omit<T, 'hasSelect' | 'result' | 'then'> & {
|
|
1620
1524
|
hasSelect: true;
|
|
@@ -1690,7 +1594,7 @@ declare type SetQueryWith<T extends Query, WithData extends Record<string, WithD
|
|
|
1690
1594
|
declare type AddQueryWith<T extends Query, With extends WithDataItem> = SetQueryWith<T, Spread<[T['withData'], {
|
|
1691
1595
|
[K in With['table']]: With;
|
|
1692
1596
|
}]>>;
|
|
1693
|
-
declare type SetQueryWindows<T extends Query, W extends
|
|
1597
|
+
declare type SetQueryWindows<T extends Query, W extends EmptyObject> = T & {
|
|
1694
1598
|
windows: W;
|
|
1695
1599
|
};
|
|
1696
1600
|
|
|
@@ -2247,30 +2151,13 @@ declare class ArrayOfColumnsObjects<Shape extends ColumnsShape> extends ColumnTy
|
|
|
2247
2151
|
}
|
|
2248
2152
|
declare abstract class PluckResultColumnType<C extends ColumnType> extends ColumnType<C['type'][], typeof Operators.any> {
|
|
2249
2153
|
}
|
|
2250
|
-
declare type
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
declare type GetPrimaryKeys<S extends ColumnsShape> = UnionToArray<S, {
|
|
2258
|
-
[K in keyof S]: S[K] extends {
|
|
2259
|
-
isPrimaryKey: true;
|
|
2260
|
-
} ? K : never;
|
|
2261
|
-
}[keyof S]>;
|
|
2262
|
-
declare type GetPrimaryTypes<S extends ColumnsShape, Keys extends [...(keyof S | string)[]] = GetPrimaryKeys<S>> = GetTypesFromKeys<S, Keys>;
|
|
2263
|
-
declare type GetTypesFromKeys<S extends ColumnsShape, T extends [...(keyof S)[]]> = T extends [
|
|
2264
|
-
infer Head extends keyof S,
|
|
2265
|
-
...infer Tail extends [...(keyof S)[]]
|
|
2266
|
-
] ? [GetTypeFromKey<S, Head>, ...GetTypesFromKeys<S, Tail>] : [];
|
|
2267
|
-
declare type GetTypeFromKey<S extends ColumnsShape, T extends keyof S> = S[T]['type'];
|
|
2268
|
-
declare class TableSchema<Shape extends ColumnsShape> {
|
|
2269
|
-
shape: Shape;
|
|
2270
|
-
primaryKeys: string extends keyof Shape ? string[] : GetPrimaryKeys<Shape>;
|
|
2271
|
-
primaryTypes: GetPrimaryTypes<Shape>;
|
|
2272
|
-
constructor(shape: Shape);
|
|
2273
|
-
}
|
|
2154
|
+
declare type SinglePrimaryKey<Shape extends ColumnsShape> = StringKey<{
|
|
2155
|
+
[K in keyof Shape]: Shape[K]['isPrimaryKey'] extends true ? [
|
|
2156
|
+
{
|
|
2157
|
+
[S in keyof Shape]: Shape[S]['isPrimaryKey'] extends true ? S extends K ? never : S : never;
|
|
2158
|
+
}[keyof Shape]
|
|
2159
|
+
] extends [never] ? K : never : never;
|
|
2160
|
+
}[keyof Shape]>;
|
|
2274
2161
|
|
|
2275
2162
|
declare type ColumnOutput<T extends ColumnType> = T['type'];
|
|
2276
2163
|
declare type ColumnInput<T extends ColumnType> = T['inputType'];
|
|
@@ -4251,6 +4138,17 @@ declare class ArrayColumn<Item extends ColumnType> extends ColumnType<Item['type
|
|
|
4251
4138
|
parseFn: (input: unknown) => unknown[];
|
|
4252
4139
|
}
|
|
4253
4140
|
|
|
4141
|
+
declare function timestamps<T extends ColumnType>(this: {
|
|
4142
|
+
timestamp(): T;
|
|
4143
|
+
}): {
|
|
4144
|
+
createdAt: T & {
|
|
4145
|
+
hasDefault: true;
|
|
4146
|
+
};
|
|
4147
|
+
updatedAt: T & {
|
|
4148
|
+
hasDefault: true;
|
|
4149
|
+
};
|
|
4150
|
+
};
|
|
4151
|
+
|
|
4254
4152
|
declare type ColumnTypes = typeof columnTypes;
|
|
4255
4153
|
declare type TableData = {
|
|
4256
4154
|
primaryKey?: {
|
|
@@ -4347,7 +4245,6 @@ declare namespace utils {
|
|
|
4347
4245
|
declare type Value = any;
|
|
4348
4246
|
declare const quote: (value: Value) => string;
|
|
4349
4247
|
|
|
4350
|
-
declare const removeFromQuery: <T extends Query>(q: T, key: string) => T;
|
|
4351
4248
|
declare const pushQueryArray: <T extends {
|
|
4352
4249
|
query: QueryData;
|
|
4353
4250
|
}>(q: T, key: string, value: unknown) => T;
|
|
@@ -4371,4 +4268,4 @@ declare class UnhandledTypeError extends PormInternalError {
|
|
|
4371
4268
|
constructor(value: never);
|
|
4372
4269
|
}
|
|
4373
4270
|
|
|
4374
|
-
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg,
|
|
4271
|
+
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SinglePrimaryKey, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|