pqb 0.69.0 → 0.70.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 +226 -200
- package/dist/index.js +60 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -18
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +203 -178
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Adapter, AdapterClass, AdapterConfigBase, AdapterParams, AdapterSchemaConfigOptions, AfterCommitStandaloneHook, AfterHook, ArrayColumn, ArrayColumnValue, ArrayData, AsyncState, BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Code, Codes, Column, ColumnFromDbParams, ColumnSchemaConfig, ColumnSchemaGetterColumns, ColumnSchemaGetterTableClass, ColumnToCodeCtx, ColumnTypeSchemaArg, ColumnsByType, ColumnsShape, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateCtx, CreateData, CreateManyMethodsNames, CreateMethodsNames, CreateSelf, CustomTypeColumn, DateColumn, DateColumnData, DbDomainArg, DbExtension, DbOptions, DbResult, DbSharedOptions, DbSqlMethod, DbStructureDomainsMap, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, DriverAdapter, DynamicRawSQL, EmptyObject, EmptyTuple, EnumColumn, Expression, ExpressionData, FromArg, FromResult, GeneratorIgnore, HookSelectValue, InetColumn, IntegerColumn, IntervalColumn, IsQuery, IsolationLevel, JSONColumn, JSONTextColumn,
|
|
1
|
+
import { Adapter, AdapterClass, AdapterConfigBase, AdapterParams, AdapterSchemaConfigOptions, AfterCommitStandaloneHook, AfterHook, ArrayColumn, ArrayColumnValue, ArrayData, AsyncState, BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Code, Codes, Column, ColumnFromDbParams, ColumnSchemaConfig, ColumnSchemaGetterColumns, ColumnSchemaGetterTableClass, ColumnToCodeCtx, ColumnTypeSchemaArg, ColumnsByType, ColumnsShape, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateCtx, CreateData, CreateManyMethodsNames, CreateMethodsNames, CreateSelf, CustomTypeColumn, DateColumn, DateColumnData, DbDomainArg, DbExtension, DbOptions, DbResult, DbSharedOptions, DbSqlMethod, DbStructureDomainsMap, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, DriverAdapter, DynamicRawSQL, EmptyObject, EmptyTuple, EnumColumn, Expression, ExpressionData, FromArg, FromResult, GeneratorIgnore, HookSelectValue, InetColumn, IntegerColumn, IntervalColumn, IsQuery, IsolationLevel, JSONColumn, JSONTextColumn, JoinedShapes, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MaybeArray, MaybePromise, MergeQuery, MoneyColumn, NoPrimaryKeyOption, NonUniqDataItem, NumberColumnData, Operators, OperatorsArray, OperatorsJson, OperatorsOrdinalText, OperatorsText, Ord, PathColumn, PickQueryInputType, PickQueryInternal, PickQueryQ, PickQueryRelations, PickQuerySelectableRelations, PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryAfterHook, QueryBeforeActionHook, QueryBeforeHook, QueryData, QueryHasWhere, QueryHookUtils, QueryHooks, QueryInternal, QueryLogObject, QueryLogOptions, QueryLogger, QueryManyTake, QueryManyTakeOptional, QueryOrExpression, QueryResult, QueryResultRow, QueryReturnType, QuerySchema, QueryScopes, RawSql, RawSqlBase, RealColumn, RecordKeyTrue, RecordOptionalString, RecordString, RecordStringOrNumber, RecordUnknown, RelationConfigBase, RelationJoinQuery, RelationsBase, Rls, RlsPolicy, SchemaConfigFnWithOptions, SearchWeight, SelectableFromShape, SerialColumn, SerialColumnData, ShallowSimplify, ShapeUniqueColumns, SingleSql, SingleSqlItem, SmallIntColumn, SmallSerialColumn, Sql, SqlFn, SqlSessionState, StorageOptions, StringColumn, StringData, TableData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TemplateLiteralArgs, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, Timestamps, ToSQLCtx, ToSqlValues, TransactionAdapter, TransactionAdapterClass, TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, UniqueConstraints, UniqueTableDataItem, UnknownColumn, UpdateData, UpsertData, UpsertThis, VarCharColumn, VirtualColumn, WhereArg, XMLColumn, _appendQuery, _appendQueryOnUpsertCreate, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, queryToSql, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, rawSqlToSql, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry } from "./index.d.ts";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
interface RelationJoinQuery$1 {
|
|
4
4
|
(joiningQuery: IsQuery$1, baseQuery: IsQuery$1): IsQuery$1;
|
|
@@ -3164,169 +3164,6 @@ interface AggregateOptions<T extends PickQuerySelectableResultRelationsWindows>
|
|
|
3164
3164
|
over?: Over<T>;
|
|
3165
3165
|
}
|
|
3166
3166
|
type Over<T extends PickQuerySelectableResultWindows> = keyof T['windows'] | WindowArgDeclaration<T>;
|
|
3167
|
-
interface ColumnsShape$1 {
|
|
3168
|
-
[K: string]: Column$1;
|
|
3169
|
-
}
|
|
3170
|
-
declare namespace ColumnsShape$1 {
|
|
3171
|
-
export type DefaultSelectKeys<S extends Column$1.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
|
|
3172
|
-
export type DefaultOutput<Set extends Column$1.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
|
|
3173
|
-
export type Input<Shape extends Column$1.QueryColumnsInit, AppReadOnly = { [K in keyof Shape]: Shape[K]['data']['appReadOnly'] extends true ? K : never }[keyof Shape], Optional extends keyof Shape = { [K in keyof Shape]: Shape[K]['data']['optional'] extends true ? K : never }[keyof Shape]> = { [K in Exclude<keyof Shape, AppReadOnly | Optional>]: Shape[K]['__inputType'] } & { [K in Exclude<Optional, AppReadOnly>]?: Shape[K]['__inputType'] };
|
|
3174
|
-
export type InputPartial<Shape extends Column$1.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
|
|
3175
|
-
export type Output<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
3176
|
-
export type DefaultSelectOutput<Shape extends Column$1.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
|
|
3177
|
-
export interface MapToObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
3178
|
-
dataType: 'object';
|
|
3179
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
3180
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>;
|
|
3181
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
|
|
3182
|
-
operators: OperatorsAny;
|
|
3183
|
-
}
|
|
3184
|
-
export interface MapToNullableObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
3185
|
-
dataType: 'object';
|
|
3186
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
3187
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>> | undefined;
|
|
3188
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
|
|
3189
|
-
operators: OperatorsAny;
|
|
3190
|
-
}
|
|
3191
|
-
export interface MapToPluckColumn<Shape extends Column$1.QueryColumns> {
|
|
3192
|
-
dataType: 'array';
|
|
3193
|
-
__type: Shape['pluck']['__type'][];
|
|
3194
|
-
__outputType: Shape['pluck']['__outputType'][];
|
|
3195
|
-
__queryType: Shape['pluck']['__queryType'][];
|
|
3196
|
-
operators: OperatorsAny;
|
|
3197
|
-
}
|
|
3198
|
-
export interface MapToObjectArrayColumn<Shape extends Column$1.QueryColumns> {
|
|
3199
|
-
dataType: 'array';
|
|
3200
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] }[];
|
|
3201
|
-
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>[];
|
|
3202
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
|
|
3203
|
-
operators: OperatorsAny;
|
|
3204
|
-
}
|
|
3205
|
-
type ObjectOutput<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
3206
|
-
export {};
|
|
3207
|
-
}
|
|
3208
|
-
interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape$1, PickQueryRelations$1, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
|
|
3209
|
-
type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
3210
|
-
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
3211
|
-
withData: T['withData'];
|
|
3212
|
-
}
|
|
3213
|
-
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject$1 extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? RelationQueryMaybeSingle<T['relations'][K]> & SubQueryAddition<T> : K extends keyof T ? T[K] : never };
|
|
3214
|
-
interface SelectAsArg<T extends SelectSelf> {
|
|
3215
|
-
[K: string]: keyof T['__selectable'] | Expression$1 | ((q: SelectAsFnArg<T>) => unknown);
|
|
3216
|
-
}
|
|
3217
|
-
type SelectAsFnReturnType = {
|
|
3218
|
-
result: Column$1.QueryColumns;
|
|
3219
|
-
returnType: Exclude<QueryReturnType$1, 'rows'>;
|
|
3220
|
-
} | Expression$1;
|
|
3221
|
-
interface SelectAsCheckReturnTypes {
|
|
3222
|
-
[K: string]: PropertyKey | Expression$1 | ((q: never) => SelectAsFnReturnType);
|
|
3223
|
-
}
|
|
3224
|
-
type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
|
|
3225
|
-
type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
3226
|
-
type SelectResultObj<T extends SelectSelf, Obj> = Obj extends SelectAsCheckReturnTypes ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never } : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never }> : T[K] } : `Invalid return type of ${{ [K in keyof Obj]: Obj[K] extends ((...args: any[]) => any) ? ReturnType<Obj[K]> extends SelectAsFnReturnType ? never : K : never }[keyof Obj] & string}`;
|
|
3227
|
-
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
3228
|
-
{ [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
3229
|
-
interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
3230
|
-
result: Column$1.QueryColumns;
|
|
3231
|
-
returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
|
|
3232
|
-
}
|
|
3233
|
-
type SelectAsSelectable<Obj> = UnionToIntersection<{ [K in keyof Obj]: Obj[K] extends ((q: never) => infer R extends AllowedRelationOneQueryForSelectable) ? { [C in R['returnType'] extends 'value' | 'valueOrThrow' ? K : keyof R['result'] as R['returnType'] extends 'value' | 'valueOrThrow' ? K : `${K & string}.${C & string}`]: {
|
|
3234
|
-
as: C;
|
|
3235
|
-
column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
|
|
3236
|
-
} } : never }[keyof Obj]>;
|
|
3237
|
-
type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery$1) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression$1) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery$1 | Expression$1) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression$1>> | Exclude<ReturnType<Arg>, IsQuery$1>['result']['value'] : never;
|
|
3238
|
-
type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape$1.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape$1.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape$1.MapToNullableObjectColumn<Arg['result']> : ColumnsShape$1.MapToObjectColumn<Arg['result']>;
|
|
3239
|
-
declare class Select {
|
|
3240
|
-
/**
|
|
3241
|
-
* Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
|
|
3242
|
-
*
|
|
3243
|
-
* The last argument can be an object. Keys of the object are column aliases, value can be a column name, sub-query, or raw SQL expression.
|
|
3244
|
-
*
|
|
3245
|
-
* ```ts
|
|
3246
|
-
* import { sql } from './baseTable'
|
|
3247
|
-
*
|
|
3248
|
-
* // select columns of the table:
|
|
3249
|
-
* db.table.select('id', 'name', { idAlias: 'id' });
|
|
3250
|
-
*
|
|
3251
|
-
* // accepts columns with table names:
|
|
3252
|
-
* db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
|
|
3253
|
-
*
|
|
3254
|
-
* // table name may refer to the current table or a joined table:
|
|
3255
|
-
* db.table
|
|
3256
|
-
* .join(db.message, 'authorId', 'user.id')
|
|
3257
|
-
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
3258
|
-
*
|
|
3259
|
-
* // select value from the sub-query,
|
|
3260
|
-
* // this sub-query should return a single record and a single column:
|
|
3261
|
-
* db.table.select({
|
|
3262
|
-
* subQueryResult: Otherdb.table.select('column').take(),
|
|
3263
|
-
* });
|
|
3264
|
-
*
|
|
3265
|
-
* // select raw SQL value, specify the returning type via <generic> syntax:
|
|
3266
|
-
* db.table.select({
|
|
3267
|
-
* raw: sql<number>`1 + 2`,
|
|
3268
|
-
* });
|
|
3269
|
-
*
|
|
3270
|
-
* // select raw SQL value, the resulting type can be set by providing a column type in such way:
|
|
3271
|
-
* db.table.select({
|
|
3272
|
-
* raw: sql`1 + 2`.type((t) => t.integer()),
|
|
3273
|
-
* });
|
|
3274
|
-
*
|
|
3275
|
-
* // same raw SQL query as above, but the sql is returned from a callback
|
|
3276
|
-
* db.table.select({
|
|
3277
|
-
* raw: () => sql`1 + 2`.type((t) => t.integer()),
|
|
3278
|
-
* });
|
|
3279
|
-
* ```
|
|
3280
|
-
*
|
|
3281
|
-
* When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
|
|
3282
|
-
*
|
|
3283
|
-
* ```ts
|
|
3284
|
-
* await db.author.select({
|
|
3285
|
-
* allBooks: (q) => q.books,
|
|
3286
|
-
* firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
|
|
3287
|
-
* booksCount: (q) => q.books.count(),
|
|
3288
|
-
* });
|
|
3289
|
-
* ```
|
|
3290
|
-
*
|
|
3291
|
-
* When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
|
|
3292
|
-
*
|
|
3293
|
-
* ```ts
|
|
3294
|
-
* // select books with their authors included, order by author name and filter by author column:
|
|
3295
|
-
* await db.books
|
|
3296
|
-
* .select({
|
|
3297
|
-
* author: (q) => q.author,
|
|
3298
|
-
* })
|
|
3299
|
-
* .order('author.name')
|
|
3300
|
-
* .where({ 'author.isPopular': true });
|
|
3301
|
-
* ```
|
|
3302
|
-
*/
|
|
3303
|
-
select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
|
|
3304
|
-
select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
3305
|
-
select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
|
|
3306
|
-
/**
|
|
3307
|
-
* When querying the table or creating records, all columns are selected by default,
|
|
3308
|
-
* but updating and deleting queries are returning affected row counts by default.
|
|
3309
|
-
*
|
|
3310
|
-
* Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
|
|
3311
|
-
*
|
|
3312
|
-
* ```ts
|
|
3313
|
-
* const selectFull = await db.table
|
|
3314
|
-
* .select('id', 'name') // discarded by `selectAll`
|
|
3315
|
-
* .selectAll();
|
|
3316
|
-
*
|
|
3317
|
-
* const updatedFull = await db.table.selectAll().where(conditions).update(data);
|
|
3318
|
-
*
|
|
3319
|
-
* const deletedFull = await db.table.selectAll().where(conditions).delete();
|
|
3320
|
-
* ```
|
|
3321
|
-
*/
|
|
3322
|
-
selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
|
|
3323
|
-
}
|
|
3324
|
-
interface QueryGetSelf extends PickQuerySelectable, PickQueryRelationsWithData {}
|
|
3325
|
-
type GetArg<T extends QueryGetSelf> = GetStringArg<T> | Expression$1 | ((q: SelectAsFnArg<T>) => Expression$1 | Query.Pick.SingleValueResult);
|
|
3326
|
-
type GetStringArg<T extends PickQuerySelectable> = keyof T['__selectable'] & string;
|
|
3327
|
-
type ResolveGetArgColumn<Arg> = Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => infer R) ? R extends Expression$1 ? R['result']['value'] : R extends Query.Pick.SingleValueResult ? R['result']['value'] : never : never;
|
|
3328
|
-
type GetResult<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOrThrow<T, Arg> : SetQueryReturnsColumnOrThrow<T, ResolveGetArgColumn<Arg>>;
|
|
3329
|
-
type GetResultOptional<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOptional<T, Arg> : SetQueryReturnsColumnOptional<T, ResolveGetArgColumn<Arg>>;
|
|
3330
3167
|
type HeadlineSearchArg<T extends PickQueryTsQuery> = Exclude<T['__tsQuery'], undefined>;
|
|
3331
3168
|
interface HeadlineParams<T extends PickQuerySelectable> {
|
|
3332
3169
|
text?: SelectableOrExpressionOfType<T, Column$1.Pick.QueryColumnOfType<string>>;
|
|
@@ -3663,16 +3500,6 @@ interface AggregateArgTypes {
|
|
|
3663
3500
|
}
|
|
3664
3501
|
interface AggregateMethods extends SearchAggregateMethods {}
|
|
3665
3502
|
declare class AggregateMethods {
|
|
3666
|
-
/**
|
|
3667
|
-
* Use `exists()` to check if there is at least one record-matching condition.
|
|
3668
|
-
*
|
|
3669
|
-
* It will discard previous `select` statements if any. Returns a boolean.
|
|
3670
|
-
*
|
|
3671
|
-
* ```ts
|
|
3672
|
-
* const exists: boolean = await db.table.where(...conditions).exists();
|
|
3673
|
-
* ```
|
|
3674
|
-
*/
|
|
3675
|
-
exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
|
|
3676
3503
|
/**
|
|
3677
3504
|
* Count records with the `count` function:
|
|
3678
3505
|
*
|
|
@@ -5823,6 +5650,169 @@ declare class FromMethods {
|
|
|
5823
5650
|
*/
|
|
5824
5651
|
only<T>(this: T, only?: boolean): T;
|
|
5825
5652
|
}
|
|
5653
|
+
interface ColumnsShape$1 {
|
|
5654
|
+
[K: string]: Column$1;
|
|
5655
|
+
}
|
|
5656
|
+
declare namespace ColumnsShape$1 {
|
|
5657
|
+
export type DefaultSelectKeys<S extends Column$1.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
|
|
5658
|
+
export type DefaultOutput<Set extends Column$1.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
|
|
5659
|
+
export type Input<Shape extends Column$1.QueryColumnsInit, AppReadOnly = { [K in keyof Shape]: Shape[K]['data']['appReadOnly'] extends true ? K : never }[keyof Shape], Optional extends keyof Shape = { [K in keyof Shape]: Shape[K]['data']['optional'] extends true ? K : never }[keyof Shape]> = { [K in Exclude<keyof Shape, AppReadOnly | Optional>]: Shape[K]['__inputType'] } & { [K in Exclude<Optional, AppReadOnly>]?: Shape[K]['__inputType'] };
|
|
5660
|
+
export type InputPartial<Shape extends Column$1.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
|
|
5661
|
+
export type Output<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5662
|
+
export type DefaultSelectOutput<Shape extends Column$1.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
|
|
5663
|
+
export interface MapToObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5664
|
+
dataType: 'object';
|
|
5665
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5666
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>;
|
|
5667
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
|
|
5668
|
+
operators: OperatorsAny;
|
|
5669
|
+
}
|
|
5670
|
+
export interface MapToNullableObjectColumn<Shape extends Column$1.QueryColumns> {
|
|
5671
|
+
dataType: 'object';
|
|
5672
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5673
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>> | undefined;
|
|
5674
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
|
|
5675
|
+
operators: OperatorsAny;
|
|
5676
|
+
}
|
|
5677
|
+
export interface MapToPluckColumn<Shape extends Column$1.QueryColumns> {
|
|
5678
|
+
dataType: 'array';
|
|
5679
|
+
__type: Shape['pluck']['__type'][];
|
|
5680
|
+
__outputType: Shape['pluck']['__outputType'][];
|
|
5681
|
+
__queryType: Shape['pluck']['__queryType'][];
|
|
5682
|
+
operators: OperatorsAny;
|
|
5683
|
+
}
|
|
5684
|
+
export interface MapToObjectArrayColumn<Shape extends Column$1.QueryColumns> {
|
|
5685
|
+
dataType: 'array';
|
|
5686
|
+
__type: { [K in keyof Shape]: Shape[K]['__type'] }[];
|
|
5687
|
+
__outputType: ShallowSimplify$1<ObjectOutput<Shape>>[];
|
|
5688
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
|
|
5689
|
+
operators: OperatorsAny;
|
|
5690
|
+
}
|
|
5691
|
+
type ObjectOutput<Shape extends Column$1.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5692
|
+
export {};
|
|
5693
|
+
}
|
|
5694
|
+
interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape$1, PickQueryRelations$1, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
|
|
5695
|
+
type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
5696
|
+
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
5697
|
+
withData: T['withData'];
|
|
5698
|
+
}
|
|
5699
|
+
type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject$1 extends T['relations'] ? T : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? RelationQueryMaybeSingle<T['relations'][K]> & SubQueryAddition<T> : K extends keyof T ? T[K] : never };
|
|
5700
|
+
interface SelectAsArg<T extends SelectSelf> {
|
|
5701
|
+
[K: string]: keyof T['__selectable'] | Expression$1 | ((q: SelectAsFnArg<T>) => unknown);
|
|
5702
|
+
}
|
|
5703
|
+
type SelectAsFnReturnType = {
|
|
5704
|
+
result: Column$1.QueryColumns;
|
|
5705
|
+
returnType: Exclude<QueryReturnType$1, 'rows'>;
|
|
5706
|
+
} | Expression$1;
|
|
5707
|
+
interface SelectAsCheckReturnTypes {
|
|
5708
|
+
[K: string]: PropertyKey | Expression$1 | ((q: never) => SelectAsFnReturnType);
|
|
5709
|
+
}
|
|
5710
|
+
type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
|
|
5711
|
+
type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in '*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number] as T['__selectable'][K]['as']]: T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5712
|
+
type SelectResultObj<T extends SelectSelf, Obj> = Obj extends SelectAsCheckReturnTypes ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never } : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? keyof Obj | keyof T['result'] : keyof Obj]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never }> : T[K] } : `Invalid return type of ${{ [K in keyof Obj]: Obj[K] extends ((...args: any[]) => any) ? ReturnType<Obj[K]> extends SelectAsFnReturnType ? never : K : never }[keyof Obj] & string}`;
|
|
5713
|
+
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = { [K in keyof T]: K extends '__hasSelect' ? true : K extends '__selectable' ? T['__selectable'] & SelectAsSelectable<Obj> : K extends 'result' ? // Combine previously selected items, all columns if * was provided,
|
|
5714
|
+
{ [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown) : K extends 'returnType' ? SelectReturnType<T> : K extends 'then' ? QueryThenByReturnType<SelectReturnType<T>, { [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | T['__defaultSelect'] : Columns[number]) | keyof Obj as K extends Columns[number] ? T['__selectable'][K]['as'] : K]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : T['__selectable'][K]['column'] } & (T['__hasSelect'] extends (T['returnType'] extends 'value' | 'valueOrThrow' ? never : true) ? Omit<T['result'], Columns[number]> : unknown)> : T[K] };
|
|
5715
|
+
interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
5716
|
+
result: Column$1.QueryColumns;
|
|
5717
|
+
returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
|
|
5718
|
+
}
|
|
5719
|
+
type SelectAsSelectable<Obj> = UnionToIntersection<{ [K in keyof Obj]: Obj[K] extends ((q: never) => infer R extends AllowedRelationOneQueryForSelectable) ? { [C in R['returnType'] extends 'value' | 'valueOrThrow' ? K : keyof R['result'] as R['returnType'] extends 'value' | 'valueOrThrow' ? K : `${K & string}.${C & string}`]: {
|
|
5720
|
+
as: C;
|
|
5721
|
+
column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
|
|
5722
|
+
} } : never }[keyof Obj]>;
|
|
5723
|
+
type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery$1) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression$1) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery$1 | Expression$1) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression$1>> | Exclude<ReturnType<Arg>, IsQuery$1>['result']['value'] : never;
|
|
5724
|
+
type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape$1.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape$1.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape$1.MapToNullableObjectColumn<Arg['result']> : ColumnsShape$1.MapToObjectColumn<Arg['result']>;
|
|
5725
|
+
declare class Select {
|
|
5726
|
+
/**
|
|
5727
|
+
* Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
|
|
5728
|
+
*
|
|
5729
|
+
* The last argument can be an object. Keys of the object are column aliases, value can be a column name, sub-query, or raw SQL expression.
|
|
5730
|
+
*
|
|
5731
|
+
* ```ts
|
|
5732
|
+
* import { sql } from './baseTable'
|
|
5733
|
+
*
|
|
5734
|
+
* // select columns of the table:
|
|
5735
|
+
* db.table.select('id', 'name', { idAlias: 'id' });
|
|
5736
|
+
*
|
|
5737
|
+
* // accepts columns with table names:
|
|
5738
|
+
* db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
|
|
5739
|
+
*
|
|
5740
|
+
* // table name may refer to the current table or a joined table:
|
|
5741
|
+
* db.table
|
|
5742
|
+
* .join(db.message, 'authorId', 'user.id')
|
|
5743
|
+
* .select('user.name', 'message.text', { textAlias: 'message.text' });
|
|
5744
|
+
*
|
|
5745
|
+
* // select value from the sub-query,
|
|
5746
|
+
* // this sub-query should return a single record and a single column:
|
|
5747
|
+
* db.table.select({
|
|
5748
|
+
* subQueryResult: Otherdb.table.select('column').take(),
|
|
5749
|
+
* });
|
|
5750
|
+
*
|
|
5751
|
+
* // select raw SQL value, specify the returning type via <generic> syntax:
|
|
5752
|
+
* db.table.select({
|
|
5753
|
+
* raw: sql<number>`1 + 2`,
|
|
5754
|
+
* });
|
|
5755
|
+
*
|
|
5756
|
+
* // select raw SQL value, the resulting type can be set by providing a column type in such way:
|
|
5757
|
+
* db.table.select({
|
|
5758
|
+
* raw: sql`1 + 2`.type((t) => t.integer()),
|
|
5759
|
+
* });
|
|
5760
|
+
*
|
|
5761
|
+
* // same raw SQL query as above, but the sql is returned from a callback
|
|
5762
|
+
* db.table.select({
|
|
5763
|
+
* raw: () => sql`1 + 2`.type((t) => t.integer()),
|
|
5764
|
+
* });
|
|
5765
|
+
* ```
|
|
5766
|
+
*
|
|
5767
|
+
* When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
|
|
5768
|
+
*
|
|
5769
|
+
* ```ts
|
|
5770
|
+
* await db.author.select({
|
|
5771
|
+
* allBooks: (q) => q.books,
|
|
5772
|
+
* firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
|
|
5773
|
+
* booksCount: (q) => q.books.count(),
|
|
5774
|
+
* });
|
|
5775
|
+
* ```
|
|
5776
|
+
*
|
|
5777
|
+
* When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
|
|
5778
|
+
*
|
|
5779
|
+
* ```ts
|
|
5780
|
+
* // select books with their authors included, order by author name and filter by author column:
|
|
5781
|
+
* await db.books
|
|
5782
|
+
* .select({
|
|
5783
|
+
* author: (q) => q.author,
|
|
5784
|
+
* })
|
|
5785
|
+
* .order('author.name')
|
|
5786
|
+
* .where({ 'author.isPopular': true });
|
|
5787
|
+
* ```
|
|
5788
|
+
*/
|
|
5789
|
+
select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
|
|
5790
|
+
select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
|
|
5791
|
+
select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
|
|
5792
|
+
/**
|
|
5793
|
+
* When querying the table or creating records, all columns are selected by default,
|
|
5794
|
+
* but updating and deleting queries are returning affected row counts by default.
|
|
5795
|
+
*
|
|
5796
|
+
* Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
|
|
5797
|
+
*
|
|
5798
|
+
* ```ts
|
|
5799
|
+
* const selectFull = await db.table
|
|
5800
|
+
* .select('id', 'name') // discarded by `selectAll`
|
|
5801
|
+
* .selectAll();
|
|
5802
|
+
*
|
|
5803
|
+
* const updatedFull = await db.table.selectAll().where(conditions).update(data);
|
|
5804
|
+
*
|
|
5805
|
+
* const deletedFull = await db.table.selectAll().where(conditions).delete();
|
|
5806
|
+
* ```
|
|
5807
|
+
*/
|
|
5808
|
+
selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
|
|
5809
|
+
}
|
|
5810
|
+
interface QueryGetSelf extends PickQuerySelectable, PickQueryRelationsWithData {}
|
|
5811
|
+
type GetArg<T extends QueryGetSelf> = GetStringArg<T> | Expression$1 | ((q: SelectAsFnArg<T>) => Expression$1 | Query.Pick.SingleValueResult);
|
|
5812
|
+
type GetStringArg<T extends PickQuerySelectable> = keyof T['__selectable'] & string;
|
|
5813
|
+
type ResolveGetArgColumn<Arg> = Arg extends Expression$1 ? Arg['result']['value'] : Arg extends ((q: never) => infer R) ? R extends Expression$1 ? R['result']['value'] : R extends Query.Pick.SingleValueResult ? R['result']['value'] : never : never;
|
|
5814
|
+
type GetResult<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOrThrow<T, Arg> : SetQueryReturnsColumnOrThrow<T, ResolveGetArgColumn<Arg>>;
|
|
5815
|
+
type GetResultOptional<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOptional<T, Arg> : SetQueryReturnsColumnOptional<T, ResolveGetArgColumn<Arg>>;
|
|
5826
5816
|
declare class QueryGet {
|
|
5827
5817
|
/**
|
|
5828
5818
|
* `.get` returns a single value, adds `LIMIT 1` to the query, and accepts a column name or a raw SQL expression.
|
|
@@ -8893,6 +8883,28 @@ declare class QueryTruncate {
|
|
|
8893
8883
|
cascade?: boolean;
|
|
8894
8884
|
}): SetQueryReturnsVoid<T>;
|
|
8895
8885
|
}
|
|
8886
|
+
declare class QueryExistsMethods {
|
|
8887
|
+
/**
|
|
8888
|
+
* Use `exists()` to check if there is at least one record-matching condition.
|
|
8889
|
+
*
|
|
8890
|
+
* It will discard previous `select` statements if any. Returns a boolean.
|
|
8891
|
+
*
|
|
8892
|
+
* ```ts
|
|
8893
|
+
* const exists: boolean = await db.table.where(...conditions).exists();
|
|
8894
|
+
* ```
|
|
8895
|
+
*/
|
|
8896
|
+
exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
|
|
8897
|
+
/**
|
|
8898
|
+
* Use `notExists()` to check if there are no matching records.
|
|
8899
|
+
*
|
|
8900
|
+
* It will discard previous `select` statements if any. Returns a boolean.
|
|
8901
|
+
*
|
|
8902
|
+
* ```ts
|
|
8903
|
+
* const exists: boolean = await db.table.where(...conditions).notExists();
|
|
8904
|
+
* ```
|
|
8905
|
+
*/
|
|
8906
|
+
notExists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
|
|
8907
|
+
}
|
|
8896
8908
|
type GroupArgs<T extends PickQueryResult> = ({ [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K }[keyof T['result']] | Expression$1)[];
|
|
8897
8909
|
interface QueryHelperQuery<T extends PickQuerySelectableShapeAs> extends MergeQueryArg {
|
|
8898
8910
|
returnType: QueryReturnType$1;
|
|
@@ -8930,7 +8942,7 @@ interface NarrowPluckTypeResult<T extends PickQueryResultReturnType, Narrow> ext
|
|
|
8930
8942
|
}
|
|
8931
8943
|
type QueryIfResult<T extends PickQueryResultReturnType, R extends PickQueryResult> = { [K in keyof T]: K extends 'result' ? { [K in keyof T['result'] | keyof R['result']]: K extends keyof T['result'] ? K extends keyof R['result'] ? R['result'][K] | T['result'][K] : T['result'][K] : Column$1.Modifiers.QueryColumnToOptional<R['result'][K]> } : K extends 'then' ? QueryIfResultThen<T, R> : T[K] };
|
|
8932
8944
|
type QueryIfResultThen<T extends PickQueryResultReturnType, R extends PickQueryResult> = T['returnType'] extends undefined | 'all' ? QueryThenShallowSimplifyArr<{ [K in keyof T['result']]: K extends keyof R['result'] ? T['result'][K]['__outputType'] | R['result'][K]['__outputType'] : T['result'][K]['__outputType'] } & { [K in keyof R['result'] as K extends keyof T['result'] ? never : K]?: R['result'][K]['__outputType'] }> : T['returnType'] extends 'one' ? QueryThenShallowSimplifyOptional<{ [K in keyof T['result']]: K extends keyof R['result'] ? T['result'][K]['__outputType'] | R['result'][K]['__outputType'] : T['result'][K]['__outputType'] } & { [K in keyof R['result'] as K extends keyof T['result'] ? never : K]?: R['result'][K]['__outputType'] }> : T['returnType'] extends 'oneOrThrow' ? QueryThenShallowSimplify<{ [K in keyof T['result']]: K extends keyof R['result'] ? T['result'][K]['__outputType'] | R['result'][K]['__outputType'] : T['result'][K]['__outputType'] } & { [K in keyof R['result'] as K extends keyof T['result'] ? never : K]?: R['result'][K]['__outputType'] }> : T['returnType'] extends 'value' ? QueryThen<T['result']['value']['__outputType'] | R['result']['value']['__outputType'] | undefined> : T['returnType'] extends 'valueOrThrow' ? QueryThen<T['result']['value']['__outputType'] | R['result']['value']['__outputType']> : T['returnType'] extends 'rows' ? QueryThen<(T['result'][keyof T['result']]['__outputType'] | R['result'][keyof R['result']]['__outputType'])[][]> : T['returnType'] extends 'pluck' ? QueryThen<(T['result']['pluck']['__outputType'] | R['result']['pluck']['__outputType'])[]> : QueryThen<void>;
|
|
8933
|
-
interface QueryMethods<ColumnTypes> extends QueryClone, QueryAsMethods, AggregateMethods, QueryDistinct, Select, FromMethods, QueryJoin, QueryLimitOffset, CteQuery, Union, QueryJsonMethods, QueryCreate, QueryCreateFrom, QueryUpdate, QueryDelete, QueryStorage, QueryTransaction, QueryTruncate, For, Where, SearchMethods, Clear, Having, QueryCatchers, QueryLog, QueryOrder, QueryWithSchema, QueryHooks$1, QueryUpsert, QueryOrCreate, QueryGet, QueryPluck, MergeQueryMethods, QuerySql<ColumnTypes>, QueryTransform, QueryMap, QueryScope, SoftDeleteMethods, QueryExpressions, QueryWrap, QueryWindow {}
|
|
8945
|
+
interface QueryMethods<ColumnTypes> extends QueryClone, QueryAsMethods, AggregateMethods, QueryDistinct, Select, FromMethods, QueryJoin, QueryLimitOffset, CteQuery, Union, QueryJsonMethods, QueryCreate, QueryCreateFrom, QueryUpdate, QueryDelete, QueryStorage, QueryTransaction, QueryTruncate, For, Where, SearchMethods, Clear, Having, QueryCatchers, QueryLog, QueryOrder, QueryWithSchema, QueryHooks$1, QueryUpsert, QueryOrCreate, QueryGet, QueryPluck, MergeQueryMethods, QuerySql<ColumnTypes>, QueryTransform, QueryMap, QueryScope, SoftDeleteMethods, QueryExpressions, QueryWrap, QueryWindow, QueryExistsMethods {}
|
|
8934
8946
|
declare class QueryMethods<ColumnTypes> {
|
|
8935
8947
|
/**
|
|
8936
8948
|
* `.all` is a default behavior, that returns an array of objects:
|
|
@@ -8993,6 +9005,15 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
8993
9005
|
* ```
|
|
8994
9006
|
*/
|
|
8995
9007
|
exec<T>(this: T): SetQueryReturnsVoid<T>;
|
|
9008
|
+
/**
|
|
9009
|
+
* For relation selects, `require` changes LEFT JOIN LATERAL to JOIN LATERAL.
|
|
9010
|
+
*
|
|
9011
|
+
* ```ts
|
|
9012
|
+
* // only the records that have `related` will be loaded:
|
|
9013
|
+
* await db.table.select({ related: (q) => q.related.required() });
|
|
9014
|
+
* ```
|
|
9015
|
+
*/
|
|
9016
|
+
require<T extends PickQueryResultReturnType>(this: T): QueryRequire<T>;
|
|
8996
9017
|
/**
|
|
8997
9018
|
* Call `toSQL` on a query to get an object with a `text` SQL string and a `values` array of binding values:
|
|
8998
9019
|
*
|
|
@@ -9181,7 +9202,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
9181
9202
|
* // all the following queries will resolve into empty arrays
|
|
9182
9203
|
*
|
|
9183
9204
|
* await db.user.select({
|
|
9184
|
-
* pets: (q) => q.pets.
|
|
9205
|
+
* pets: (q) => q.pets.require().none(),
|
|
9185
9206
|
* });
|
|
9186
9207
|
*
|
|
9187
9208
|
* await db.user.join((q) => q.pets.none());
|
|
@@ -9253,7 +9274,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
9253
9274
|
*
|
|
9254
9275
|
* @param fn - helper function
|
|
9255
9276
|
*/
|
|
9256
|
-
makeHelper<T extends PickQuerySelectableShapeAs, Args extends unknown[], Result extends MergeQueryArg>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
|
|
9277
|
+
makeHelper<T extends PickQuerySelectableShapeAs, Args extends unknown[], Result extends MergeQueryArg | Expression$1>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
|
|
9257
9278
|
/**
|
|
9258
9279
|
* `useHelper` allows to use {@link makeHelper} in different queries:
|
|
9259
9280
|
*
|
|
@@ -9462,6 +9483,9 @@ declare namespace Query {
|
|
|
9462
9483
|
type Args<T extends Order.ArgThis> = Order.Args<T>;
|
|
9463
9484
|
}
|
|
9464
9485
|
namespace Pick {
|
|
9486
|
+
interface ReturnType {
|
|
9487
|
+
returnType: QueryReturnType$1;
|
|
9488
|
+
}
|
|
9465
9489
|
interface SingleValueResult {
|
|
9466
9490
|
result: {
|
|
9467
9491
|
value: Column$1.Pick.OutputType;
|
|
@@ -9482,6 +9506,7 @@ type SetQueryReturnsAll<T extends PickQueryResult> = { [K in keyof T]: K extends
|
|
|
9482
9506
|
type SetQueryReturnsAllResult<T extends PickQueryResult, Result extends Column$1.QueryColumns> = { [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'result' ? Result : K extends 'then' ? QueryThenShallowSimplifyArr<T['result']> : T[K] } & QueryHasWhere$1;
|
|
9483
9507
|
type QueryTakeOptional<T extends PickQueryResultReturnType> = T['returnType'] extends 'value' | 'pluck' | 'void' ? T : T['returnType'] extends 'valueOrThrow' ? { [K in keyof T]: K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<T['result']['value']['__outputType'] | undefined> : T[K] } : { [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
9484
9508
|
type QueryManyTakeOptional$1<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
9509
|
+
type QueryRequire<T extends PickQueryResultReturnType> = T['returnType'] extends QueryReturnTypeAll | 'valueOrThrow' | 'pluck' | 'void' ? T : T['returnType'] extends 'value' ? { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Exclude<T['result']['value']['__outputType'], undefined>> : T[K] } : { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
9485
9510
|
type QueryTake<T extends PickQueryResultReturnType> = T['returnType'] extends 'valueOrThrow' | 'pluck' | 'void' ? T : T['returnType'] extends 'value' ? { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Exclude<T['result']['value']['__outputType'], undefined>> : T[K] } : { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
9486
9511
|
type QueryManyTake$1<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
9487
9512
|
type SetQueryReturnsOne<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape$1.Output<T['result']>> : T[K] };
|
|
@@ -9988,4 +10013,4 @@ declare class QueryUpdate {
|
|
|
9988
10013
|
*/
|
|
9989
10014
|
updateManyByOptional<T extends UpdateManyBySelf, Keys extends UpdateManyByKeys<T>, K = UpdateManyByKeyColumns<Keys>>(this: T, keys: Keys, data: UpdateManyByData<T, K>): UpdateManyResult<T> & QueryHasWhere$1;
|
|
9990
10015
|
}
|
|
9991
|
-
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CannotMutateReadOnlyTableError, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateColumn, type DateColumnData, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type Grant, type HookSelectValue, InetColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type
|
|
10016
|
+
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CannotMutateReadOnlyTableError, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateColumn, type DateColumnData, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type Grant, type HookSelectValue, InetColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinedShapes, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, type OperatorsText, OrchidOrmError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type QueryAfterHook, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, type QueryHasWhere, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type ToSQLCtx, type ToSqlValues, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpdateSelf, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _appendQueryOnUpsertCreate, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, queryToSql, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, rawSqlToSql, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|