pqb 0.33.2 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +221 -149
- package/dist/index.js +1054 -476
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1051 -475
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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, SingleSqlItem, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, MaybeArray, SelectableBase, TemplateLiteralArgs,
|
|
2
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, MaybeArray, SelectableBase, TemplateLiteralArgs, QueryColumn, MaybePromise, FnUnknownToUnknown, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, BatchParsers, HookSelect, QueryDataTransform, ExpressionChain, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, 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, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, PickQueryUniqueProperties, PickQueryMetaResult, IsQuery, PickQueryTableMetaResultInputType, SingleSql, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase } 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';
|
|
@@ -119,12 +119,12 @@ interface WithOptions {
|
|
|
119
119
|
materialized?: true;
|
|
120
120
|
notMaterialized?: true;
|
|
121
121
|
}
|
|
122
|
-
type SelectItem = string | SelectAs | Expression;
|
|
122
|
+
type SelectItem = string | SelectAs | Expression | undefined;
|
|
123
123
|
interface SelectAs {
|
|
124
124
|
selectAs: SelectAsValue;
|
|
125
125
|
}
|
|
126
126
|
interface SelectAsValue {
|
|
127
|
-
[K: string]: string | Query | Expression;
|
|
127
|
+
[K: string]: string | Query | Expression | undefined;
|
|
128
128
|
}
|
|
129
129
|
type OrderTsQueryConfig = true | OrderTsQueryConfigObject;
|
|
130
130
|
interface OrderTsQueryConfigObject {
|
|
@@ -268,9 +268,75 @@ type OnConflictMerge = string | string[] | {
|
|
|
268
268
|
except: string | string[];
|
|
269
269
|
};
|
|
270
270
|
|
|
271
|
+
declare module 'orchid-core' {
|
|
272
|
+
interface ColumnDataBase {
|
|
273
|
+
computed?: Expression;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
type ComputedColumnsFromOptions<T extends ComputedOptionsFactory<never, never> | undefined> = T extends (...args: any[]) => any ? {
|
|
277
|
+
[K in keyof ReturnType<T>]: ReturnType<T>[K]['result']['value'];
|
|
278
|
+
} : EmptyObject;
|
|
279
|
+
type ComputedOptionsFactory<ColumnTypes, Shape extends QueryColumns> = (t: ComputedMethods<ColumnTypes, Shape>) => {
|
|
280
|
+
[K: string]: QueryOrExpression<unknown>;
|
|
281
|
+
};
|
|
282
|
+
interface RuntimeComputedQueryColumn<OutputType> extends QueryColumn {
|
|
283
|
+
dataType: 'runtimeComputed';
|
|
284
|
+
type: never;
|
|
285
|
+
outputType: OutputType;
|
|
286
|
+
queryType: undefined;
|
|
287
|
+
operators: {
|
|
288
|
+
cannotQueryRuntimeComputed: never;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
interface ComputedMethods<ColumnTypes, Shape extends QueryColumns> extends QueryComputedArg<ColumnTypes, Shape> {
|
|
292
|
+
computeAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: Pick<Shape, Deps>) => OutputType): {
|
|
293
|
+
result: {
|
|
294
|
+
value: RuntimeComputedQueryColumn<OutputType>;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
computeBatchAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: Pick<Shape, Deps>[]) => MaybePromise<OutputType[]>): {
|
|
298
|
+
result: {
|
|
299
|
+
value: RuntimeComputedQueryColumn<OutputType>;
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
declare class ComputedColumn {
|
|
304
|
+
kind: 'one' | 'many';
|
|
305
|
+
deps: string[];
|
|
306
|
+
fn: FnUnknownToUnknown;
|
|
307
|
+
constructor(kind: 'one' | 'many', deps: string[], fn: FnUnknownToUnknown);
|
|
308
|
+
}
|
|
309
|
+
interface ComputedColumns {
|
|
310
|
+
[K: string]: ComputedColumn;
|
|
311
|
+
}
|
|
312
|
+
interface QueryComputedArg<ColumnTypes, Shape extends QueryColumns> extends ExpressionMethods, SqlMethod<ColumnTypes> {
|
|
313
|
+
shape: Shape;
|
|
314
|
+
columnTypes: ColumnTypes;
|
|
315
|
+
windows: EmptyObject;
|
|
316
|
+
relations: RelationsBase;
|
|
317
|
+
result: EmptyObject;
|
|
318
|
+
meta: Omit<QueryMetaBase, 'selectable'> & {
|
|
319
|
+
selectable: {
|
|
320
|
+
[K in keyof Shape]: {
|
|
321
|
+
as: string;
|
|
322
|
+
column: QueryColumn;
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
declare const applyComputedColumns: (q: Query, fn: ComputedOptionsFactory<never, never>) => void;
|
|
328
|
+
declare const processComputedResult: (query: QueryData, result: unknown) => Promise<void[]> | undefined;
|
|
329
|
+
declare const processComputedBatches: (query: QueryData, batches: QueryBatchResult[], originalReturnType: QueryReturnType, returnType: QueryReturnType, tempColumns: Set<string> | undefined, renames: RecordString | undefined, key: string) => Promise<void> | undefined;
|
|
330
|
+
|
|
271
331
|
interface RecordOfColumnsShapeBase {
|
|
272
332
|
[K: string]: ColumnsShapeBase;
|
|
273
333
|
}
|
|
334
|
+
interface WithConfigs {
|
|
335
|
+
[K: string]: {
|
|
336
|
+
shape: ColumnsShapeBase;
|
|
337
|
+
computeds?: ComputedColumns;
|
|
338
|
+
};
|
|
339
|
+
}
|
|
274
340
|
type JoinedShapes = RecordOfColumnsShapeBase;
|
|
275
341
|
interface JoinedParsers {
|
|
276
342
|
[K: string]: ColumnsParsers;
|
|
@@ -289,19 +355,26 @@ interface QueryScopeData {
|
|
|
289
355
|
type QueryDataFromItem = string | Query | Expression;
|
|
290
356
|
interface QueryDataJoinTo extends PickQueryTable, PickQueryQ {
|
|
291
357
|
}
|
|
358
|
+
type HandleResult = (q: Query, returnType: QueryReturnType, result: QueryResult, isSubQuery?: true) => MaybePromise<unknown>;
|
|
292
359
|
interface CommonQueryData {
|
|
293
360
|
adapter: Adapter;
|
|
294
361
|
shape: ColumnsShapeBase;
|
|
295
362
|
patchResult?(q: Query, queryResult: QueryResult): Promise<void>;
|
|
296
|
-
handleResult
|
|
363
|
+
handleResult: HandleResult;
|
|
297
364
|
returnType: QueryReturnType;
|
|
298
365
|
wrapInTransaction?: boolean;
|
|
299
366
|
throwOnNotFound?: boolean;
|
|
300
367
|
with?: WithItem[];
|
|
301
|
-
withShapes?:
|
|
368
|
+
withShapes?: WithConfigs;
|
|
302
369
|
joinTo?: QueryDataJoinTo;
|
|
303
370
|
joinedShapes?: JoinedShapes;
|
|
304
371
|
joinedParsers?: JoinedParsers;
|
|
372
|
+
joinedBatchParsers?: {
|
|
373
|
+
[K: string]: BatchParsers;
|
|
374
|
+
};
|
|
375
|
+
joinedComputeds?: {
|
|
376
|
+
[K: string]: ComputedColumns;
|
|
377
|
+
};
|
|
305
378
|
joinedForSelect?: string;
|
|
306
379
|
innerJoinLateral?: true;
|
|
307
380
|
joinOverrides?: JoinOverrides;
|
|
@@ -317,22 +390,26 @@ interface CommonQueryData {
|
|
|
317
390
|
or?: WhereItem[][];
|
|
318
391
|
coalesceValue?: unknown | Expression;
|
|
319
392
|
parsers?: ColumnsParsers;
|
|
393
|
+
batchParsers?: BatchParsers;
|
|
320
394
|
notFoundDefault?: unknown;
|
|
321
395
|
defaults?: RecordUnknown;
|
|
396
|
+
hookSelect?: HookSelect;
|
|
397
|
+
computeds?: ComputedColumns;
|
|
398
|
+
selectedComputeds?: ComputedColumns;
|
|
322
399
|
before?: QueryBeforeHook[];
|
|
323
400
|
after?: QueryAfterHook[];
|
|
324
401
|
beforeCreate?: QueryBeforeHook[];
|
|
325
402
|
afterCreate?: QueryAfterHook[];
|
|
326
403
|
afterCreateCommit?: QueryAfterHook[];
|
|
327
|
-
afterCreateSelect?:
|
|
404
|
+
afterCreateSelect?: Set<string>;
|
|
328
405
|
beforeUpdate?: QueryBeforeHook[];
|
|
329
406
|
afterUpdate?: QueryAfterHook[];
|
|
330
407
|
afterUpdateCommit?: QueryAfterHook[];
|
|
331
|
-
afterUpdateSelect?:
|
|
408
|
+
afterUpdateSelect?: Set<string>;
|
|
332
409
|
beforeDelete?: QueryBeforeHook[];
|
|
333
410
|
afterDelete?: QueryAfterHook[];
|
|
334
411
|
afterDeleteCommit?: QueryAfterHook[];
|
|
335
|
-
afterDeleteSelect?:
|
|
412
|
+
afterDeleteSelect?: Set<string>;
|
|
336
413
|
log?: QueryLogObject;
|
|
337
414
|
logger: QueryLogger;
|
|
338
415
|
autoPreparedStatements?: boolean;
|
|
@@ -664,21 +741,6 @@ type JoinArgToQueryCallback = (...args: any[]) => PickQueryTableMetaResult;
|
|
|
664
741
|
* Callback must return a query builder.
|
|
665
742
|
*/
|
|
666
743
|
type JoinCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => PickQueryTableMetaResult;
|
|
667
|
-
/**
|
|
668
|
-
* Type of the `joinLateral`.
|
|
669
|
-
*
|
|
670
|
-
* Receives a query builder that can access columns of both the main and the joined table.
|
|
671
|
-
*
|
|
672
|
-
* Query builder inside callback is the query derived from the `joinLateral` first argument,
|
|
673
|
-
* all query methods are allowed, `on` methods are available.
|
|
674
|
-
*
|
|
675
|
-
* The callback must return a query object. Its resulting type will become a type of the joined table.
|
|
676
|
-
*/
|
|
677
|
-
type JoinLateralCallback<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns> = (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => {
|
|
678
|
-
table: Table;
|
|
679
|
-
meta: Meta;
|
|
680
|
-
result: Result;
|
|
681
|
-
};
|
|
682
744
|
/**
|
|
683
745
|
* Type of {@link Join.join} query method.
|
|
684
746
|
*/
|
|
@@ -1235,7 +1297,11 @@ declare class Join {
|
|
|
1235
1297
|
* @param arg - {@link JoinFirstArg}
|
|
1236
1298
|
* @param cb - {@link JoinLateralCallback}
|
|
1237
1299
|
*/
|
|
1238
|
-
joinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb:
|
|
1300
|
+
joinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb: (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => {
|
|
1301
|
+
table: Table;
|
|
1302
|
+
meta: Meta;
|
|
1303
|
+
result: Result;
|
|
1304
|
+
}): JoinLateralResult<T, Table, Meta, Result, true>;
|
|
1239
1305
|
/**
|
|
1240
1306
|
* The same as {@link joinLateral}, but when no records found for the join it will result in `null`:
|
|
1241
1307
|
*
|
|
@@ -1251,7 +1317,11 @@ declare class Join {
|
|
|
1251
1317
|
* @param arg - {@link JoinFirstArg}
|
|
1252
1318
|
* @param cb - {@link JoinLateralCallback}
|
|
1253
1319
|
*/
|
|
1254
|
-
leftJoinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb:
|
|
1320
|
+
leftJoinLateral<T extends PickQueryMetaResultRelationsWithDataReturnTypeShape, Arg extends JoinFirstArg<T>, Table extends string, Meta extends QueryMetaBase, Result extends QueryColumns>(this: T, arg: Arg, cb: (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>) => {
|
|
1321
|
+
table: Table;
|
|
1322
|
+
meta: Meta;
|
|
1323
|
+
result: Result;
|
|
1324
|
+
}): JoinLateralResult<T, Table, Meta, Result, false>;
|
|
1255
1325
|
}
|
|
1256
1326
|
type OnArgs<S extends SelectableBase> = [leftColumn: keyof S, rightColumn: keyof S] | [leftColumn: keyof S, op: string, rightColumn: keyof S];
|
|
1257
1327
|
declare const pushQueryOn: <T extends PickQueryMeta>(q: T, joinFrom: PickQueryMeta, joinTo: PickQueryMeta, ...on: OnArgs<SelectableBase>) => T;
|
|
@@ -1264,21 +1334,21 @@ type OnJsonPathEqualsArgs<S extends SelectableBase> = [
|
|
|
1264
1334
|
rightPath: string
|
|
1265
1335
|
];
|
|
1266
1336
|
/**
|
|
1267
|
-
* Mutative {@link OnMethods.on}
|
|
1337
|
+
* Mutative {@link OnMethods.prototype.on}
|
|
1268
1338
|
*/
|
|
1269
1339
|
declare const _queryJoinOn: <T extends PickQueryMeta>(q: T, args: OnArgs<T['meta']['selectable']>) => T;
|
|
1270
1340
|
/**
|
|
1271
|
-
* Mutative {@link OnMethods.orOn}
|
|
1341
|
+
* Mutative {@link OnMethods.prototype.orOn}
|
|
1272
1342
|
*/
|
|
1273
1343
|
declare const _queryJoinOrOn: <T extends PickQueryMeta>(q: T, args: OnArgs<T['meta']['selectable']>) => T;
|
|
1274
1344
|
/**
|
|
1275
|
-
* Mutative {@link OnMethods.onJsonPathEquals}
|
|
1345
|
+
* Mutative {@link OnMethods.prototype.onJsonPathEquals}
|
|
1276
1346
|
*/
|
|
1277
1347
|
declare const _queryJoinOnJsonPathEquals: <T extends PickQueryMeta>(q: T, args: OnJsonPathEqualsArgs<T["meta"]["selectable"]>) => T;
|
|
1278
1348
|
/**
|
|
1279
1349
|
* Argument of join callback.
|
|
1280
1350
|
* It is a query object of table that you're joining, with ability to select main table's columns.
|
|
1281
|
-
* Adds {@link OnMethods.on} method and similar to the query.
|
|
1351
|
+
* Adds {@link OnMethods.prototype.on} method and similar to the query.
|
|
1282
1352
|
*/
|
|
1283
1353
|
type JoinQueryBuilder<T extends PickQueryMetaShape = PickQueryMetaShape, J extends PickQueryTableMetaResult = PickQueryTableMetaResult> = {
|
|
1284
1354
|
[K in keyof J]: K extends 'meta' ? {
|
|
@@ -1709,7 +1779,21 @@ type WhereArg<T extends PickQueryMetaRelations> = {
|
|
|
1709
1779
|
[K in keyof T['meta']['selectable'] | 'NOT' | 'OR' | 'IN']?: K extends 'NOT' ? WhereArg<T> | WhereArgs<T> : K extends 'OR' ? (WhereArg<T> | WhereArgs<T>)[] : K extends 'IN' ? MaybeArray<{
|
|
1710
1780
|
columns: (keyof T['meta']['selectable'])[];
|
|
1711
1781
|
values: unknown[][] | QueryBase | Expression;
|
|
1712
|
-
}> : T['meta']['selectable'][K]['column']['queryType'] | null |
|
|
1782
|
+
}> : T['meta']['selectable'][K]['column']['queryType'] | null | {
|
|
1783
|
+
[O in keyof T['meta']['selectable'][K]['column']['operators']]?: T['meta']['selectable'][K]['column']['operators'][O]['_opType'];
|
|
1784
|
+
} | {
|
|
1785
|
+
result: {
|
|
1786
|
+
value: {
|
|
1787
|
+
queryType: T['meta']['selectable'][K]['column']['queryType'] | null;
|
|
1788
|
+
};
|
|
1789
|
+
};
|
|
1790
|
+
} | ((q: T) => {
|
|
1791
|
+
result: {
|
|
1792
|
+
value: {
|
|
1793
|
+
queryType: T['meta']['selectable'][K]['column']['queryType'] | null;
|
|
1794
|
+
};
|
|
1795
|
+
};
|
|
1796
|
+
});
|
|
1713
1797
|
} | QueryOrExpressionBooleanOrNullResult | ((q: WhereQueryBuilder<T>) => QueryOrExpressionBooleanOrNullResult | WhereQueryBuilder<T>);
|
|
1714
1798
|
/**
|
|
1715
1799
|
* Callback argument of `where`.
|
|
@@ -1744,35 +1828,35 @@ interface QueryMetaHasWhere {
|
|
|
1744
1828
|
};
|
|
1745
1829
|
}
|
|
1746
1830
|
/**
|
|
1747
|
-
* Mutative {@link Where.where}
|
|
1831
|
+
* Mutative {@link Where.prototype.where}
|
|
1748
1832
|
*/
|
|
1749
1833
|
declare const _queryWhere: <T extends PickQueryMetaRelations>(q: T, args: WhereArgs<T>) => WhereResult<T>;
|
|
1750
1834
|
/**
|
|
1751
|
-
* Mutative {@link Where.whereSql}
|
|
1835
|
+
* Mutative {@link Where.prototype.whereSql}
|
|
1752
1836
|
*/
|
|
1753
1837
|
declare const _queryWhereSql: <T>(q: T, args: SQLQueryArgs) => T;
|
|
1754
1838
|
/**
|
|
1755
|
-
* Mutative {@link Where.whereNot}
|
|
1839
|
+
* Mutative {@link Where.prototype.whereNot}
|
|
1756
1840
|
*/
|
|
1757
1841
|
declare const _queryWhereNot: <T extends PickQueryMetaRelations>(q: T, args: WhereNotArgs<T>) => WhereResult<T>;
|
|
1758
1842
|
/**
|
|
1759
|
-
* Mutative {@link Where.whereNotSql}
|
|
1843
|
+
* Mutative {@link Where.prototype.whereNotSql}
|
|
1760
1844
|
*/
|
|
1761
1845
|
declare const _queryWhereNotSql: <T>(q: T, args: SQLQueryArgs) => T;
|
|
1762
1846
|
/**
|
|
1763
|
-
* Mutative {@link Where.orWhere}
|
|
1847
|
+
* Mutative {@link Where.prototype.orWhere}
|
|
1764
1848
|
*/
|
|
1765
1849
|
declare const _queryOr: <T extends PickQueryMetaRelations>(q: T, args: WhereArgs<T>) => WhereResult<T>;
|
|
1766
1850
|
/**
|
|
1767
|
-
* Mutative {@link Where.orWhereNot}
|
|
1851
|
+
* Mutative {@link Where.prototype.orWhereNot}
|
|
1768
1852
|
*/
|
|
1769
1853
|
declare const _queryOrNot: <T extends PickQueryMetaRelations>(q: T, args: WhereArgs<T>) => WhereResult<T>;
|
|
1770
1854
|
/**
|
|
1771
|
-
* Mutative {@link Where.whereIn}
|
|
1855
|
+
* Mutative {@link Where.prototype.whereIn}
|
|
1772
1856
|
*/
|
|
1773
1857
|
declare const _queryWhereIn: <T>(q: T, and: boolean, arg: unknown, values: unknown[] | unknown[][] | Query | Expression | undefined, not?: boolean) => WhereResult<T>;
|
|
1774
1858
|
/**
|
|
1775
|
-
* Mutative {@link Where.whereExists}
|
|
1859
|
+
* Mutative {@link Where.prototype.whereExists}
|
|
1776
1860
|
*/
|
|
1777
1861
|
declare const _queryWhereExists: <T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>>(q: T, arg: Arg, args: JoinArgs<T, Arg>) => WhereResult<T>;
|
|
1778
1862
|
declare class Where {
|
|
@@ -2085,7 +2169,7 @@ declare class Where {
|
|
|
2085
2169
|
*
|
|
2086
2170
|
* ### Text column operators
|
|
2087
2171
|
*
|
|
2088
|
-
* For `text`, `
|
|
2172
|
+
* For `text`, `varchar`, `string`, and `json` columns.
|
|
2089
2173
|
*
|
|
2090
2174
|
* `json` is stored as text, so it has text operators. Use the `jsonb` type for JSON operators.
|
|
2091
2175
|
*
|
|
@@ -2533,19 +2617,17 @@ declare class RawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<Col
|
|
|
2533
2617
|
interface DynamicRawSQL<T extends QueryColumn> extends Expression<T>, ExpressionTypeMethod {
|
|
2534
2618
|
}
|
|
2535
2619
|
declare class DynamicRawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends Expression<T> {
|
|
2536
|
-
fn: DynamicSQLArg
|
|
2620
|
+
fn: DynamicSQLArg<T>;
|
|
2537
2621
|
columnTypes: ColumnTypes;
|
|
2538
2622
|
result: {
|
|
2539
2623
|
value: T;
|
|
2540
2624
|
};
|
|
2541
|
-
q:
|
|
2542
|
-
|
|
2543
|
-
};
|
|
2544
|
-
constructor(fn: DynamicSQLArg);
|
|
2625
|
+
q: ExpressionData;
|
|
2626
|
+
constructor(fn: DynamicSQLArg<T>);
|
|
2545
2627
|
makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
|
|
2546
2628
|
}
|
|
2547
2629
|
declare function raw<T = never>(...args: StaticSQLArgs): RawSQL<QueryColumn<T>>;
|
|
2548
|
-
declare function raw<T = never>(...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>>;
|
|
2630
|
+
declare function raw<T = never>(...args: [DynamicSQLArg<QueryColumn<T>>]): DynamicRawSQL<QueryColumn<T>>;
|
|
2549
2631
|
declare const countSelect: RawSQL<QueryColumn<unknown, any>, DefaultColumnTypes<ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>>[];
|
|
2550
2632
|
declare function sqlQueryArgsToExpression(args: SQLQueryArgs): RawSQL<QueryColumn>;
|
|
2551
2633
|
type SqlFn = <T, Args extends [sql: TemplateStringsArray, ...values: unknown[]] | [sql: string] | [values: RecordUnknown, sql?: string]>(this: T, ...args: Args) => Args extends [RecordUnknown] ? (...sql: TemplateLiteralArgs) => RawSQLBase<QueryColumn, T> : RawSQLBase<QueryColumn, T>;
|
|
@@ -2679,8 +2761,7 @@ type TableDataInput = {
|
|
|
2679
2761
|
constraint?: TableData.Constraint;
|
|
2680
2762
|
};
|
|
2681
2763
|
interface TableDataItem {
|
|
2682
|
-
|
|
2683
|
-
name: unknown;
|
|
2764
|
+
tableDataItem: true;
|
|
2684
2765
|
}
|
|
2685
2766
|
interface UniqueTableDataItem<Shape extends QueryColumns = QueryColumns> {
|
|
2686
2767
|
columns: (keyof Shape)[];
|
|
@@ -2688,6 +2769,7 @@ interface UniqueTableDataItem<Shape extends QueryColumns = QueryColumns> {
|
|
|
2688
2769
|
}
|
|
2689
2770
|
interface TableDataMethods<Key extends PropertyKey> {
|
|
2690
2771
|
primaryKey<Columns extends [Key, ...Key[]], Name extends string>(columns: Columns, name?: Name): {
|
|
2772
|
+
tableDataItem: true;
|
|
2691
2773
|
columns: Columns;
|
|
2692
2774
|
name: string extends Name ? never : Name;
|
|
2693
2775
|
};
|
|
@@ -2695,6 +2777,7 @@ interface TableDataMethods<Key extends PropertyKey> {
|
|
|
2695
2777
|
Key | TableData.Index.ColumnOrExpressionOptions<Key>,
|
|
2696
2778
|
...(Key | TableData.Index.ColumnOrExpressionOptions<Key>)[]
|
|
2697
2779
|
], Name extends string>(columns: Columns, ...args: [options?: TableData.Index.UniqueOptionsArg] | [name?: Name, options?: TableData.Index.UniqueOptionsArg]): {
|
|
2780
|
+
tableDataItem: true;
|
|
2698
2781
|
columns: Columns extends (Key | TableData.Index.ColumnOptionsForColumn<Key>)[] ? {
|
|
2699
2782
|
[I in keyof Columns]: 'column' extends keyof Columns[I] ? Columns[I]['column'] : Columns[I];
|
|
2700
2783
|
} : never;
|
|
@@ -2820,7 +2903,7 @@ declare abstract class LimitedTextBaseColumn<Schema extends ColumnSchemaConfig>
|
|
|
2820
2903
|
data: TextColumnData & {
|
|
2821
2904
|
maxChars?: number;
|
|
2822
2905
|
};
|
|
2823
|
-
constructor(schema: Schema, limit
|
|
2906
|
+
constructor(schema: Schema, limit: number);
|
|
2824
2907
|
toSQL(): string;
|
|
2825
2908
|
}
|
|
2826
2909
|
declare class VarCharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
|
|
@@ -2831,17 +2914,13 @@ declare class StringColumn$1<Schema extends ColumnSchemaConfig> extends VarCharC
|
|
|
2831
2914
|
constructor(schema: Schema, limit?: number);
|
|
2832
2915
|
toCode(t: string, m?: boolean): Code;
|
|
2833
2916
|
}
|
|
2834
|
-
declare class CharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
|
|
2835
|
-
dataType: "char";
|
|
2836
|
-
toCode(t: string, m?: boolean): Code;
|
|
2837
|
-
}
|
|
2838
2917
|
declare class TextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema> {
|
|
2839
2918
|
dataType: "text";
|
|
2840
2919
|
data: TextColumnData & {
|
|
2841
2920
|
minArg?: number;
|
|
2842
2921
|
maxArg?: number;
|
|
2843
2922
|
};
|
|
2844
|
-
constructor(schema: Schema
|
|
2923
|
+
constructor(schema: Schema);
|
|
2845
2924
|
toCode(t: string, m?: boolean): Code;
|
|
2846
2925
|
}
|
|
2847
2926
|
declare class ByteaColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, Buffer, ReturnType<Schema['buffer']>, OperatorsText> {
|
|
@@ -3010,7 +3089,7 @@ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseCo
|
|
|
3010
3089
|
minArg?: number;
|
|
3011
3090
|
maxArg?: number;
|
|
3012
3091
|
};
|
|
3013
|
-
constructor(schema: Schema
|
|
3092
|
+
constructor(schema: Schema);
|
|
3014
3093
|
toCode(t: string, m?: boolean): Code;
|
|
3015
3094
|
}
|
|
3016
3095
|
|
|
@@ -3054,11 +3133,10 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
|
|
|
3054
3133
|
doublePrecision(): DoublePrecisionColumn<DefaultSchemaConfig>;
|
|
3055
3134
|
bigSerial(): BigSerialColumn<DefaultSchemaConfig>;
|
|
3056
3135
|
money(): MoneyColumn<DefaultSchemaConfig>;
|
|
3057
|
-
varchar(limit
|
|
3058
|
-
|
|
3059
|
-
text(min: number, max: number): TextColumn<DefaultSchemaConfig>;
|
|
3136
|
+
varchar(limit: number): VarCharColumn<DefaultSchemaConfig>;
|
|
3137
|
+
text(): TextColumn<DefaultSchemaConfig>;
|
|
3060
3138
|
string(limit?: number): StringColumn$1<DefaultSchemaConfig>;
|
|
3061
|
-
citext(
|
|
3139
|
+
citext(): CitextColumn<DefaultSchemaConfig>;
|
|
3062
3140
|
date(): DateColumn<DefaultSchemaConfig>;
|
|
3063
3141
|
timestampNoTZ(precision?: number): TimestampColumn<DefaultSchemaConfig>;
|
|
3064
3142
|
timestamp(precision?: number): TimestampTZColumn<DefaultSchemaConfig>;
|
|
@@ -3151,7 +3229,7 @@ type DbOptions<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> = ({
|
|
|
3151
3229
|
snakeCase?: boolean;
|
|
3152
3230
|
nowSQL?: string;
|
|
3153
3231
|
};
|
|
3154
|
-
interface DbTableOptions<Table extends string | undefined, Shape extends QueryColumns> extends QueryLogOptions {
|
|
3232
|
+
interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape extends QueryColumns> extends QueryLogOptions {
|
|
3155
3233
|
schema?: string;
|
|
3156
3234
|
autoPreparedStatements?: boolean;
|
|
3157
3235
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
@@ -3166,6 +3244,7 @@ interface DbTableOptions<Table extends string | undefined, Shape extends QueryCo
|
|
|
3166
3244
|
*/
|
|
3167
3245
|
softDelete?: SoftDeleteOption<Shape>;
|
|
3168
3246
|
comment?: string;
|
|
3247
|
+
computed?: ComputedOptionsFactory<ColumnTypes, Shape>;
|
|
3169
3248
|
}
|
|
3170
3249
|
/**
|
|
3171
3250
|
* See {@link ScopeMethods}
|
|
@@ -3180,7 +3259,7 @@ declare const anyShape: QueryColumnsInit;
|
|
|
3180
3259
|
interface Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape, Scopes extends CoreQueryScopes | undefined = EmptyObject> extends DbBase<Adapter, Table, Shape, ColumnTypes, ShapeWithComputed>, QueryMethods<ColumnTypes>, QueryBase {
|
|
3181
3260
|
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
3182
3261
|
queryBuilder: Db;
|
|
3183
|
-
returnType:
|
|
3262
|
+
returnType: undefined;
|
|
3184
3263
|
then: QueryThen<QueryDefaultReturnData<Shape>>;
|
|
3185
3264
|
windows: Query['windows'];
|
|
3186
3265
|
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
@@ -3210,7 +3289,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Que
|
|
|
3210
3289
|
table: Table;
|
|
3211
3290
|
shape: ShapeWithComputed;
|
|
3212
3291
|
columnTypes: ColumnTypes;
|
|
3213
|
-
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: ShapeWithComputed, columnTypes: ColumnTypes, transactionStorage: AsyncLocalStorage<TransactionState>, options: DbTableOptions<Table, ShapeWithComputed>, tableData?: TableData);
|
|
3292
|
+
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: ShapeWithComputed, columnTypes: ColumnTypes, transactionStorage: AsyncLocalStorage<TransactionState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData);
|
|
3214
3293
|
[inspect.custom](): string;
|
|
3215
3294
|
/**
|
|
3216
3295
|
* Use `query` to perform raw SQL queries.
|
|
@@ -3270,7 +3349,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Que
|
|
|
3270
3349
|
*/
|
|
3271
3350
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryArraysResult<R>>;
|
|
3272
3351
|
}
|
|
3273
|
-
type DbTableConstructor<ColumnTypes> = <Table extends string, Shape extends QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options) => Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, EmptyObject, ColumnTypes, Shape
|
|
3352
|
+
type DbTableConstructor<ColumnTypes> = <Table extends string, Shape extends QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options) => Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, EmptyObject, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options['scopes'], Options['softDelete']>>;
|
|
3274
3353
|
type MapTableScopesOption<Scopes extends CoreQueryScopes | undefined, SoftDelete extends true | PropertyKey | undefined> = {
|
|
3275
3354
|
[K in keyof Scopes | (SoftDelete extends true | PropertyKey ? 'nonDeleted' : never)]: unknown;
|
|
3276
3355
|
};
|
|
@@ -3322,8 +3401,8 @@ interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, n
|
|
|
3322
3401
|
* ```ts
|
|
3323
3402
|
* export const User = db('user', (t) => ({
|
|
3324
3403
|
* id: t.identity().primaryKey(),
|
|
3325
|
-
* name: t.
|
|
3326
|
-
* password: t.
|
|
3404
|
+
* name: t.string(),
|
|
3405
|
+
* password: t.varchar(100),
|
|
3327
3406
|
* age: t.integer().nullable(),
|
|
3328
3407
|
* ...t.timestamps(),
|
|
3329
3408
|
* }));
|
|
@@ -3355,7 +3434,7 @@ interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, n
|
|
|
3355
3434
|
* ```
|
|
3356
3435
|
*/
|
|
3357
3436
|
declare const createDb: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>> = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase, nowSQL, schemaConfig, columnTypes: ctOrFn, ...options }: DbOptions<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
3358
|
-
declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, transactionStorage: AsyncLocalStorage<TransactionState>, commonOptions: DbTableOptions<undefined, QueryColumns>, options: DbSharedOptions) => Db;
|
|
3437
|
+
declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, transactionStorage: AsyncLocalStorage<TransactionState>, commonOptions: DbTableOptions<unknown, undefined, QueryColumns>, options: DbSharedOptions) => Db;
|
|
3359
3438
|
|
|
3360
3439
|
type ToSQLCtx = {
|
|
3361
3440
|
queryBuilder: Db;
|
|
@@ -3395,7 +3474,15 @@ declare const getSqlText: (sql: Sql) => string;
|
|
|
3395
3474
|
|
|
3396
3475
|
type AliasOrTable<T extends PickQueryMetaTable> = T['meta']['as'] extends string ? T['meta']['as'] : T['table'] extends string ? T['table'] : never;
|
|
3397
3476
|
type SelectableOrExpression<T extends PickQueryMeta = PickQueryMeta, C extends QueryColumn = QueryColumn> = '*' | keyof T['meta']['selectable'] | Expression<C>;
|
|
3398
|
-
type SelectableOrExpressions<T extends
|
|
3477
|
+
type SelectableOrExpressions<T extends {
|
|
3478
|
+
meta: {
|
|
3479
|
+
selectable: unknown;
|
|
3480
|
+
};
|
|
3481
|
+
} = {
|
|
3482
|
+
meta: {
|
|
3483
|
+
selectable: unknown;
|
|
3484
|
+
};
|
|
3485
|
+
}, C extends QueryColumn = QueryColumn> = ('*' | keyof T['meta']['selectable'] | Expression<C>)[];
|
|
3399
3486
|
type ExpressionOutput<T extends PickQueryMeta, Expr extends SelectableOrExpression<T>> = Expr extends keyof T['meta']['selectable'] ? T['meta']['selectable'][Expr]['column'] : Expr extends Expression ? Expr['result']['value'] : never;
|
|
3400
3487
|
declare const getClonedQueryData: (query: QueryData) => QueryData;
|
|
3401
3488
|
declare const getQueryAs: (q: {
|
|
@@ -3915,19 +4002,21 @@ type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends k
|
|
|
3915
4002
|
[K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K>;
|
|
3916
4003
|
};
|
|
3917
4004
|
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | QueryOrExpression<T['inputType'][K]> | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
3918
|
-
type CreateRelationsData<T extends CreateSelf, BelongsToData> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate']> & BelongsToData & T['relations'][keyof T['relations']]['relationConfig']['optionalDataForCreate'];
|
|
3919
|
-
type CreateBelongsToData<T extends CreateSelf> =
|
|
4005
|
+
type CreateRelationsData<T extends CreateSelf, BelongsToData> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate']> & ([BelongsToData] extends [never] ? EmptyObject : BelongsToData) & T['relations'][keyof T['relations']]['relationConfig']['optionalDataForCreate'];
|
|
4006
|
+
type CreateBelongsToData<T extends CreateSelf> = [
|
|
4007
|
+
T['relations'][keyof T['relations']]['relationConfig']['dataForCreate']
|
|
4008
|
+
] extends [never] ? never : CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['relationConfig']['dataForCreate']>;
|
|
3920
4009
|
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: keyof Union['columns'] extends keyof T['meta']['defaults'] ? Omit<Union['columns'], keyof T['meta']['defaults']> & {
|
|
3921
4010
|
[P in keyof T['meta']['defaults'] & keyof Union['columns']]?: Union['columns'][P];
|
|
3922
|
-
} & Partial<Union['nested']> : Union['columns'] | Union['nested']) => void : never) extends (u: infer Obj
|
|
4011
|
+
} & Partial<Union['nested']> : Union['columns'] | Union['nested']) => void : never) extends (u: infer Obj) => void ? Obj : never;
|
|
3923
4012
|
type CreateResult<T extends CreateSelf, BT> = T extends {
|
|
3924
4013
|
isCount: true;
|
|
3925
|
-
} ? SetQueryKind<T, 'create'> :
|
|
4014
|
+
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
3926
4015
|
type CreateRawOrFromResult<T extends CreateSelf> = T extends {
|
|
3927
4016
|
isCount: true;
|
|
3928
|
-
} ? SetQueryKind<T, 'create'> :
|
|
3929
|
-
type InsertResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ?
|
|
3930
|
-
type InsertRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ?
|
|
4017
|
+
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4018
|
+
type InsertResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryReturnsRowCount<T, 'create'>;
|
|
4019
|
+
type InsertRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCount<T, 'create'>;
|
|
3931
4020
|
type CreateManyResult<T extends CreateSelf, BT> = T extends {
|
|
3932
4021
|
isCount: true;
|
|
3933
4022
|
} ? SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
@@ -3942,10 +4031,12 @@ type InsertManyRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] ex
|
|
|
3942
4031
|
*
|
|
3943
4032
|
* The same should work as well with any non-null columns passed to `create`, but it's to be implemented later.
|
|
3944
4033
|
*/
|
|
3945
|
-
type NarrowCreateResult<T extends CreateSelf,
|
|
3946
|
-
|
|
4034
|
+
type NarrowCreateResult<T extends CreateSelf, Bt> = [
|
|
4035
|
+
{
|
|
4036
|
+
[K in keyof T['relations']]: T['relations'][K]['relationConfig']['omitForeignKeyInCreate'];
|
|
4037
|
+
}[keyof T['relations'] & keyof Bt]
|
|
3947
4038
|
] extends [never] ? T['result'] : {
|
|
3948
|
-
[K in keyof T['result']]: K extends T['relations'][keyof T['relations']
|
|
4039
|
+
[K in keyof T['result']]: K extends T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate'] ? QueryColumn<Exclude<T['result'][K]['type'], null>, T['result'][K]['operators']> : T['result'][K];
|
|
3949
4040
|
};
|
|
3950
4041
|
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? SetQueryReturnsOneOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
3951
4042
|
interface CreateRawData<T extends CreateSelf> {
|
|
@@ -3981,10 +4072,10 @@ interface CreateCtx {
|
|
|
3981
4072
|
returnTypeAll?: true;
|
|
3982
4073
|
resultAll: RecordUnknown[];
|
|
3983
4074
|
}
|
|
3984
|
-
declare const _queryCreate: <T extends CreateSelf, BT extends
|
|
3985
|
-
declare const _queryInsert: <T extends CreateSelf, BT extends
|
|
3986
|
-
declare const _queryCreateMany: <T extends CreateSelf, BT extends
|
|
3987
|
-
declare const _queryInsertMany: <T extends CreateSelf, BT extends
|
|
4075
|
+
declare const _queryCreate: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>) => CreateResult<T, BT>;
|
|
4076
|
+
declare const _queryInsert: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>) => InsertResult<T, BT>;
|
|
4077
|
+
declare const _queryCreateMany: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>[]) => CreateManyResult<T, BT>;
|
|
4078
|
+
declare const _queryInsertMany: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>[]) => InsertManyResult<T, BT>;
|
|
3988
4079
|
declare const _queryCreateRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) => CreateRawOrFromResult<T>;
|
|
3989
4080
|
declare const _queryInsertRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateRawData<T>>) => InsertRawOrFromResult<T>;
|
|
3990
4081
|
declare const _queryCreateManyRaw: <T extends CreateSelf>(q: T, args: CreateRawArgs<T, CreateManyRawData<T>>) => CreateManyRawOrFromResult<T>;
|
|
@@ -3997,7 +4088,7 @@ declare const _queryInsertFrom: <T extends CreateSelf, Q extends Query & {
|
|
|
3997
4088
|
}>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => InsertRawOrFromResult<T>;
|
|
3998
4089
|
declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: Query) => CreateManyRawOrFromResult<T>;
|
|
3999
4090
|
declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: Query) => InsertManyRawOrFromResult<T>;
|
|
4000
|
-
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T,
|
|
4091
|
+
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T, CreateBelongsToData<T>>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
|
|
4001
4092
|
/**
|
|
4002
4093
|
* Names of all create methods,
|
|
4003
4094
|
* is used in {@link RelationQuery} to remove these methods if chained relation shouldn't have them,
|
|
@@ -4740,22 +4831,22 @@ declare class Having {
|
|
|
4740
4831
|
type AfterHook<Select extends PropertyKey[], Shape extends QueryColumns> = QueryAfterHook<{
|
|
4741
4832
|
[K in keyof Select[number]]: K extends keyof Shape ? Shape[K]['outputType'] : never;
|
|
4742
4833
|
}[]>;
|
|
4743
|
-
type
|
|
4834
|
+
type HookSelectArg<T extends PickQueryShape> = (keyof T['shape'] & string)[];
|
|
4744
4835
|
type HookAction = 'Create' | 'Update' | 'Delete';
|
|
4745
4836
|
declare const _queryHookBeforeQuery: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
4746
4837
|
declare const _queryHookAfterQuery: <T extends PickQueryShape>(q: T, cb: QueryAfterHook) => T;
|
|
4747
4838
|
declare const _queryHookBeforeCreate: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
4748
|
-
declare const _queryHookAfterCreate: <T extends PickQueryShape, S extends
|
|
4749
|
-
declare const _queryHookAfterCreateCommit: <T extends PickQueryShape, S extends
|
|
4839
|
+
declare const _queryHookAfterCreate: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4840
|
+
declare const _queryHookAfterCreateCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4750
4841
|
declare const _queryHookBeforeUpdate: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
4751
|
-
declare const _queryHookAfterUpdate: <T extends PickQueryShape, S extends
|
|
4752
|
-
declare const _queryHookAfterUpdateCommit: <T extends PickQueryShape, S extends
|
|
4842
|
+
declare const _queryHookAfterUpdate: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4843
|
+
declare const _queryHookAfterUpdateCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4753
4844
|
declare const _queryHookBeforeSave: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
4754
|
-
declare const _queryHookAfterSave: <T extends PickQueryShape, S extends
|
|
4755
|
-
declare const _queryAfterSaveCommit: <T extends PickQueryShape, S extends
|
|
4845
|
+
declare const _queryHookAfterSave: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4846
|
+
declare const _queryAfterSaveCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4756
4847
|
declare const _queryHookBeforeDelete: <T extends PickQueryShape>(q: T, cb: QueryBeforeHook) => T;
|
|
4757
|
-
declare const _queryHookAfterDelete: <T extends PickQueryShape, S extends
|
|
4758
|
-
declare const _queryHookAfterDeleteCommit: <T extends PickQueryShape, S extends
|
|
4848
|
+
declare const _queryHookAfterDelete: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4849
|
+
declare const _queryHookAfterDeleteCommit: <T extends PickQueryShape, S extends HookSelectArg<T>>(q: T, select: S, cb: AfterHook<S, T['shape']>) => T;
|
|
4759
4850
|
declare abstract class QueryHooks {
|
|
4760
4851
|
/**
|
|
4761
4852
|
* Run the function before any kind of query.
|
|
@@ -4786,7 +4877,7 @@ declare abstract class QueryHooks {
|
|
|
4786
4877
|
* @param select - list of columns to select for the hook
|
|
4787
4878
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4788
4879
|
*/
|
|
4789
|
-
afterCreate<T extends PickQueryShape, S extends
|
|
4880
|
+
afterCreate<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4790
4881
|
/**
|
|
4791
4882
|
* Run the function after transaction for a `create` kind of query will be committed.
|
|
4792
4883
|
* If the query wasn't wrapped in a transaction, will run after the query.
|
|
@@ -4794,7 +4885,7 @@ declare abstract class QueryHooks {
|
|
|
4794
4885
|
* @param select - list of columns to select for the hook
|
|
4795
4886
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4796
4887
|
*/
|
|
4797
|
-
afterCreateCommit<T extends PickQueryShape, S extends
|
|
4888
|
+
afterCreateCommit<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4798
4889
|
/**
|
|
4799
4890
|
* Run the function before an `update` kind of query.
|
|
4800
4891
|
*
|
|
@@ -4811,7 +4902,7 @@ declare abstract class QueryHooks {
|
|
|
4811
4902
|
* @param select - list of columns to select for the hook
|
|
4812
4903
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4813
4904
|
*/
|
|
4814
|
-
afterUpdate<T extends PickQueryShape, S extends
|
|
4905
|
+
afterUpdate<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4815
4906
|
/**
|
|
4816
4907
|
* Run the function after transaction for an `update` kind of query will be committed.
|
|
4817
4908
|
* If the query wasn't wrapped in a transaction, will run after the query.
|
|
@@ -4820,7 +4911,7 @@ declare abstract class QueryHooks {
|
|
|
4820
4911
|
* @param select - list of columns to select for the hook
|
|
4821
4912
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4822
4913
|
*/
|
|
4823
|
-
afterUpdateCommit<T extends PickQueryShape, S extends
|
|
4914
|
+
afterUpdateCommit<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4824
4915
|
/**
|
|
4825
4916
|
* Run the function before a `create` or an `update` kind of query.
|
|
4826
4917
|
*
|
|
@@ -4837,7 +4928,7 @@ declare abstract class QueryHooks {
|
|
|
4837
4928
|
* @param select - list of columns to select for the hook
|
|
4838
4929
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4839
4930
|
*/
|
|
4840
|
-
afterSave<T extends PickQueryShape, S extends
|
|
4931
|
+
afterSave<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4841
4932
|
/**
|
|
4842
4933
|
* Run the function after transaction for a `create` or an `update` kind of query will be committed.
|
|
4843
4934
|
* If the query wasn't wrapped in a transaction, will run after the query.
|
|
@@ -4846,7 +4937,7 @@ declare abstract class QueryHooks {
|
|
|
4846
4937
|
* @param select - list of columns to select for the hook
|
|
4847
4938
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4848
4939
|
*/
|
|
4849
|
-
afterSaveCommit<T extends PickQueryShape, S extends
|
|
4940
|
+
afterSaveCommit<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4850
4941
|
/**
|
|
4851
4942
|
* Run the function before a `delete` kind of query.
|
|
4852
4943
|
*
|
|
@@ -4863,7 +4954,7 @@ declare abstract class QueryHooks {
|
|
|
4863
4954
|
* @param select - list of columns to select for the hook
|
|
4864
4955
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4865
4956
|
*/
|
|
4866
|
-
afterDelete<T extends PickQueryShape, S extends
|
|
4957
|
+
afterDelete<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4867
4958
|
/**
|
|
4868
4959
|
* Run the function after transaction for a `delete` kind of query will be committed.
|
|
4869
4960
|
* If the query wasn't wrapped in a transaction, will run after the query.
|
|
@@ -4872,7 +4963,7 @@ declare abstract class QueryHooks {
|
|
|
4872
4963
|
* @param select - list of columns to select for the hook
|
|
4873
4964
|
* @param cb - function to call, first argument is the query result with selected columns, second argument is a query object
|
|
4874
4965
|
*/
|
|
4875
|
-
afterDeleteCommit<T extends PickQueryShape, S extends
|
|
4966
|
+
afterDeleteCommit<T extends PickQueryShape, S extends HookSelectArg<T>>(this: T, select: S, cb: AfterHook<S, T['shape']>): T;
|
|
4876
4967
|
}
|
|
4877
4968
|
|
|
4878
4969
|
declare abstract class JsonMethods {
|
|
@@ -4921,7 +5012,7 @@ declare class QueryLog {
|
|
|
4921
5012
|
type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows> = {
|
|
4922
5013
|
[K in keyof T]: K extends 'meta' ? {
|
|
4923
5014
|
[K in keyof T['meta'] | keyof Q['meta']]: K extends 'selectable' ? MergeObjects<T['meta']['selectable'], Q['meta']['selectable']> : K extends keyof Q['meta'] ? Q['meta'][K] : T['meta'][K];
|
|
4924
|
-
} : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ?
|
|
5015
|
+
} : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? Q['returnType'] extends undefined ? T['returnType'] : Q['returnType'] : K extends 'then' ? QueryThen<GetQueryResult<QueryReturnType extends Q['returnType'] ? T : Q, MergeQueryResult<T, Q>>> : K extends 'windows' ? MergeObjects<T['windows'], Q['windows']> : K extends 'withData' ? MergeObjects<T['withData'], Q['withData']> : T[K];
|
|
4925
5016
|
};
|
|
4926
5017
|
type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? {
|
|
4927
5018
|
[K in keyof T['result'] | keyof Q['result']]: K extends keyof Q['result'] ? Q['result'][K] : T['result'][K];
|
|
@@ -4943,7 +5034,9 @@ type SelectArgs<T extends SelectSelf> = ('*' | keyof T['meta']['selectable'])[];
|
|
|
4943
5034
|
interface SelectAsArg<T extends SelectSelf> {
|
|
4944
5035
|
[K: string]: keyof T['meta']['selectable'] | Expression | ((q: {
|
|
4945
5036
|
[K in keyof T]: K extends keyof T['relations'] ? T['relations'][K]['relationConfig']['methodQuery'] : T[K];
|
|
4946
|
-
}) => QueryBase
|
|
5037
|
+
}) => (QueryBase & {
|
|
5038
|
+
returnType: Exclude<QueryReturnType, 'rows'>;
|
|
5039
|
+
}) | Expression);
|
|
4947
5040
|
}
|
|
4948
5041
|
type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = {
|
|
4949
5042
|
[K in keyof T]: K extends 'result' ? ('*' extends Columns[number] ? {
|
|
@@ -4972,9 +5065,9 @@ type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey
|
|
|
4972
5065
|
selectable: SelectAsSelectable<Obj>;
|
|
4973
5066
|
} : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
4974
5067
|
{
|
|
4975
|
-
[K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends
|
|
5068
|
+
[K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['meta']['selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends Columns[number] ? T['meta']['selectable'][K]['column'] : never;
|
|
4976
5069
|
} & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown) : K extends 'then' ? QueryThen<GetQueryResult<T, {
|
|
4977
|
-
[K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends
|
|
5070
|
+
[K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['meta']['selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends Columns[number] ? T['meta']['selectable'][K]['column'] : never;
|
|
4978
5071
|
} & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
|
|
4979
5072
|
};
|
|
4980
5073
|
type SelectAsSelectable<Arg> = {
|
|
@@ -4996,11 +5089,16 @@ type SelectAsSelectable<Arg> = {
|
|
|
4996
5089
|
} : never;
|
|
4997
5090
|
}[keyof Arg];
|
|
4998
5091
|
type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['meta']['selectable'] ? T['meta']['selectable'][Arg]['column'] : Arg extends Expression ? Arg['result']['value'] : Arg extends (q: never) => QueryBase ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends (q: never) => Expression ? ReturnType<Arg>['result']['value'] : Arg extends (q: never) => QueryBase | Expression ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression>> | Exclude<ReturnType<Arg>, QueryBase>['result']['value'] : never;
|
|
4999
|
-
type SelectSubQueryResult<Arg extends SelectSelf> =
|
|
5092
|
+
type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShapeToObjectArray<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShapeToPluck<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShapeToNullableObject<Arg['result']> : ColumnsShapeToObject<Arg['result']>;
|
|
5000
5093
|
declare const addParserForRawExpression: (q: PickQueryQ, key: string | getValueKey, raw: Expression) => void;
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5094
|
+
interface QueryBatchResult {
|
|
5095
|
+
data: any;
|
|
5096
|
+
parent: any;
|
|
5097
|
+
key: PropertyKey;
|
|
5098
|
+
}
|
|
5099
|
+
declare const addParserForSelectItem: <T extends PickQueryMeta>(q: T, as: string | getValueKey | undefined, key: string, arg: SelectableOrExpression<T> | Query) => string | Expression | Query | undefined;
|
|
5100
|
+
declare const processSelectArg: <T extends SelectSelf>(q: T, as: string | undefined, arg: SelectArg<T>, columnAs?: string | getValueKey) => SelectItem | undefined | false;
|
|
5101
|
+
declare const setParserForSelectedString: (q: PickQueryQAndInternal, arg: string, as: string | getValueKey | undefined, columnAs?: string | getValueKey) => string | undefined;
|
|
5004
5102
|
declare const getShapeFromSelect: (q: QueryBase, isSubQuery?: boolean) => QueryColumns;
|
|
5005
5103
|
declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>>(q: T, columns: Columns): SelectResult<T, Columns>;
|
|
5006
5104
|
declare function _querySelect<T extends SelectSelf, Obj extends SelectAsArg<T>>(q: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
@@ -5230,7 +5328,7 @@ declare class SqlMethod<ColumnTypes> {
|
|
|
5230
5328
|
* @return object that has `type` and `values` methods
|
|
5231
5329
|
*/
|
|
5232
5330
|
sql<T = unknown>(this: PickQueryColumnTypes, ...args: StaticSQLArgs): RawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5233
|
-
sql<T = unknown>(this: PickQueryColumnTypes, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5331
|
+
sql<T = unknown>(this: PickQueryColumnTypes, ...args: [DynamicSQLArg<QueryColumn<T>>]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5234
5332
|
}
|
|
5235
5333
|
|
|
5236
5334
|
interface WithArgsOptions {
|
|
@@ -5444,7 +5542,7 @@ type UpdateData<T extends UpdateSelf> = {
|
|
|
5444
5542
|
[K in keyof T['inputType'] | keyof T['relations']]?: K extends keyof T['inputType'] ? UpdateColumn<T, K> : UpdateRelationData<T, T['relations'][K]['relationConfig']>;
|
|
5445
5543
|
};
|
|
5446
5544
|
type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] | QueryOrExpression<T['inputType'][Key]> | ((q: T) => QueryOrExpression<T['inputType'][Key]>);
|
|
5447
|
-
type UpdateRelationData<T extends UpdateSelf, Rel extends RelationConfigBase> =
|
|
5545
|
+
type UpdateRelationData<T extends UpdateSelf, Rel extends RelationConfigBase> = T['returnType'] extends undefined | 'all' ? Rel['dataForUpdate'] : Rel['one'] extends true ? Rel['dataForUpdate'] | Rel['dataForUpdateOne'] : Rel['dataForUpdate'] & Rel['dataForUpdateOne'];
|
|
5448
5546
|
type UpdateArg<T extends UpdateSelf> = T['meta']['hasWhere'] extends true ? UpdateData<T> : never;
|
|
5449
5547
|
type UpdateRawArgs<T extends UpdateSelf> = T['meta']['hasWhere'] extends true ? SQLQueryArgs : never;
|
|
5450
5548
|
type UpdateResult<T extends UpdateSelf> = T['meta']['hasSelect'] extends true ? SetQueryKind<T, 'update'> : SetQueryReturnsRowCount<T, 'update'>;
|
|
@@ -6332,10 +6430,10 @@ declare class QueryMap {
|
|
|
6332
6430
|
*
|
|
6333
6431
|
* @param fn - function to transform an individual record
|
|
6334
6432
|
*/
|
|
6335
|
-
map<T extends Query, Result extends RecordUnknown>(this: T, fn: (input:
|
|
6433
|
+
map<T extends Query, Result extends RecordUnknown>(this: T, fn: (input: T['returnType'] extends undefined | 'all' ? T['then'] extends QueryThen<(infer Data)[]> ? Data : never : T['then'] extends QueryThen<infer Data> ? Data : never) => Result): {
|
|
6336
6434
|
[K in keyof T]: K extends 'result' ? {
|
|
6337
6435
|
[K in keyof Result]: QueryColumn<Result[K]>;
|
|
6338
|
-
} : K extends 'then' ? QueryThen<
|
|
6436
|
+
} : K extends 'then' ? QueryThen<T['returnType'] extends undefined | 'all' ? Result[] : Result> : T[K];
|
|
6339
6437
|
};
|
|
6340
6438
|
}
|
|
6341
6439
|
|
|
@@ -6357,11 +6455,13 @@ type OrderArg<T extends OrderArgSelf> = OrderArgKey<T> | OrderArgTsQuery<T> | {
|
|
|
6357
6455
|
} | Expression;
|
|
6358
6456
|
type OrderArgs<T extends OrderArgSelf> = OrderArg<T>[];
|
|
6359
6457
|
type OrderArgTsQuery<T extends OrderArgSelf> = string | undefined extends T['meta']['tsQuery'] ? never : Exclude<T['meta']['tsQuery'], undefined>;
|
|
6360
|
-
type OrderArgKey<T extends OrderArgSelf> =
|
|
6361
|
-
[K in keyof T['
|
|
6458
|
+
type OrderArgKey<T extends OrderArgSelf> = {
|
|
6459
|
+
[K in keyof T['meta']['selectable']]: T['meta']['selectable'][K]['column']['queryType'] extends undefined ? never : K;
|
|
6460
|
+
}[keyof T['meta']['selectable']] | {
|
|
6461
|
+
[K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K;
|
|
6362
6462
|
}[keyof T['result']];
|
|
6363
6463
|
type GroupArgs<T extends PickQueryResult> = ({
|
|
6364
|
-
[K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' ? never : K;
|
|
6464
|
+
[K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K;
|
|
6365
6465
|
}[keyof T['result']] | Expression)[];
|
|
6366
6466
|
interface QueryHelper<T extends PickQueryMetaShape, Args extends unknown[], Result> {
|
|
6367
6467
|
<Q extends {
|
|
@@ -6940,14 +7040,14 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6940
7040
|
}
|
|
6941
7041
|
|
|
6942
7042
|
declare const queryMethodByReturnType: {
|
|
6943
|
-
[K in
|
|
7043
|
+
[K in string]: 'query' | 'arrays';
|
|
6944
7044
|
};
|
|
6945
7045
|
declare class Then {
|
|
6946
7046
|
catch(this: Query, fn: (reason: any) => unknown): Promise<unknown>;
|
|
6947
7047
|
}
|
|
6948
|
-
declare const handleResult:
|
|
6949
|
-
declare const
|
|
6950
|
-
declare const
|
|
7048
|
+
declare const handleResult: HandleResult;
|
|
7049
|
+
declare const parseRecord: (parsers: ColumnsParsers, row: any) => unknown;
|
|
7050
|
+
declare const filterResult: (q: Query, returnType: QueryReturnType, queryResult: QueryResult, result: unknown, tempColumns: Set<string> | undefined, hasAfterHook?: unknown) => unknown;
|
|
6951
7051
|
|
|
6952
7052
|
declare function queryJson<T>(self: T, coalesce?: boolean): SetQueryReturnsColumnOptional<T, QueryColumn<string>>;
|
|
6953
7053
|
|
|
@@ -7087,20 +7187,9 @@ type SelectableOrExpressionOfType<T extends PickQueryMeta, C extends PickType> =
|
|
|
7087
7187
|
interface QueryWithTable extends Query {
|
|
7088
7188
|
table: string;
|
|
7089
7189
|
}
|
|
7090
|
-
declare const queryTypeWithLimitOne:
|
|
7091
|
-
all: true | undefined;
|
|
7092
|
-
one: true | undefined;
|
|
7093
|
-
oneOrThrow: true | undefined;
|
|
7094
|
-
rows: true | undefined;
|
|
7095
|
-
pluck: true | undefined;
|
|
7096
|
-
value: true | undefined;
|
|
7097
|
-
valueOrThrow: true | undefined;
|
|
7098
|
-
rowCount: true | undefined;
|
|
7099
|
-
void: true | undefined;
|
|
7100
|
-
};
|
|
7190
|
+
declare const queryTypeWithLimitOne: RecordKeyTrue;
|
|
7101
7191
|
declare const isQueryReturnsAll: (q: Query) => boolean;
|
|
7102
|
-
type
|
|
7103
|
-
type GetQueryResult<T extends PickQueryReturnType, Result extends QueryColumns> = QueryReturnsAll<T['returnType']> extends true ? ColumnShapeOutput<Result>[] : T['returnType'] extends 'one' ? ColumnShapeOutput<Result> | undefined : T['returnType'] extends 'oneOrThrow' ? ColumnShapeOutput<Result> : T['returnType'] extends 'value' ? Result['value']['outputType'] | undefined : T['returnType'] extends 'valueOrThrow' ? Result['value']['outputType'] : T['returnType'] extends 'rows' ? ColumnShapeOutput<Result>[keyof Result][][] : T['returnType'] extends 'pluck' ? Result['pluck']['outputType'][] : T['returnType'] extends 'rowCount' ? number : void;
|
|
7192
|
+
type GetQueryResult<T extends PickQueryReturnType, Result extends QueryColumns> = T['returnType'] extends undefined | 'all' ? ColumnShapeOutput<Result>[] : T['returnType'] extends 'one' ? ColumnShapeOutput<Result> | undefined : T['returnType'] extends 'oneOrThrow' ? ColumnShapeOutput<Result> : T['returnType'] extends 'value' ? Result['value']['outputType'] | undefined : T['returnType'] extends 'valueOrThrow' ? Result['value']['outputType'] : T['returnType'] extends 'rows' ? ColumnShapeOutput<Result>[keyof Result][][] : T['returnType'] extends 'pluck' ? Result['pluck']['outputType'][] : T['returnType'] extends 'rowCount' ? number : void;
|
|
7104
7193
|
type AddQuerySelect<T extends PickQueryMetaResultReturnType, Result extends QueryColumns> = {
|
|
7105
7194
|
[K in keyof T]: K extends 'result' ? {
|
|
7106
7195
|
[K in (T['meta']['hasSelect'] extends true ? keyof T['result'] : never) | keyof Result]: K extends keyof Result ? Result[K] : K extends keyof T['result'] ? T['result'][K] : never;
|
|
@@ -7586,7 +7675,6 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
|
|
|
7586
7675
|
bigSerial: SchemaConfig['bigSerial'];
|
|
7587
7676
|
money: SchemaConfig['money'];
|
|
7588
7677
|
varchar: SchemaConfig['varchar'];
|
|
7589
|
-
char: SchemaConfig['char'];
|
|
7590
7678
|
text: SchemaConfig['text'];
|
|
7591
7679
|
string: SchemaConfig['string'];
|
|
7592
7680
|
citext: SchemaConfig['citext'];
|
|
@@ -7675,6 +7763,7 @@ declare abstract class VirtualColumn<Schema extends ColumnSchemaConfig, InputSch
|
|
|
7675
7763
|
}
|
|
7676
7764
|
|
|
7677
7765
|
declare class UnknownColumn<Schema extends ColumnSchemaConfig> extends VirtualColumn<Schema> {
|
|
7766
|
+
static instance: UnknownColumn<DefaultSchemaConfig>;
|
|
7678
7767
|
constructor(schema: Schema);
|
|
7679
7768
|
}
|
|
7680
7769
|
|
|
@@ -7779,23 +7868,6 @@ declare const testTransaction: {
|
|
|
7779
7868
|
close(arg: Arg): Promise<void>;
|
|
7780
7869
|
};
|
|
7781
7870
|
|
|
7782
|
-
interface ComputedColumnsBase<T extends PickQueryTableMetaShape> {
|
|
7783
|
-
[K: string]: (q: T) => Expression;
|
|
7784
|
-
}
|
|
7785
|
-
type QueryWithComputed<T extends PickQueryTableMetaShape, Computed extends ComputedColumnsBase<T>, Shape extends QueryColumns = {
|
|
7786
|
-
[K in keyof Computed]: ReturnType<Computed[K]>['result']['value'];
|
|
7787
|
-
}> = {
|
|
7788
|
-
[K in keyof T]: K extends 'shape' ? T['shape'] & Shape : K extends 'meta' ? T['meta'] & {
|
|
7789
|
-
selectable: SelectableFromShape<Shape, T['table']>;
|
|
7790
|
-
} : T[K];
|
|
7791
|
-
};
|
|
7792
|
-
declare module 'orchid-core' {
|
|
7793
|
-
interface ColumnDataBase {
|
|
7794
|
-
computed?: Expression;
|
|
7795
|
-
}
|
|
7796
|
-
}
|
|
7797
|
-
declare function addComputedColumns<T extends PickQueryTableMetaShape, Computed extends ComputedColumnsBase<T>>(q: T, computed: Computed): QueryWithComputed<T, Computed>;
|
|
7798
|
-
|
|
7799
7871
|
/**
|
|
7800
7872
|
* Result type for `columnInfo` method.
|
|
7801
7873
|
* Sets query kind to 'columnInfo', returns a single value (may return undefined),
|
|
@@ -7892,4 +7964,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
7892
7964
|
*/
|
|
7893
7965
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
7894
7966
|
|
|
7895
|
-
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn,
|
|
7967
|
+
export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumn, ComputedColumns, ComputedColumnsFromOptions, ComputedMethods, ComputedOptionsFactory, 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, GroupArgs, HandleResult, Having, HavingItem, HookAction, HookSelectArg, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgToQuery, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonMethods, 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, PickQueryResultColumnTypes, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBatchResult, QueryBeforeHook, QueryComputedArg, QueryData, QueryDataFromItem, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryInternal, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryOrExpression, QueryOrExpressionBooleanOrNullResult, QueryResult, QueryScopeData, QueryScopes, QuerySourceItem, QueryUpsertOrCreate, QueryWithTable, RawSQL, RealColumn, RecordOfColumnsShapeBase, RefExpression, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, RuntimeComputedQueryColumn, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectArgs, SelectAs, SelectAsValue, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SelectableOrExpressions, 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, UnionArgs, UnionItem, UnionKind, UnionSet, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, 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, WithConfigs, 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, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|