pqb 0.30.7 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +328 -222
- package/dist/index.js +310 -232
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +308 -231
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as orchid_core from 'orchid-core';
|
|
2
|
-
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, FnUnknownToUnknown, ExpressionChain, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, QueryColumnBooleanOrNull, ExpressionData, ValExpression, PickOutputType, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, PickQueryMetaResult, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, CoreBaseOperators, PickQueryUniqueProperties, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase, PickQueryTableMetaShape } from 'orchid-core';
|
|
2
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, FnUnknownToUnknown, ExpressionChain, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, QueryColumnBooleanOrNull, ExpressionData, ValExpression, PickOutputType, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, PickQueryMetaResult, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, CoreBaseOperators, PickQueryUniqueProperties, IsQuery, PickQueryTableMetaResultInputType, PickQueryMetaShapeResultReturnType, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase, PickQueryTableMetaShape } from 'orchid-core';
|
|
3
3
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -106,11 +106,12 @@ interface QueryBaseThen<T> extends QueryBase {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
declare const checkIfASimpleQuery: (q: Query) => boolean;
|
|
109
|
-
type WithItem =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
type WithItem = {
|
|
110
|
+
n: string;
|
|
111
|
+
o?: WithOptions;
|
|
112
|
+
q?: Query;
|
|
113
|
+
s?: Expression;
|
|
114
|
+
};
|
|
114
115
|
interface WithOptions {
|
|
115
116
|
columns?: string[];
|
|
116
117
|
recursive?: true;
|
|
@@ -288,7 +289,14 @@ interface WindowDeclaration {
|
|
|
288
289
|
partitionBy?: SelectableOrExpression | SelectableOrExpression[];
|
|
289
290
|
order?: OrderItem;
|
|
290
291
|
}
|
|
291
|
-
|
|
292
|
+
interface UnionItem {
|
|
293
|
+
a: Query | Expression;
|
|
294
|
+
k: UnionKind;
|
|
295
|
+
}
|
|
296
|
+
interface UnionSet {
|
|
297
|
+
b: Query;
|
|
298
|
+
u: UnionItem[];
|
|
299
|
+
}
|
|
292
300
|
type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT' | 'EXCEPT ALL';
|
|
293
301
|
type OnConflictTarget = string | string[] | Expression | {
|
|
294
302
|
constraint: string;
|
|
@@ -461,10 +469,9 @@ interface SelectQueryData extends CommonQueryData {
|
|
|
461
469
|
having?: HavingItem[];
|
|
462
470
|
window?: WindowItem[];
|
|
463
471
|
union?: {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}[];
|
|
472
|
+
b: Query;
|
|
473
|
+
u: UnionItem[];
|
|
474
|
+
};
|
|
468
475
|
order?: OrderItem[];
|
|
469
476
|
returnsOne?: true;
|
|
470
477
|
limit?: number;
|
|
@@ -3923,6 +3930,22 @@ declare class Create {
|
|
|
3923
3930
|
* });
|
|
3924
3931
|
* ```
|
|
3925
3932
|
*
|
|
3933
|
+
* `create` and `insert` can be used in {@link WithMethods.with} expressions:
|
|
3934
|
+
*
|
|
3935
|
+
* ```ts
|
|
3936
|
+
* db.$queryBuilder
|
|
3937
|
+
* // create a record in one table
|
|
3938
|
+
* .with('a', db.table.select('id').create(data))
|
|
3939
|
+
* // create a record in other table using the first table record id
|
|
3940
|
+
* .with('b', (q) =>
|
|
3941
|
+
* db.otherTable.select('id').create({
|
|
3942
|
+
* ...otherData,
|
|
3943
|
+
* aId: () => q.from('a').get('id'),
|
|
3944
|
+
* }),
|
|
3945
|
+
* )
|
|
3946
|
+
* .from('b');
|
|
3947
|
+
* ```
|
|
3948
|
+
*
|
|
3926
3949
|
* @param data - data for the record, may have values, raw SQL, queries, relation operations.
|
|
3927
3950
|
*/
|
|
3928
3951
|
create<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>): CreateResult<T, BT>;
|
|
@@ -4379,6 +4402,19 @@ declare class Delete {
|
|
|
4379
4402
|
* // delete all users who have corresponding profile records:
|
|
4380
4403
|
* db.table.join(Profile, 'profile.userId', 'user.id').all().delete();
|
|
4381
4404
|
* ```
|
|
4405
|
+
*
|
|
4406
|
+
* `delete` can be used in {@link WithMethods.with} expressions:
|
|
4407
|
+
*
|
|
4408
|
+
* ```ts
|
|
4409
|
+
* db.$queryBuilder
|
|
4410
|
+
* // delete a record in one table
|
|
4411
|
+
* .with('a', db.table.find(1).select('id').delete())
|
|
4412
|
+
* // delete a record in other table using the first table record id
|
|
4413
|
+
* .with('b', (q) =>
|
|
4414
|
+
* db.otherTable.select('id').whereIn('aId', q.from('a').pluck('id')).delete(),
|
|
4415
|
+
* )
|
|
4416
|
+
* .from('b');
|
|
4417
|
+
* ```
|
|
4382
4418
|
*/
|
|
4383
4419
|
delete<T extends PickQueryMetaResult>(this: T, ..._args: DeleteArgs<T>): DeleteResult<T>;
|
|
4384
4420
|
}
|
|
@@ -4399,17 +4435,12 @@ type FromArg<T extends FromQuerySelf> = PickQueryTableMetaResult | Expression |
|
|
|
4399
4435
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
4400
4436
|
type FromResult<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>> = Arg extends string ? T['withData'] extends WithDataItems ? {
|
|
4401
4437
|
[K in keyof T]: K extends 'meta' ? {
|
|
4402
|
-
[K in keyof T['meta']]: K extends 'as' ? string | undefined : K extends 'selectable' ? SelectableFromShape<T['withData'][Arg]['shape'], Arg> : T['meta'][K];
|
|
4403
|
-
} : T[K];
|
|
4404
|
-
} : SetQueryTableAlias<T, Arg> : Arg extends
|
|
4438
|
+
[K in keyof T['meta']]: K extends 'as' ? string | undefined : K extends 'selectable' ? SelectableFromShape<T['withData'][Arg]['shape'], Arg> : K extends 'kind' ? 'select' : T['meta'][K];
|
|
4439
|
+
} : K extends 'result' ? T['withData'][Arg]['shape'] : K extends 'then' ? QueryThen<GetQueryResult<T, T['withData'][Arg]['shape']>> : T[K];
|
|
4440
|
+
} : SetQueryTableAlias<T, Arg> : Arg extends PickQueryTableMetaResultInputType ? {
|
|
4405
4441
|
[K in keyof T]: K extends 'meta' ? {
|
|
4406
|
-
[K in keyof T['meta']]: K extends 'as' ? AliasOrTable<Arg> : K extends 'selectable' ?
|
|
4407
|
-
|
|
4408
|
-
as: K;
|
|
4409
|
-
column: Arg['result'][K];
|
|
4410
|
-
} : never;
|
|
4411
|
-
} : T['meta'][K];
|
|
4412
|
-
} : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : T[K];
|
|
4442
|
+
[K in keyof T['meta']]: K extends 'as' ? AliasOrTable<Arg> : K extends 'selectable' ? SelectableFromShape<Arg['result'], AliasOrTable<Arg>> : K extends 'kind' ? 'select' : T['meta'][K];
|
|
4443
|
+
} : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'inputType' ? Arg['inputType'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : T[K];
|
|
4413
4444
|
} : Arg extends (infer A)[] ? {
|
|
4414
4445
|
[K in keyof T]: K extends 'meta' ? {
|
|
4415
4446
|
[K in keyof T['meta']]: K extends 'selectable' ? UnionToIntersection<A extends string ? T['withData'] extends WithDataItems ? {
|
|
@@ -4427,7 +4458,7 @@ type FromResult<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>> = A
|
|
|
4427
4458
|
} : T;
|
|
4428
4459
|
declare function queryFrom<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>>(self: T, arg: Arg): FromResult<T, Arg>;
|
|
4429
4460
|
declare function queryFromSql<T extends FromQuerySelf>(self: T, args: SQLQueryArgs): T;
|
|
4430
|
-
declare class
|
|
4461
|
+
declare class FromMethods {
|
|
4431
4462
|
/**
|
|
4432
4463
|
* Set the `FROM` value, by default the table name is used.
|
|
4433
4464
|
*
|
|
@@ -4459,7 +4490,7 @@ declare class From {
|
|
|
4459
4490
|
*
|
|
4460
4491
|
* @param arg - query or name of CTE table
|
|
4461
4492
|
*/
|
|
4462
|
-
from<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>>(this: T, arg: T['meta']['hasSelect'] extends true ? '`select` must be
|
|
4493
|
+
from<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>>(this: T, arg: T['meta']['hasSelect'] extends true ? '`select` must be placed after `from`' : Arg): FromResult<T, Arg>;
|
|
4463
4494
|
/**
|
|
4464
4495
|
* Set the `FROM` value with custom SQL:
|
|
4465
4496
|
*
|
|
@@ -5091,16 +5122,180 @@ declare class Select {
|
|
|
5091
5122
|
selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
|
|
5092
5123
|
}
|
|
5093
5124
|
|
|
5094
|
-
|
|
5095
|
-
|
|
5125
|
+
declare class SqlMethod<ColumnTypes> {
|
|
5126
|
+
/**
|
|
5127
|
+
* When there is a need to use a piece of raw SQL, use the `sql` exported from the `BaseTable` file, it is also attached to query objects for convenience.
|
|
5128
|
+
*
|
|
5129
|
+
* When selecting a custom SQL, specify a resulting type with `<generic>` syntax:
|
|
5130
|
+
*
|
|
5131
|
+
* ```ts
|
|
5132
|
+
* import { sql } from './baseTable';
|
|
5133
|
+
*
|
|
5134
|
+
* const result: { num: number }[] = await db.table.select({
|
|
5135
|
+
* num: sql<number>`random() * 100`,
|
|
5136
|
+
* });
|
|
5137
|
+
* ```
|
|
5138
|
+
*
|
|
5139
|
+
* In a situation when you want the result to be parsed, such as when returning a timestamp that you want to be parsed into a `Date` object, provide a column type in such a way:
|
|
5140
|
+
*
|
|
5141
|
+
* This example assumes that the `timestamp` column was overridden with `asDate` as shown in [Override column types](/guide/columns-overview#override-column-types).
|
|
5142
|
+
*
|
|
5143
|
+
* ```ts
|
|
5144
|
+
* import { sql } from './baseTable';
|
|
5145
|
+
*
|
|
5146
|
+
* const result: { timestamp: Date }[] = await db.table.select({
|
|
5147
|
+
* timestamp: sql`now()`.type((t) => t.timestamp()),
|
|
5148
|
+
* });
|
|
5149
|
+
* ```
|
|
5150
|
+
*
|
|
5151
|
+
* In some cases such as when using [from](/guide/orm-and-query-builder.html#from), setting column type via callback allows for special `where` operations:
|
|
5152
|
+
*
|
|
5153
|
+
* ```ts
|
|
5154
|
+
* const subQuery = db.someTable.select({
|
|
5155
|
+
* sum: (q) => q.sql`$a + $b`.type((t) => t.decimal()).values({ a: 1, b: 2 }),
|
|
5156
|
+
* });
|
|
5157
|
+
*
|
|
5158
|
+
* // `gt`, `gte`, `min`, `lt`, `lte`, `max` in `where`
|
|
5159
|
+
* // are allowed only for numeric columns:
|
|
5160
|
+
* const result = await db.$from(subQuery).where({ sum: { gte: 5 } });
|
|
5161
|
+
* ```
|
|
5162
|
+
*
|
|
5163
|
+
* Many query methods have a version suffixed with `Sql`, you can pass an SQL template literal directly to these methods.
|
|
5164
|
+
* These methods are: `whereSql`, `whereNotSql`, `orderSql`, `havingSql`, `fromSql`, `findBySql`.
|
|
5165
|
+
*
|
|
5166
|
+
* ```ts
|
|
5167
|
+
* await db.table.whereSql`"someValue" = random() * 100`;
|
|
5168
|
+
* ```
|
|
5169
|
+
*
|
|
5170
|
+
* Interpolating values in template literals is completely safe:
|
|
5171
|
+
*
|
|
5172
|
+
* ```ts
|
|
5173
|
+
* // get value from user-provided params
|
|
5174
|
+
* const { value } = req.params;
|
|
5175
|
+
*
|
|
5176
|
+
* // SQL injection is prevented by a library, this is safe:
|
|
5177
|
+
* await db.table.whereSql`column = ${value}`;
|
|
5178
|
+
* ```
|
|
5179
|
+
*
|
|
5180
|
+
* In the example above, TS cannot check if the table has `column` column, or if there are joined tables that have such column which will lead to error.
|
|
5181
|
+
* Instead, use the [column](/guide/sql-expressions#column) or [ref](/guide/sql-expressions#ref) to reference a column:
|
|
5182
|
+
*
|
|
5183
|
+
* ```ts
|
|
5184
|
+
* // ids will be prefixed with proper table names, no ambiguity:
|
|
5185
|
+
* db.table.join(db.otherTable, 'id', 'otherId').where`
|
|
5186
|
+
* ${db.table.column('id')} = 1 AND
|
|
5187
|
+
* ${db.otherTable.ref('id')} = 2
|
|
5188
|
+
* `;
|
|
5189
|
+
* ```
|
|
5190
|
+
*
|
|
5191
|
+
* SQL can be passed with a simple string, it's important to note that this is not safe to interpolate values in it.
|
|
5192
|
+
*
|
|
5193
|
+
* ```ts
|
|
5194
|
+
* import { sql } from './baseTable';
|
|
5195
|
+
*
|
|
5196
|
+
* // no interpolation is okay
|
|
5197
|
+
* await db.table.where(sql({ raw: 'column = random() * 100' }));
|
|
5198
|
+
*
|
|
5199
|
+
* // get value from user-provided params
|
|
5200
|
+
* const { value } = req.params;
|
|
5201
|
+
*
|
|
5202
|
+
* // this is NOT safe, SQL injection is possible:
|
|
5203
|
+
* await db.table.where(sql({ raw: `column = random() * ${value}` }));
|
|
5204
|
+
* ```
|
|
5205
|
+
*
|
|
5206
|
+
* To inject values into `sql({ raw: '...' })` SQL strings, denote it with `$` in the string and provide `values` object.
|
|
5207
|
+
*
|
|
5208
|
+
* Use `$$` to provide column or/and table name (`column` or `ref` are preferable). Column names will be quoted so don't quote them manually.
|
|
5209
|
+
*
|
|
5210
|
+
* ```ts
|
|
5211
|
+
* import { sql } from './baseTable';
|
|
5212
|
+
*
|
|
5213
|
+
* // get value from user-provided params
|
|
5214
|
+
* const { value } = req.params;
|
|
5215
|
+
*
|
|
5216
|
+
* // this is SAFE, SQL injection are prevented:
|
|
5217
|
+
* await db.table.where(
|
|
5218
|
+
* sql<boolean>({
|
|
5219
|
+
* raw: '$$column = random() * $value',
|
|
5220
|
+
* values: {
|
|
5221
|
+
* column: 'someTable.someColumn', // or simply 'column'
|
|
5222
|
+
* one: value,
|
|
5223
|
+
* two: 123,
|
|
5224
|
+
* },
|
|
5225
|
+
* }),
|
|
5226
|
+
* );
|
|
5227
|
+
* ```
|
|
5228
|
+
*
|
|
5229
|
+
* Summarizing:
|
|
5230
|
+
*
|
|
5231
|
+
* ```ts
|
|
5232
|
+
* import { sql } from './baseTable';
|
|
5233
|
+
*
|
|
5234
|
+
* // simplest form:
|
|
5235
|
+
* sql`key = ${value}`;
|
|
5236
|
+
*
|
|
5237
|
+
* // with resulting type:
|
|
5238
|
+
* sql<boolean>`key = ${value}`;
|
|
5239
|
+
*
|
|
5240
|
+
* // with column type for select:
|
|
5241
|
+
* sql`key = ${value}`.type((t) => t.boolean());
|
|
5242
|
+
*
|
|
5243
|
+
* // with column name via `column` method:
|
|
5244
|
+
* sql`${db.table.column('column')} = ${value}`;
|
|
5245
|
+
*
|
|
5246
|
+
* // raw SQL string, not allowed to interpolate values:
|
|
5247
|
+
* sql({ raw: 'random()' });
|
|
5248
|
+
*
|
|
5249
|
+
* // with resulting type and `raw` string:
|
|
5250
|
+
* sql<number>({ raw: 'random()' });
|
|
5251
|
+
*
|
|
5252
|
+
* // with column name and a value in a `raw` string:
|
|
5253
|
+
* sql({
|
|
5254
|
+
* raw: `$$column = $value`,
|
|
5255
|
+
* values: { column: 'columnName', value: 123 },
|
|
5256
|
+
* });
|
|
5257
|
+
*
|
|
5258
|
+
* // combine template literal, column type, and values:
|
|
5259
|
+
* sql`($one + $two) / $one`.type((t) => t.numeric()).values({ one: 1, two: 2 });
|
|
5260
|
+
* ```
|
|
5261
|
+
*
|
|
5262
|
+
* @param args - template literal or an object { raw: string }
|
|
5263
|
+
* @return object that has `type` and `values` methods
|
|
5264
|
+
*/
|
|
5265
|
+
sql<T = unknown>(this: PickQueryColumnTypes, ...args: StaticSQLArgs): RawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5266
|
+
sql<T = unknown>(this: PickQueryColumnTypes, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5267
|
+
}
|
|
5268
|
+
|
|
5269
|
+
interface WithArgsOptions {
|
|
5270
|
+
columns?: string[] | boolean;
|
|
5271
|
+
materialized?: true;
|
|
5272
|
+
notMaterialized?: true;
|
|
5273
|
+
}
|
|
5274
|
+
interface WithRecursiveOptions extends WithArgsOptions {
|
|
5275
|
+
union?: 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT' | 'EXCEPT ALL';
|
|
5276
|
+
}
|
|
5277
|
+
type WithQueryBuilder<T extends PickQueryWithDataColumnTypes> = {
|
|
5278
|
+
[K in keyof Query]: K extends 'sql' ? SqlMethod<T['columnTypes']>['sql'] : K extends 'relations' ? EmptyObject : K extends 'withData' ? T['withData'] : Query[K];
|
|
5096
5279
|
};
|
|
5097
|
-
type
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5280
|
+
type WithResult<T extends PickQueryMetaWithDataColumnTypes, Name extends string, Q extends PickQueryResult> = {
|
|
5281
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
5282
|
+
[K in keyof T['meta']]: K extends 'kind' ? 'select' : T['meta'][K];
|
|
5283
|
+
} : K extends 'withData' ? {
|
|
5284
|
+
[K in keyof T['withData'] | Name]: K extends Name ? {
|
|
5285
|
+
table: Name;
|
|
5286
|
+
shape: Q['result'];
|
|
5287
|
+
} : K extends keyof T['withData'] ? T['withData'][K] : never;
|
|
5288
|
+
} : T[K];
|
|
5289
|
+
};
|
|
5290
|
+
type WithSqlResult<T extends PickQueryWithDataColumnTypes, Name extends string, Shape extends ColumnsShapeBase> = {
|
|
5291
|
+
[K in keyof T]: K extends 'withData' ? {
|
|
5292
|
+
[K in Name | keyof T['withData']]: K extends Name ? {
|
|
5293
|
+
table: Name;
|
|
5294
|
+
shape: Shape;
|
|
5295
|
+
} : K extends keyof T['withData'] ? T['withData'][K] : never;
|
|
5296
|
+
} : T[K];
|
|
5297
|
+
};
|
|
5298
|
+
declare class WithMethods {
|
|
5104
5299
|
/**
|
|
5105
5300
|
* Add Common Table Expression (CTE) to the query.
|
|
5106
5301
|
*
|
|
@@ -5164,73 +5359,113 @@ declare class With {
|
|
|
5164
5359
|
* .join('alias', 'alias.id', 'user.id')
|
|
5165
5360
|
* .select('alias.id');
|
|
5166
5361
|
* ```
|
|
5167
|
-
*
|
|
5168
|
-
* @param args - first argument is an alias for this CTE, other arguments can be column shape, query object, or raw SQL.
|
|
5169
5362
|
*/
|
|
5170
|
-
with<T extends
|
|
5363
|
+
with<T extends PickQueryMetaWithDataColumnTypes, Name extends string, Q>(this: T, name: Name, query: Q | ((q: WithQueryBuilder<T>) => Q)): WithResult<T, Name, Q extends Query ? Q : never>;
|
|
5364
|
+
with<T extends PickQueryMetaWithDataColumnTypes, Name extends string, Q extends Query>(this: T, name: Name, options: WithArgsOptions, query: Q | ((qb: WithQueryBuilder<T>) => Q)): WithResult<T, Name, Q>;
|
|
5365
|
+
withRecursive<T extends PickQueryMetaWithDataColumnTypes, Name extends string, Q extends Query, Result = WithResult<T, Name, Q>>(this: T, name: Name, base: Q | ((qb: WithQueryBuilder<T>) => Q), recursive: (qb: {
|
|
5366
|
+
[K in keyof Result]: K extends 'result' ? Q['result'] : Result[K];
|
|
5367
|
+
}) => Query): Result;
|
|
5368
|
+
withRecursive<T extends PickQueryMetaWithDataColumnTypes, Name extends string, Q extends Query, Result = WithResult<T, Name, Q>>(this: T, name: Name, options: WithRecursiveOptions, base: Q | ((qb: WithQueryBuilder<T>) => Q), recursive: (qb: {
|
|
5369
|
+
[K in keyof Result]: K extends 'result' ? Q['result'] : Result[K];
|
|
5370
|
+
}) => Query): Result;
|
|
5371
|
+
withSql<T extends PickQueryWithDataColumnTypes, Name extends string, Shape extends ColumnsShapeBase>(this: T, name: Name, options: WithOptions, shape: (t: T['columnTypes']) => Shape, expr: (q: T) => Expression): WithSqlResult<T, Name, Shape>;
|
|
5372
|
+
withSql<T extends PickQueryWithDataColumnTypes, Name extends string, Shape extends ColumnsShapeBase>(this: T, name: Name, shape: (t: T['columnTypes']) => Shape, expr: (q: T) => Expression): WithSqlResult<T, Name, Shape>;
|
|
5171
5373
|
}
|
|
5172
5374
|
|
|
5173
5375
|
type UnionArg<T extends PickQueryResult> = {
|
|
5174
5376
|
result: {
|
|
5175
5377
|
[K in keyof T['result']]: {
|
|
5176
|
-
|
|
5378
|
+
queryType: T['result'][K]['queryType'];
|
|
5177
5379
|
};
|
|
5178
5380
|
};
|
|
5179
|
-
} | Expression;
|
|
5381
|
+
} | ((q: T) => Expression);
|
|
5382
|
+
declare const _queryUnion: <T extends Query>(base: T, args: UnionArg<T>[], k: UnionKind) => T;
|
|
5180
5383
|
declare class Union {
|
|
5181
5384
|
/**
|
|
5182
|
-
* Creates a union query,
|
|
5183
|
-
* If the `wrap` parameter is true, the queries will be individually wrapped in parentheses.
|
|
5385
|
+
* Creates a union query, takes one or more queries or SQL expressions.
|
|
5184
5386
|
*
|
|
5185
5387
|
* ```ts
|
|
5186
|
-
*
|
|
5187
|
-
*
|
|
5188
|
-
*
|
|
5189
|
-
*
|
|
5190
|
-
*
|
|
5191
|
-
*
|
|
5192
|
-
* )
|
|
5388
|
+
* // The first query of the union
|
|
5389
|
+
* db.one
|
|
5390
|
+
* .select('id', 'name')
|
|
5391
|
+
* // add two more queries to the union
|
|
5392
|
+
* .union(
|
|
5393
|
+
* db.two.select('id', 'name'),
|
|
5394
|
+
* (q = q.sql`SELECT id, name FROM "thirdTable"`),
|
|
5395
|
+
* )
|
|
5396
|
+
* // sub-sequent `union` is equivalent to passing multiple queries into a single `union`
|
|
5397
|
+
* .union(db.three.select('id', 'name'));
|
|
5398
|
+
* ```
|
|
5399
|
+
*
|
|
5400
|
+
* `order`, `limit`, `offset` are special, it matters if you place them **before** or **after** the `union`, it also have a meaning to place them before and after.
|
|
5401
|
+
*
|
|
5402
|
+
* ```ts
|
|
5403
|
+
* // order, limit, offset are applied ONLY to 'one'
|
|
5404
|
+
* db.one
|
|
5405
|
+
* .order('x')
|
|
5406
|
+
* .limit(1)
|
|
5407
|
+
* .offset(1)
|
|
5408
|
+
* // 'two' also has order, limit, and offset
|
|
5409
|
+
* .unionAll(db.two.order('y').limit(2).offset(2))
|
|
5410
|
+
* // sets order, limit, offset for all records
|
|
5411
|
+
* .order('z')
|
|
5412
|
+
* .limit(3)
|
|
5413
|
+
* .offset(3);
|
|
5193
5414
|
* ```
|
|
5194
5415
|
*
|
|
5195
|
-
*
|
|
5196
|
-
*
|
|
5416
|
+
* Equivalent SQL:
|
|
5417
|
+
*
|
|
5418
|
+
* ```sql
|
|
5419
|
+
* -- both union parts have their own order, limit, offset
|
|
5420
|
+
* ( SELECT * FROM one ORDER x ASC LIMIT 1 OFFSET 1 )
|
|
5421
|
+
* UNION ALL
|
|
5422
|
+
* ( SELECT * FROM two ORDER y ASC LIMIT 2 OFFSET 2 )
|
|
5423
|
+
* -- order, limit, offset of the whole query
|
|
5424
|
+
* ORDER BY z ASC LIMIT 3 OFFSET 3
|
|
5425
|
+
* ```
|
|
5426
|
+
*
|
|
5427
|
+
* All the listed methods have the same signature, they are only different by SQL keyword:
|
|
5428
|
+
*
|
|
5429
|
+
* - `union` - union of all queries, performs deduplication
|
|
5430
|
+
* - `unionAll` - `union` that allows duplicated rows
|
|
5431
|
+
* - `intersect` - get only rows that are present in all queries
|
|
5432
|
+
* - `intersectAll` - `intersect` that allows duplicated rows
|
|
5433
|
+
* - `except` - get only rows that are in the first query but not in the second
|
|
5434
|
+
* - `exceptAll` - `except` that allows duplicated rows
|
|
5435
|
+
*
|
|
5436
|
+
* @param args - array of queries or SQL expressions
|
|
5197
5437
|
*/
|
|
5198
|
-
union<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5438
|
+
union<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5199
5439
|
/**
|
|
5200
|
-
* Same as
|
|
5440
|
+
* Same as {@link union}, but allows duplicated rows.
|
|
5201
5441
|
*
|
|
5202
|
-
* @param args - array of queries or
|
|
5203
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
5442
|
+
* @param args - array of queries or SQL expressions
|
|
5204
5443
|
*/
|
|
5205
|
-
unionAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5444
|
+
unionAll<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5206
5445
|
/**
|
|
5207
|
-
* Same as
|
|
5446
|
+
* Same as {@link union}, but uses a `INTERSECT` SQL keyword instead
|
|
5208
5447
|
*
|
|
5209
|
-
* @param args - array of queries or
|
|
5210
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
5448
|
+
* @param args - array of queries or SQL expressions
|
|
5211
5449
|
*/
|
|
5212
|
-
intersect<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5450
|
+
intersect<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5213
5451
|
/**
|
|
5214
|
-
* Same as
|
|
5452
|
+
* Same as {@link intersect}, but allows duplicated rows.
|
|
5215
5453
|
*
|
|
5216
|
-
* @param args - array of queries or
|
|
5217
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
5454
|
+
* @param args - array of queries or SQL expressions
|
|
5218
5455
|
*/
|
|
5219
|
-
intersectAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5456
|
+
intersectAll<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5220
5457
|
/**
|
|
5221
|
-
* Same as
|
|
5458
|
+
* Same as {@link union}, but uses an `EXCEPT` SQL keyword instead
|
|
5222
5459
|
*
|
|
5223
|
-
* @param args - array of queries or
|
|
5224
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
5460
|
+
* @param args - array of queries or SQL expressions
|
|
5225
5461
|
*/
|
|
5226
|
-
except<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5462
|
+
except<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5227
5463
|
/**
|
|
5228
|
-
* Same as
|
|
5464
|
+
* Same as {@link except}, but allows duplicated rows.
|
|
5229
5465
|
*
|
|
5230
|
-
* @param args - array of queries or
|
|
5231
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
5466
|
+
* @param args - array of queries or SQL expressions
|
|
5232
5467
|
*/
|
|
5233
|
-
exceptAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[]
|
|
5468
|
+
exceptAll<T extends PickQueryResult>(this: T, ...args: UnionArg<T>[]): T;
|
|
5234
5469
|
}
|
|
5235
5470
|
|
|
5236
5471
|
type UpdateSelf = {
|
|
@@ -5394,7 +5629,24 @@ declare class Update {
|
|
|
5394
5629
|
* })
|
|
5395
5630
|
* ```
|
|
5396
5631
|
*
|
|
5397
|
-
*
|
|
5632
|
+
* `update` can be used in {@link WithMethods.with} expressions:
|
|
5633
|
+
*
|
|
5634
|
+
* ```ts
|
|
5635
|
+
* db.$queryBuilder
|
|
5636
|
+
* // update record in one table
|
|
5637
|
+
* .with('a', db.table.find(1).select('id').update(data))
|
|
5638
|
+
* // update record in other table using the first table record id
|
|
5639
|
+
* .with('b', (q) =>
|
|
5640
|
+
* db.otherTable
|
|
5641
|
+
* .find(1)
|
|
5642
|
+
* .select('id')
|
|
5643
|
+
* .update({
|
|
5644
|
+
* ...otherData,
|
|
5645
|
+
* aId: () => q.from('a').get('id'),
|
|
5646
|
+
* }),
|
|
5647
|
+
* )
|
|
5648
|
+
* .from('b');
|
|
5649
|
+
* ```
|
|
5398
5650
|
*
|
|
5399
5651
|
* ### null, undefined, unknown columns
|
|
5400
5652
|
*
|
|
@@ -6021,150 +6273,6 @@ declare class QueryUpsertOrCreate {
|
|
|
6021
6273
|
orCreate<T extends UpsertThis, BT extends CreateBelongsToData<T>>(this: T, data: OrCreateArg<T, BT>): UpsertResult<T>;
|
|
6022
6274
|
}
|
|
6023
6275
|
|
|
6024
|
-
declare class SqlMethod<ColumnTypes> {
|
|
6025
|
-
/**
|
|
6026
|
-
* When there is a need to use a piece of raw SQL, use the `sql` exported from the `BaseTable` file, it is also attached to query objects for convenience.
|
|
6027
|
-
*
|
|
6028
|
-
* When selecting a custom SQL, specify a resulting type with `<generic>` syntax:
|
|
6029
|
-
*
|
|
6030
|
-
* ```ts
|
|
6031
|
-
* import { sql } from './baseTable';
|
|
6032
|
-
*
|
|
6033
|
-
* const result: { num: number }[] = await db.table.select({
|
|
6034
|
-
* num: sql<number>`random() * 100`,
|
|
6035
|
-
* });
|
|
6036
|
-
* ```
|
|
6037
|
-
*
|
|
6038
|
-
* In a situation when you want the result to be parsed, such as when returning a timestamp that you want to be parsed into a `Date` object, provide a column type in such a way:
|
|
6039
|
-
*
|
|
6040
|
-
* This example assumes that the `timestamp` column was overridden with `asDate` as shown in [Override column types](/guide/columns-overview#override-column-types).
|
|
6041
|
-
*
|
|
6042
|
-
* ```ts
|
|
6043
|
-
* import { sql } from './baseTable';
|
|
6044
|
-
*
|
|
6045
|
-
* const result: { timestamp: Date }[] = await db.table.select({
|
|
6046
|
-
* timestamp: sql`now()`.type((t) => t.timestamp()),
|
|
6047
|
-
* });
|
|
6048
|
-
* ```
|
|
6049
|
-
*
|
|
6050
|
-
* In some cases such as when using [from](/guide/orm-and-query-builder.html#from), setting column type via callback allows for special `where` operations:
|
|
6051
|
-
*
|
|
6052
|
-
* ```ts
|
|
6053
|
-
* const subQuery = db.someTable.select({
|
|
6054
|
-
* sum: (q) => q.sql`$a + $b`.type((t) => t.decimal()).values({ a: 1, b: 2 }),
|
|
6055
|
-
* });
|
|
6056
|
-
*
|
|
6057
|
-
* // `gt`, `gte`, `min`, `lt`, `lte`, `max` in `where`
|
|
6058
|
-
* // are allowed only for numeric columns:
|
|
6059
|
-
* const result = await db.$from(subQuery).where({ sum: { gte: 5 } });
|
|
6060
|
-
* ```
|
|
6061
|
-
*
|
|
6062
|
-
* Many query methods have a version suffixed with `Sql`, you can pass an SQL template literal directly to these methods.
|
|
6063
|
-
* These methods are: `whereSql`, `whereNotSql`, `orderSql`, `havingSql`, `fromSql`, `findBySql`.
|
|
6064
|
-
*
|
|
6065
|
-
* ```ts
|
|
6066
|
-
* await db.table.whereSql`"someValue" = random() * 100`;
|
|
6067
|
-
* ```
|
|
6068
|
-
*
|
|
6069
|
-
* Interpolating values in template literals is completely safe:
|
|
6070
|
-
*
|
|
6071
|
-
* ```ts
|
|
6072
|
-
* // get value from user-provided params
|
|
6073
|
-
* const { value } = req.params;
|
|
6074
|
-
*
|
|
6075
|
-
* // SQL injection is prevented by a library, this is safe:
|
|
6076
|
-
* await db.table.whereSql`column = ${value}`;
|
|
6077
|
-
* ```
|
|
6078
|
-
*
|
|
6079
|
-
* In the example above, TS cannot check if the table has `column` column, or if there are joined tables that have such column which will lead to error.
|
|
6080
|
-
* Instead, use the [column](/guide/sql-expressions#column) or [ref](/guide/sql-expressions#ref) to reference a column:
|
|
6081
|
-
*
|
|
6082
|
-
* ```ts
|
|
6083
|
-
* // ids will be prefixed with proper table names, no ambiguity:
|
|
6084
|
-
* db.table.join(db.otherTable, 'id', 'otherId').where`
|
|
6085
|
-
* ${db.table.column('id')} = 1 AND
|
|
6086
|
-
* ${db.otherTable.ref('id')} = 2
|
|
6087
|
-
* `;
|
|
6088
|
-
* ```
|
|
6089
|
-
*
|
|
6090
|
-
* SQL can be passed with a simple string, it's important to note that this is not safe to interpolate values in it.
|
|
6091
|
-
*
|
|
6092
|
-
* ```ts
|
|
6093
|
-
* import { sql } from './baseTable';
|
|
6094
|
-
*
|
|
6095
|
-
* // no interpolation is okay
|
|
6096
|
-
* await db.table.where(sql({ raw: 'column = random() * 100' }));
|
|
6097
|
-
*
|
|
6098
|
-
* // get value from user-provided params
|
|
6099
|
-
* const { value } = req.params;
|
|
6100
|
-
*
|
|
6101
|
-
* // this is NOT safe, SQL injection is possible:
|
|
6102
|
-
* await db.table.where(sql({ raw: `column = random() * ${value}` }));
|
|
6103
|
-
* ```
|
|
6104
|
-
*
|
|
6105
|
-
* To inject values into `sql({ raw: '...' })` SQL strings, denote it with `$` in the string and provide `values` object.
|
|
6106
|
-
*
|
|
6107
|
-
* Use `$$` to provide column or/and table name (`column` or `ref` are preferable). Column names will be quoted so don't quote them manually.
|
|
6108
|
-
*
|
|
6109
|
-
* ```ts
|
|
6110
|
-
* import { sql } from './baseTable';
|
|
6111
|
-
*
|
|
6112
|
-
* // get value from user-provided params
|
|
6113
|
-
* const { value } = req.params;
|
|
6114
|
-
*
|
|
6115
|
-
* // this is SAFE, SQL injection are prevented:
|
|
6116
|
-
* await db.table.where(
|
|
6117
|
-
* sql<boolean>({
|
|
6118
|
-
* raw: '$$column = random() * $value',
|
|
6119
|
-
* values: {
|
|
6120
|
-
* column: 'someTable.someColumn', // or simply 'column'
|
|
6121
|
-
* one: value,
|
|
6122
|
-
* two: 123,
|
|
6123
|
-
* },
|
|
6124
|
-
* }),
|
|
6125
|
-
* );
|
|
6126
|
-
* ```
|
|
6127
|
-
*
|
|
6128
|
-
* Summarizing:
|
|
6129
|
-
*
|
|
6130
|
-
* ```ts
|
|
6131
|
-
* import { sql } from './baseTable';
|
|
6132
|
-
*
|
|
6133
|
-
* // simplest form:
|
|
6134
|
-
* sql`key = ${value}`;
|
|
6135
|
-
*
|
|
6136
|
-
* // with resulting type:
|
|
6137
|
-
* sql<boolean>`key = ${value}`;
|
|
6138
|
-
*
|
|
6139
|
-
* // with column type for select:
|
|
6140
|
-
* sql`key = ${value}`.type((t) => t.boolean());
|
|
6141
|
-
*
|
|
6142
|
-
* // with column name via `column` method:
|
|
6143
|
-
* sql`${db.table.column('column')} = ${value}`;
|
|
6144
|
-
*
|
|
6145
|
-
* // raw SQL string, not allowed to interpolate values:
|
|
6146
|
-
* sql({ raw: 'random()' });
|
|
6147
|
-
*
|
|
6148
|
-
* // with resulting type and `raw` string:
|
|
6149
|
-
* sql<number>({ raw: 'random()' });
|
|
6150
|
-
*
|
|
6151
|
-
* // with column name and a value in a `raw` string:
|
|
6152
|
-
* sql({
|
|
6153
|
-
* raw: `$$column = $value`,
|
|
6154
|
-
* values: { column: 'columnName', value: 123 },
|
|
6155
|
-
* });
|
|
6156
|
-
*
|
|
6157
|
-
* // combine template literal, column type, and values:
|
|
6158
|
-
* sql`($one + $two) / $one`.type((t) => t.numeric()).values({ one: 1, two: 2 });
|
|
6159
|
-
* ```
|
|
6160
|
-
*
|
|
6161
|
-
* @param args - template literal or an object { raw: string }
|
|
6162
|
-
* @return object that has `type` and `values` methods
|
|
6163
|
-
*/
|
|
6164
|
-
sql<T = unknown>(this: PickQueryColumnTypes, ...args: StaticSQLArgs): RawSQL<QueryColumn<T>, ColumnTypes>;
|
|
6165
|
-
sql<T = unknown>(this: PickQueryColumnTypes, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
|
|
6166
|
-
}
|
|
6167
|
-
|
|
6168
6276
|
type QueryTransformFn<T extends Query> = (input: T['then'] extends QueryThen<infer Data> ? Data : never) => unknown;
|
|
6169
6277
|
type QueryTransform<T extends QueryBase, Data> = {
|
|
6170
6278
|
[K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
@@ -6277,7 +6385,7 @@ declare const _queryExec: <T extends Query>(q: T) => never;
|
|
|
6277
6385
|
declare const _queryFindBy: <T extends QueryBase<EmptyObject>>(q: T, args: WhereArg<T>[]) => SetQueryReturnsOne<WhereResult<T>>;
|
|
6278
6386
|
declare const _queryFindByOptional: <T extends QueryBase<EmptyObject>>(q: T, args: WhereArg<T>[]) => SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
6279
6387
|
declare const _queryRows: <T extends Query>(q: T) => SetQueryReturnsRows<T>;
|
|
6280
|
-
interface QueryMethods<ColumnTypes> extends AsMethods, AggregateMethods, Select,
|
|
6388
|
+
interface QueryMethods<ColumnTypes> extends AsMethods, AggregateMethods, Select, FromMethods, Join, WithMethods, Union, JsonModifiers, JsonMethods, Create, Update, Delete, Transaction, For, Where, SearchMethods, Clear, Having, QueryLog, QueryHooks, QueryUpsertOrCreate, QueryGet, MergeQueryMethods, SqlMethod<ColumnTypes>, TransformMethods, ScopeMethods, SoftDeleteMethods, ExpressionMethods {
|
|
6281
6389
|
}
|
|
6282
6390
|
declare class QueryMethods<ColumnTypes> {
|
|
6283
6391
|
/**
|
|
@@ -6928,6 +7036,10 @@ interface PickQueryColumnTypes {
|
|
|
6928
7036
|
}
|
|
6929
7037
|
interface PickQueryMetaResultRelationsWindowsColumnTypes extends PickQueryMetaResultRelationsWindows, PickQueryColumnTypes {
|
|
6930
7038
|
}
|
|
7039
|
+
interface PickQueryWithDataColumnTypes extends PickQueryWithData, PickQueryColumnTypes {
|
|
7040
|
+
}
|
|
7041
|
+
interface PickQueryMetaWithDataColumnTypes extends PickQueryMeta, PickQueryWithData, PickQueryColumnTypes {
|
|
7042
|
+
}
|
|
6931
7043
|
interface PickQueryMetaTable extends PickQueryMeta, PickQueryTable {
|
|
6932
7044
|
}
|
|
6933
7045
|
interface PickQueryMetaTableShape extends PickQueryMetaTable, PickQueryShape {
|
|
@@ -7106,12 +7218,6 @@ type SetQueryTableAlias<T extends PickQueryMetaTableShape, As extends string> =
|
|
|
7106
7218
|
} : T['meta'][K];
|
|
7107
7219
|
} : T[K];
|
|
7108
7220
|
};
|
|
7109
|
-
type SetQueryWith<T, WithData> = {
|
|
7110
|
-
[K in keyof T]: K extends 'withData' ? WithData : T[K];
|
|
7111
|
-
};
|
|
7112
|
-
type AddQueryWith<T extends PickQueryWithData, With extends WithDataItem> = SetQueryWith<T, {
|
|
7113
|
-
[K in keyof T['withData'] | With['table']]: K extends With['table'] ? With : K extends keyof T['withData'] ? T['withData'][K] : never;
|
|
7114
|
-
}>;
|
|
7115
7221
|
interface QueryOrExpression<T> {
|
|
7116
7222
|
result: {
|
|
7117
7223
|
value: QueryColumn<T>;
|
|
@@ -7780,4 +7886,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
7780
7886
|
*/
|
|
7781
7887
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
7782
7888
|
|
|
7783
|
-
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect,
|
|
7889
|
+
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateBelongsToData, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbDomainArg, DbDomainArgRecord, DbExtension, DbOptions, DbResult, DbSharedOptions, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, FromArg, FromMethods, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictMerge, OnConflictQueryBuilder, OnConflictSet, OnConflictTarget, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryColumnTypes, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryMetaWithDataColumnTypes, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBeforeHook, QueryData, QueryDataFromItem, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryInternal, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryOrExpression, QueryOrExpressionBooleanOrNullResult, QueryResult, QueryReturnsAll, QueryScopeData, QueryScopes, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithComputed, QueryWithTable, RawSQL, RealColumn, RecordOfColumnsShapeBase, RefExpression, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectAs, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryKindResult, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsAllKindResult, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnKindResult, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneKindResult, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsPluckColumnKindResult, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, SortDir, SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnionSet, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertArg, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, WithArgsOptions, WithDataBase, WithDataItem, WithDataItems, WithItem, WithMethods, WithOptions, WithQueryBuilder, WithRecursiveOptions, WithResult, WithSqlResult, WrapQueryArg, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseResult, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|