pqb 0.69.0 → 0.71.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 CHANGED
@@ -642,7 +642,7 @@ interface ColumnSchemaGetterTableClass {
642
642
  type ColumnSchemaGetterColumns<T extends ColumnSchemaGetterTableClass> = T['prototype']['columns']['shape'];
643
643
  interface ColumnTypeSchemaArg {
644
644
  __schemaType: unknown;
645
- nullable<T extends Column.Pick.ForNullable>(this: T): Column.Modifiers.Nullable<T, unknown, unknown, unknown>;
645
+ nullable: unknown;
646
646
  encode: unknown;
647
647
  parse: unknown;
648
648
  parseNull: unknown;
@@ -1064,7 +1064,7 @@ interface NumberColumnData extends BaseNumberData, Column.Data {
1064
1064
  identity?: TableData.Identity;
1065
1065
  }
1066
1066
  interface SerialColumnData extends NumberColumnData {
1067
- default: Expression;
1067
+ default: true;
1068
1068
  }
1069
1069
  declare abstract class NumberBaseColumn<Schema extends ColumnSchemaConfig, SchemaType extends Schema['__schemaType']> extends Column {
1070
1070
  __schema: Schema;
@@ -1109,27 +1109,26 @@ declare class DecimalColumn<Schema extends ColumnSchemaConfig> extends NumberAsS
1109
1109
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1110
1110
  toSQL(): string;
1111
1111
  }
1112
- type IdentityColumn<T extends Column.Pick.Data> = Column.Modifiers.Default<T, Expression>;
1113
1112
  declare class SmallIntColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
1114
1113
  dataType: "int2";
1115
1114
  querySchema: ReturnType<Schema['int']>;
1116
1115
  constructor(schema: Schema);
1117
1116
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1118
- identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): IdentityColumn<T>;
1117
+ identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.Modifiers.HasDefault<T>;
1119
1118
  }
1120
1119
  declare class IntegerColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
1121
1120
  dataType: "int4";
1122
1121
  querySchema: ReturnType<Schema['int']>;
1123
1122
  constructor(schema: Schema);
1124
1123
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1125
- identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): IdentityColumn<T>;
1124
+ identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.Modifiers.HasDefault<T>;
1126
1125
  }
1127
1126
  declare class BigIntColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema, string | number | bigint> {
1128
1127
  dataType: "int8";
1129
1128
  querySchema: ReturnType<Schema['stringSchema']>;
1130
1129
  constructor(schema: Schema);
1131
1130
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1132
- identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): IdentityColumn<T>;
1131
+ identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.Modifiers.HasDefault<T>;
1133
1132
  }
1134
1133
  declare class RealColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['number']>> {
1135
1134
  dataType: "float4";
@@ -1332,6 +1331,7 @@ declare class JSONTextColumn<T, Schema extends ColumnTypeSchemaArg, InputSchema
1332
1331
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1333
1332
  }
1334
1333
  interface DefaultSchemaConfig extends ColumnSchemaConfig<Column> {
1334
+ nullable<T extends Column.Pick.ForNullable>(this: T): Column.Modifiers.Nullable<T>;
1335
1335
  parse<T extends Column.Pick.ForParse, Output>(this: T, fn: (input: T['__type']) => Output): Column.Modifiers.Parse<T, unknown, Output>;
1336
1336
  parseNull<T extends Column.Pick.ForParseNull, Output>(this: T, fn: () => Output): Column.Modifiers.ParseNull<T, unknown, Output>;
1337
1337
  encode<T extends Column.Pick.Type, Input>(this: T, fn: (input: Input) => unknown): Column.Modifiers.Encode<T, unknown, Input>;
@@ -1730,7 +1730,7 @@ declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends Column {
1730
1730
  T & {
1731
1731
  data: {
1732
1732
  primaryKey: Name;
1733
- default: RawSqlBase;
1733
+ default: true;
1734
1734
  };
1735
1735
  };
1736
1736
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
@@ -1782,8 +1782,8 @@ declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends Column {
1782
1782
  toCode(ctx: ColumnToCodeCtx, key: string): Code;
1783
1783
  }
1784
1784
  interface Timestamps<T extends Column.Pick.Data> {
1785
- createdAt: Column.Modifiers.Default<T, RawSqlBase>;
1786
- updatedAt: Column.Modifiers.Default<T, RawSqlBase>;
1785
+ createdAt: Column.Modifiers.HasDefault<T>;
1786
+ updatedAt: Column.Modifiers.HasDefault<T>;
1787
1787
  }
1788
1788
  interface TimestampHelpers {
1789
1789
  /**
@@ -1866,7 +1866,7 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
1866
1866
  decimal: SchemaConfig['decimal'];
1867
1867
  real: SchemaConfig['real'];
1868
1868
  doublePrecision: SchemaConfig['doublePrecision'];
1869
- identity(options?: TableData.Identity): IdentityColumn<ReturnType<SchemaConfig['integer']>>;
1869
+ identity(options?: TableData.Identity): Column.Modifiers.HasDefault<ReturnType<SchemaConfig['integer']>>;
1870
1870
  smallSerial: SchemaConfig['smallSerial'];
1871
1871
  serial: SchemaConfig['serial'];
1872
1872
  bigSerial: SchemaConfig['bigSerial'];
@@ -2109,12 +2109,6 @@ interface JoinCallback<T extends PickQuerySelectableShapeRelationsWithDataAs, Ar
2109
2109
  (q: JoinQueryBuilder<T, JoinArgToQuery<T, Arg>>): IsQuery;
2110
2110
  }
2111
2111
  type JoinCallbackArgs<T extends PickQuerySelectableShapeRelationsWithDataAs, Arg extends JoinFirstArg<T>> = [cb?: JoinCallback<T, Arg> | true];
2112
- /**
2113
- * Type of {@link QueryJoin.join} query method.
2114
- */
2115
- interface JoinQueryMethod {
2116
- <T extends PickQuerySelectableResultRelationsWithDataReturnTypeShapeAs, Arg extends JoinFirstArg<T>, Cb extends JoinCallbackArgs<T, Arg>>(this: T, arg: Arg, ...args: Cb | JoinArgs<T, Arg>): JoinResultFromArgs<T, Arg, Cb, true, true>;
2117
- }
2118
2112
  declare class QueryJoin {
2119
2113
  /**
2120
2114
  * ## Select relation
@@ -2981,172 +2975,6 @@ interface AggregateOptions<T extends PickQuerySelectableResultRelationsWindows>
2981
2975
  over?: Over<T>;
2982
2976
  }
2983
2977
  type Over<T extends PickQuerySelectableResultWindows> = keyof T['windows'] | WindowArgDeclaration<T>;
2984
- interface ColumnsShape {
2985
- [K: string]: Column;
2986
- }
2987
- declare namespace ColumnsShape {
2988
- export type DefaultSelectKeys<S extends Column.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
2989
- export type DefaultOutput<Set extends Column.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
2990
- export type Input<Shape extends Column.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'] };
2991
- export type InputPartial<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
2992
- export type Output<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
2993
- export type DefaultSelectOutput<Shape extends Column.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
2994
- export interface MapToObjectColumn<Shape extends Column.QueryColumns> {
2995
- dataType: 'object';
2996
- __type: { [K in keyof Shape]: Shape[K]['__type'] };
2997
- __outputType: ShallowSimplify<ObjectOutput<Shape>>;
2998
- __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
2999
- operators: OperatorsAny;
3000
- }
3001
- export interface MapToNullableObjectColumn<Shape extends Column.QueryColumns> {
3002
- dataType: 'object';
3003
- __type: { [K in keyof Shape]: Shape[K]['__type'] };
3004
- __outputType: ShallowSimplify<ObjectOutput<Shape>> | undefined;
3005
- __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
3006
- operators: OperatorsAny;
3007
- }
3008
- export interface MapToPluckColumn<Shape extends Column.QueryColumns> {
3009
- dataType: 'array';
3010
- __type: Shape['pluck']['__type'][];
3011
- __outputType: Shape['pluck']['__outputType'][];
3012
- __queryType: Shape['pluck']['__queryType'][];
3013
- operators: OperatorsAny;
3014
- }
3015
- export interface MapToObjectArrayColumn<Shape extends Column.QueryColumns> {
3016
- dataType: 'array';
3017
- __type: { [K in keyof Shape]: Shape[K]['__type'] }[];
3018
- __outputType: ShallowSimplify<ObjectOutput<Shape>>[];
3019
- __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
3020
- operators: OperatorsAny;
3021
- }
3022
- type ObjectOutput<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
3023
- export {};
3024
- }
3025
- interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape, PickQueryRelations, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
3026
- type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
3027
- interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
3028
- withData: T['withData'];
3029
- }
3030
- type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject 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 };
3031
- interface SelectAsArg<T extends SelectSelf> {
3032
- [K: string]: keyof T['__selectable'] | Expression | ((q: SelectAsFnArg<T>) => unknown);
3033
- }
3034
- type SelectAsFnReturnType = {
3035
- result: Column.QueryColumns;
3036
- returnType: Exclude<QueryReturnType, 'rows'>;
3037
- } | Expression;
3038
- interface SelectAsCheckReturnTypes {
3039
- [K: string]: PropertyKey | Expression | ((q: never) => SelectAsFnReturnType);
3040
- }
3041
- type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
3042
- 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] };
3043
- 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}`;
3044
- 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,
3045
- { [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] };
3046
- interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
3047
- result: Column.QueryColumns;
3048
- returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
3049
- }
3050
- 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}`]: {
3051
- as: C;
3052
- column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
3053
- } } : never }[keyof Obj]>;
3054
- type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery | Expression) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression>> | Exclude<ReturnType<Arg>, IsQuery>['result']['value'] : never;
3055
- type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape.MapToNullableObjectColumn<Arg['result']> : ColumnsShape.MapToObjectColumn<Arg['result']>;
3056
- declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>>(q: T, columns: Columns): SelectResult<T, Columns>;
3057
- declare function _querySelect<T extends SelectSelf, Obj extends SelectAsArg<T>>(q: T, obj: Obj): SelectResultObj<T, Obj>;
3058
- declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(q: T, args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
3059
- declare class Select {
3060
- /**
3061
- * Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
3062
- *
3063
- * 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.
3064
- *
3065
- * ```ts
3066
- * import { sql } from './baseTable'
3067
- *
3068
- * // select columns of the table:
3069
- * db.table.select('id', 'name', { idAlias: 'id' });
3070
- *
3071
- * // accepts columns with table names:
3072
- * db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
3073
- *
3074
- * // table name may refer to the current table or a joined table:
3075
- * db.table
3076
- * .join(db.message, 'authorId', 'user.id')
3077
- * .select('user.name', 'message.text', { textAlias: 'message.text' });
3078
- *
3079
- * // select value from the sub-query,
3080
- * // this sub-query should return a single record and a single column:
3081
- * db.table.select({
3082
- * subQueryResult: Otherdb.table.select('column').take(),
3083
- * });
3084
- *
3085
- * // select raw SQL value, specify the returning type via <generic> syntax:
3086
- * db.table.select({
3087
- * raw: sql<number>`1 + 2`,
3088
- * });
3089
- *
3090
- * // select raw SQL value, the resulting type can be set by providing a column type in such way:
3091
- * db.table.select({
3092
- * raw: sql`1 + 2`.type((t) => t.integer()),
3093
- * });
3094
- *
3095
- * // same raw SQL query as above, but the sql is returned from a callback
3096
- * db.table.select({
3097
- * raw: () => sql`1 + 2`.type((t) => t.integer()),
3098
- * });
3099
- * ```
3100
- *
3101
- * When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
3102
- *
3103
- * ```ts
3104
- * await db.author.select({
3105
- * allBooks: (q) => q.books,
3106
- * firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
3107
- * booksCount: (q) => q.books.count(),
3108
- * });
3109
- * ```
3110
- *
3111
- * When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
3112
- *
3113
- * ```ts
3114
- * // select books with their authors included, order by author name and filter by author column:
3115
- * await db.books
3116
- * .select({
3117
- * author: (q) => q.author,
3118
- * })
3119
- * .order('author.name')
3120
- * .where({ 'author.isPopular': true });
3121
- * ```
3122
- */
3123
- select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
3124
- select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
3125
- select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
3126
- /**
3127
- * When querying the table or creating records, all columns are selected by default,
3128
- * but updating and deleting queries are returning affected row counts by default.
3129
- *
3130
- * Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
3131
- *
3132
- * ```ts
3133
- * const selectFull = await db.table
3134
- * .select('id', 'name') // discarded by `selectAll`
3135
- * .selectAll();
3136
- *
3137
- * const updatedFull = await db.table.selectAll().where(conditions).update(data);
3138
- *
3139
- * const deletedFull = await db.table.selectAll().where(conditions).delete();
3140
- * ```
3141
- */
3142
- selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
3143
- }
3144
- interface QueryGetSelf extends PickQuerySelectable, PickQueryRelationsWithData {}
3145
- type GetArg<T extends QueryGetSelf> = GetStringArg<T> | Expression | ((q: SelectAsFnArg<T>) => Expression | Query.Pick.SingleValueResult);
3146
- type GetStringArg<T extends PickQuerySelectable> = keyof T['__selectable'] & string;
3147
- type ResolveGetArgColumn<Arg> = Arg extends Expression ? Arg['result']['value'] : Arg extends ((q: never) => infer R) ? R extends Expression ? R['result']['value'] : R extends Query.Pick.SingleValueResult ? R['result']['value'] : never : never;
3148
- type GetResult<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOrThrow<T, Arg> : SetQueryReturnsColumnOrThrow<T, ResolveGetArgColumn<Arg>>;
3149
- type GetResultOptional<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOptional<T, Arg> : SetQueryReturnsColumnOptional<T, ResolveGetArgColumn<Arg>>;
3150
2978
  type HeadlineSearchArg<T extends PickQueryTsQuery> = Exclude<T['__tsQuery'], undefined>;
3151
2979
  interface HeadlineParams<T extends PickQuerySelectable> {
3152
2980
  text?: SelectableOrExpressionOfType<T, Column.Pick.QueryColumnOfType<string>>;
@@ -3483,16 +3311,6 @@ interface AggregateArgTypes {
3483
3311
  }
3484
3312
  interface AggregateMethods extends SearchAggregateMethods {}
3485
3313
  declare class AggregateMethods {
3486
- /**
3487
- * Use `exists()` to check if there is at least one record-matching condition.
3488
- *
3489
- * It will discard previous `select` statements if any. Returns a boolean.
3490
- *
3491
- * ```ts
3492
- * const exists: boolean = await db.table.where(...conditions).exists();
3493
- * ```
3494
- */
3495
- exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
3496
3314
  /**
3497
3315
  * Count records with the `count` function:
3498
3316
  *
@@ -5143,7 +4961,8 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
5143
4961
  */
5144
4962
  nestedCreateBatchMax: number;
5145
4963
  }
5146
- type ShapeColumnPrimaryKeys<Shape extends Column.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? K : never }[keyof Shape]]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']> };
4964
+ type ShapeHasPrimaryKeys<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? K : never }[keyof Shape];
4965
+ type TablePrimaryKeys<Shape extends Column.QueryColumnsInit> = ShapeHasPrimaryKeys<Shape> extends never ? never : { [K in ShapeHasPrimaryKeys<Shape>]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']> };
5147
4966
  type ShapeUniqueColumns<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? { [C in K]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']> } : never }[keyof Shape];
5148
4967
  type UniqueConstraints<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? string extends Shape[K]['data']['primaryKey'] ? never : Shape[K]['data']['primaryKey'] : Shape[K]['data']['unique'] extends string ? string extends Shape[K]['data']['unique'] ? never : Shape[K]['data']['unique'] : never }[keyof Shape];
5149
4968
  type NoPrimaryKeyOption = 'error' | 'warning' | 'ignore';
@@ -5219,6 +5038,10 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
5219
5038
  * Exclude a table-like definition from migration DDL generation.
5220
5039
  */
5221
5040
  generatorIgnore?: true | undefined;
5041
+ /**
5042
+ * Database relation name. The public `table` name remains a query alias.
5043
+ */
5044
+ nameInDb?: string;
5222
5045
  /**
5223
5046
  * Computed SQL or JS columns definitions
5224
5047
  */
@@ -5232,7 +5055,7 @@ type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.
5232
5055
  interface QueryBuilder extends Query.NotReadOnlyQuery {
5233
5056
  returnType: undefined;
5234
5057
  }
5235
- declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends Column.QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject, DefaultSelect extends keyof Shape = keyof Shape, ReadOnly extends true | undefined = undefined, Materialized extends true | undefined = undefined> extends QueryMethods<ColumnTypes> implements Query {
5058
+ declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem> = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ReadOnly extends true | undefined = undefined, Options = never> extends QueryMethods<ColumnTypes> implements Query {
5236
5059
  adapterNotInTransaction: Adapter;
5237
5060
  qb: QueryBuilder;
5238
5061
  table: Table;
@@ -5240,19 +5063,21 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
5240
5063
  q: QueryData;
5241
5064
  __isQuery: true;
5242
5065
  __as: Table & string;
5243
- __selectable: SelectableFromShape<ShapeWithComputed, Table>;
5066
+ __selectable: SelectableFromShape<ComputedColumnsFromOptions<Shape, Options>, Table>;
5244
5067
  __readOnly: ReadOnly;
5245
- __materialized: Materialized;
5068
+ __materialized: Options extends {
5069
+ materialized: true;
5070
+ } ? true : undefined;
5246
5071
  __hasSelect: boolean;
5247
5072
  __hasWhere: boolean;
5248
- __defaults: { [K in { [K in keyof Shape]: unknown extends Shape[K]['data']['default'] ? never : K }[keyof Shape]]: true };
5249
- __scopes: { [K in keyof Scopes]: true };
5250
- __defaultSelect: DefaultSelect;
5073
+ __defaults: { [K in { [K in keyof Shape]: Shape[K]['data']['default'] extends true ? K : never }[keyof Shape]]: true };
5074
+ __scopes: { [K in keyof MapTableScopesOption<Options>]: true };
5075
+ __defaultSelect: ColumnsShape.DefaultSelectKeys<Shape>;
5251
5076
  baseQuery: Query;
5252
5077
  columns: (keyof Shape)[];
5253
5078
  __outputType: ColumnsShape.DefaultSelectOutput<Shape>;
5254
5079
  __inputType: ColumnsShape.Input<Shape>;
5255
- result: { [K in DefaultSelect]: Shape[K] };
5080
+ result: { [K in ColumnsShape.DefaultSelectKeys<Shape>]: Shape[K] };
5256
5081
  returnType: undefined;
5257
5082
  then: QueryThenShallowSimplifyArr<ColumnsShape.DefaultOutput<Shape>>;
5258
5083
  windows: EmptyObject;
@@ -5262,10 +5087,10 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
5262
5087
  relationQueries: EmptyObject;
5263
5088
  withData: EmptyObject;
5264
5089
  error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
5265
- internal: QueryInternal<{ [K in keyof PrimaryKeys]: (keyof PrimaryKeys extends K ? never : keyof PrimaryKeys) extends never ? PrimaryKeys[K] : never }[keyof PrimaryKeys], PrimaryKeys | UniqueColumns, { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? K : never }[keyof Shape] | keyof PrimaryKeys, UniqueColumnTuples, UniqueConstraints>;
5090
+ internal: QueryInternal<TablePrimaryKeys<Shape> extends never ? never : { [K in keyof TablePrimaryKeys<Shape>]: (keyof TablePrimaryKeys<Shape> extends K ? never : keyof TablePrimaryKeys<Shape>) extends never ? TablePrimaryKeys<Shape>[K] : never }[keyof TablePrimaryKeys<Shape>], TablePrimaryKeys<Shape> | ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? K : never }[keyof Shape] | keyof TablePrimaryKeys<Shape>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>>;
5266
5091
  catch: QueryCatch;
5267
- shape: ShapeWithComputed;
5268
- constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ShapeWithComputed, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ShapeWithComputed>, tableData?: TableData, viewData?: QueryInternal['viewData']);
5092
+ shape: ComputedColumnsFromOptions<Shape, Options>;
5093
+ constructor(adapterNotInTransaction: Adapter, qb: QueryBuilder, table: Table | undefined, shape: ComputedColumnsFromOptions<Shape, Options>, columnTypes: ColumnTypes, asyncStorage: AsyncLocalStorage<AsyncState>, options: DbTableOptions<ColumnTypes, Table, ComputedColumnsFromOptions<Shape, Options>>, tableData?: TableData, viewData?: QueryInternal['viewData']);
5269
5094
  /**
5270
5095
  * When in transaction, returns a db adapter object for the transaction,
5271
5096
  * returns a default adapter object otherwise.
@@ -5334,7 +5159,9 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
5334
5159
  queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryResult<R>>;
5335
5160
  }
5336
5161
  interface DbTableConstructor<ColumnTypes> {
5337
- <Table extends string, Shape extends Column.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>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>, ColumnsShape.DefaultSelectKeys<Shape>, Options['readOnly'] extends true ? true : undefined, Options['materialized'] extends true ? true : undefined>;
5162
+ <Table extends string, Shape extends Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape> | undefined>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, Data, ColumnTypes, Options extends {
5163
+ readOnly: true;
5164
+ } ? true : undefined, Options>;
5338
5165
  }
5339
5166
  interface DbSqlMethod<ColumnTypes> {
5340
5167
  <T>(...args: StaticSQLArgs): RawSql<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
@@ -5352,7 +5179,7 @@ type MapTableScopesOption<T> = T extends {
5352
5179
  } ? {
5353
5180
  nonDeleted: unknown;
5354
5181
  } : EmptyObject;
5355
- interface DbResult<ColumnTypes> extends Db<undefined, EmptyObject, never, never, never, never, ColumnTypes, never, never>, DbTableConstructor<ColumnTypes> {
5182
+ interface DbResult<ColumnTypes> extends Db<undefined, EmptyObject, never, ColumnTypes, never, never>, DbTableConstructor<ColumnTypes> {
5356
5183
  adapterNotInTransaction: Adapter;
5357
5184
  adapter: Adapter;
5358
5185
  close: Adapter['close'];
@@ -6438,6 +6265,166 @@ declare class QueryTransaction {
6438
6265
  */
6439
6266
  recoverable<T>(this: T): T;
6440
6267
  }
6268
+ interface ColumnsShape {
6269
+ [K: string]: Column;
6270
+ }
6271
+ declare namespace ColumnsShape {
6272
+ export type DefaultSelectKeys<S extends Column.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
6273
+ export type DefaultOutput<Set extends Column.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
6274
+ export type Input<Shape extends Column.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'] };
6275
+ export type InputPartial<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
6276
+ export type Output<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
6277
+ export type DefaultSelectOutput<Shape extends Column.QueryColumnsInit> = { [K in { [K in keyof Shape]: Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof Shape]]: Shape[K]['__outputType'] };
6278
+ export interface MapToObjectColumn<Shape extends Column.QueryColumns> {
6279
+ dataType: 'object';
6280
+ __type: { [K in keyof Shape]: Shape[K]['__type'] };
6281
+ __outputType: ShallowSimplify<ObjectOutput<Shape>>;
6282
+ __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
6283
+ operators: OperatorsAny;
6284
+ }
6285
+ export interface MapToNullableObjectColumn<Shape extends Column.QueryColumns> {
6286
+ dataType: 'object';
6287
+ __type: { [K in keyof Shape]: Shape[K]['__type'] };
6288
+ __outputType: ShallowSimplify<ObjectOutput<Shape>> | undefined;
6289
+ __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
6290
+ operators: OperatorsAny;
6291
+ }
6292
+ export interface MapToPluckColumn<Shape extends Column.QueryColumns> {
6293
+ dataType: 'array';
6294
+ __type: Shape['pluck']['__type'][];
6295
+ __outputType: Shape['pluck']['__outputType'][];
6296
+ __queryType: Shape['pluck']['__queryType'][];
6297
+ operators: OperatorsAny;
6298
+ }
6299
+ export interface MapToObjectArrayColumn<Shape extends Column.QueryColumns> {
6300
+ dataType: 'array';
6301
+ __type: { [K in keyof Shape]: Shape[K]['__type'] }[];
6302
+ __outputType: ShallowSimplify<ObjectOutput<Shape>>[];
6303
+ __queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
6304
+ operators: OperatorsAny;
6305
+ }
6306
+ type ObjectOutput<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
6307
+ export {};
6308
+ }
6309
+ interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape, PickQueryRelations, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
6310
+ type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
6311
+ interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
6312
+ withData: T['withData'];
6313
+ }
6314
+ type SelectAsFnArg<T extends PickQueryRelationsWithData> = EmptyObject 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 };
6315
+ interface SelectAsArg<T extends SelectSelf> {
6316
+ [K: string]: keyof T['__selectable'] | Expression | ((q: SelectAsFnArg<T>) => unknown);
6317
+ }
6318
+ type SelectAsFnReturnType = {
6319
+ result: Column.QueryColumns;
6320
+ returnType: Exclude<QueryReturnType, 'rows'>;
6321
+ } | Expression;
6322
+ interface SelectAsCheckReturnTypes {
6323
+ [K: string]: PropertyKey | Expression | ((q: never) => SelectAsFnReturnType);
6324
+ }
6325
+ type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
6326
+ 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] };
6327
+ 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}`;
6328
+ 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,
6329
+ { [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] };
6330
+ interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
6331
+ result: Column.QueryColumns;
6332
+ returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
6333
+ }
6334
+ 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}`]: {
6335
+ as: C;
6336
+ column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
6337
+ } } : never }[keyof Obj]>;
6338
+ type SelectAsValueResult<T extends SelectSelf, Arg> = Arg extends keyof T['__selectable'] ? T['__selectable'][Arg]['column'] : Arg extends Expression ? Arg['result']['value'] : Arg extends ((q: never) => IsQuery) ? SelectSubQueryResult<ReturnType<Arg>> : Arg extends ((q: never) => Expression) ? ReturnType<Arg>['result']['value'] : Arg extends ((q: never) => IsQuery | Expression) ? SelectSubQueryResult<Exclude<ReturnType<Arg>, Expression>> | Exclude<ReturnType<Arg>, IsQuery>['result']['value'] : never;
6339
+ type SelectSubQueryResult<Arg extends SelectSelf> = Arg['returnType'] extends undefined | 'all' ? ColumnsShape.MapToObjectArrayColumn<Arg['result']> : Arg['returnType'] extends 'value' | 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? ColumnsShape.MapToPluckColumn<Arg['result']> : Arg['returnType'] extends 'one' ? ColumnsShape.MapToNullableObjectColumn<Arg['result']> : ColumnsShape.MapToObjectColumn<Arg['result']>;
6340
+ declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>>(q: T, columns: Columns): SelectResult<T, Columns>;
6341
+ declare function _querySelect<T extends SelectSelf, Obj extends SelectAsArg<T>>(q: T, obj: Obj): SelectResultObj<T, Obj>;
6342
+ declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(q: T, args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
6343
+ declare class Select {
6344
+ /**
6345
+ * Takes a list of columns to be selected, and by default, the query builder will select all columns of the table.
6346
+ *
6347
+ * 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.
6348
+ *
6349
+ * ```ts
6350
+ * import { sql } from './baseTable'
6351
+ *
6352
+ * // select columns of the table:
6353
+ * db.table.select('id', 'name', { idAlias: 'id' });
6354
+ *
6355
+ * // accepts columns with table names:
6356
+ * db.table.select('user.id', 'user.name', { nameAlias: 'user.name' });
6357
+ *
6358
+ * // table name may refer to the current table or a joined table:
6359
+ * db.table
6360
+ * .join(db.message, 'authorId', 'user.id')
6361
+ * .select('user.name', 'message.text', { textAlias: 'message.text' });
6362
+ *
6363
+ * // select value from the sub-query,
6364
+ * // this sub-query should return a single record and a single column:
6365
+ * db.table.select({
6366
+ * subQueryResult: Otherdb.table.select('column').take(),
6367
+ * });
6368
+ *
6369
+ * // select raw SQL value, specify the returning type via <generic> syntax:
6370
+ * db.table.select({
6371
+ * raw: sql<number>`1 + 2`,
6372
+ * });
6373
+ *
6374
+ * // select raw SQL value, the resulting type can be set by providing a column type in such way:
6375
+ * db.table.select({
6376
+ * raw: sql`1 + 2`.type((t) => t.integer()),
6377
+ * });
6378
+ *
6379
+ * // same raw SQL query as above, but the sql is returned from a callback
6380
+ * db.table.select({
6381
+ * raw: () => sql`1 + 2`.type((t) => t.integer()),
6382
+ * });
6383
+ * ```
6384
+ *
6385
+ * When you use the ORM and defined relations, `select` can also accept callbacks with related table queries:
6386
+ *
6387
+ * ```ts
6388
+ * await db.author.select({
6389
+ * allBooks: (q) => q.books,
6390
+ * firstBook: (q) => q.books.order({ createdAt: 'ASC' }).take(),
6391
+ * booksCount: (q) => q.books.count(),
6392
+ * });
6393
+ * ```
6394
+ *
6395
+ * When you're selecting a relation that's connected via `belongsTo` or `hasOne`, it becomes available to use in `order` or in `where`:
6396
+ *
6397
+ * ```ts
6398
+ * // select books with their authors included, order by author name and filter by author column:
6399
+ * await db.books
6400
+ * .select({
6401
+ * author: (q) => q.author,
6402
+ * })
6403
+ * .order('author.name')
6404
+ * .where({ 'author.isPopular': true });
6405
+ * ```
6406
+ */
6407
+ select<T extends SelectSelf, Columns extends SelectArgs<T>>(this: T, ...args: Columns): SelectResult<T, Columns>;
6408
+ select<T extends SelectSelf, Obj extends SelectAsArg<T>>(this: T, obj: Obj): SelectResultObj<T, Obj>;
6409
+ select<T extends SelectSelf, Columns extends SelectArgs<T>, Obj extends SelectAsArg<T>>(this: T, ...args: [...columns: Columns, obj: Obj]): SelectResultColumnsAndObj<T, Columns, Obj>;
6410
+ /**
6411
+ * When querying the table or creating records, all columns are selected by default,
6412
+ * but updating and deleting queries are returning affected row counts by default.
6413
+ *
6414
+ * Use `selectAll` to select all columns. If the `.select` method was applied before it will be discarded.
6415
+ *
6416
+ * ```ts
6417
+ * const selectFull = await db.table
6418
+ * .select('id', 'name') // discarded by `selectAll`
6419
+ * .selectAll();
6420
+ *
6421
+ * const updatedFull = await db.table.selectAll().where(conditions).update(data);
6422
+ *
6423
+ * const deletedFull = await db.table.selectAll().where(conditions).delete();
6424
+ * ```
6425
+ */
6426
+ selectAll<T extends SelectSelf>(this: T): SelectResult<T, ['*']>;
6427
+ }
6441
6428
  type SelectItem = string | SelectAs | Expression | undefined;
6442
6429
  interface SelectAs {
6443
6430
  selectAs: SelectAsValue;
@@ -6620,7 +6607,8 @@ declare namespace Column {
6620
6607
  unique: Name;
6621
6608
  };
6622
6609
  };
6623
- export type Nullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema> = { [K in keyof T]: K extends '__type' ? T['__type'] | null : K extends '__inputType' ? T['__inputType'] | null : K extends 'inputSchema' ? InputSchema : K extends '__outputType' ? T['__outputType'] | (unknown extends T['__nullType'] ? null : T['__nullType']) : K extends 'outputSchema' ? OutputSchema : K extends '__queryType' ? T['__queryType'] | null : K extends 'querySchema' ? QuerySchema : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? { [K in keyof T['operators']]: K extends 'equals' | 'not' | 'isDistinctFrom' | 'isNotDistinctFrom' ? Operator<T['__queryType'] | null, T> : T['operators'][K] } : T[K] };
6610
+ export type Nullable<T extends Column.Pick.ForNullable> = { [K in keyof T]: K extends '__type' ? T['__type'] | null : K extends '__inputType' ? T['__inputType'] | null : K extends '__outputType' ? T['__outputType'] | (unknown extends T['__nullType'] ? null : T['__nullType']) : K extends '__queryType' ? T['__queryType'] | null : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? { [K in keyof T['operators']]: K extends 'equals' | 'not' | 'isDistinctFrom' | 'isNotDistinctFrom' ? Operator<T['__queryType'] | null, T> : T['operators'][K] } : T[K] };
6611
+ export type NullableWithSchema<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema> = { [K in keyof T]: K extends '__type' ? T['__type'] | null : K extends '__inputType' ? T['__inputType'] | null : K extends 'inputSchema' ? InputSchema : K extends '__outputType' ? T['__outputType'] | (unknown extends T['__nullType'] ? null : T['__nullType']) : K extends 'outputSchema' ? OutputSchema : K extends '__queryType' ? T['__queryType'] | null : K extends 'querySchema' ? QuerySchema : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? { [K in keyof T['operators']]: K extends 'equals' | 'not' | 'isDistinctFrom' | 'isNotDistinctFrom' ? Operator<T['__queryType'] | null, T> : T['operators'][K] } : T[K] };
6624
6612
  export type QueryColumnToNullable<C> = { [K in keyof C]: K extends '__outputType' | '__queryType' ? C[K] | null : C[K] };
6625
6613
  export type QueryColumnToOptional<C> = { [K in keyof C]: K extends '__outputType' ? C[K] | undefined : C[K] };
6626
6614
  interface DataNullable {
@@ -6636,8 +6624,7 @@ declare namespace Column {
6636
6624
  export type Encode<T, InputSchema, Input> = { [K in keyof T]: K extends '__inputType' ? Input : K extends 'inputSchema' ? InputSchema : T[K] };
6637
6625
  export type Parse<T extends Pick.ForParse, OutputSchema, Output> = { [K in keyof T]: K extends '__outputType' ? null extends T['__type'] ? (Output extends null ? never : Output) | (unknown extends T['__nullType'] ? null : T['__nullType']) : Output : K extends 'outputSchema' ? null extends T['__type'] ? OutputSchema | T['nullSchema'] : OutputSchema : T[K] };
6638
6626
  export type ParseNull<T extends Column.Pick.ForParseNull, NullSchema, NullType> = { [K in keyof T]: K extends '__outputType' ? null extends T['__type'] ? Exclude<T['__outputType'], null> | NullType : T['__outputType'] : K extends '__nullType' ? NullType : K extends 'outputSchema' ? null extends T['__type'] ? T['outputSchema'] | NullSchema : T['outputSchema'] : K extends 'nullSchema' ? NullSchema : T[K] };
6639
- type DefaultData<T extends Column.Data, Value> = { [K in keyof T]: K extends 'default' ? Value extends null ? never : Value : K extends 'optional' ? true : T[K] };
6640
- export type Default<T extends Column.Pick.Data, Value> = { [K in keyof T]: K extends 'data' ? DefaultData<T['data'], Value> : T[K] };
6627
+ export type HasDefault<T extends Column.Pick.Data> = T & Column.Data.Default;
6641
6628
  type DefaultSelectData<T extends Column.Data, Value> = { [K in keyof T]: K extends 'explicitSelect' ? Value extends true ? false : true : T[K] };
6642
6629
  export type DefaultSelect<T extends Column.Pick.Data, Value extends boolean> = { [K in keyof T]: K extends 'data' ? DefaultSelectData<T['data'], Value> : T[K] };
6643
6630
  export interface IsAppReadOnly {
@@ -6737,6 +6724,7 @@ declare namespace Column {
6737
6724
  interface TableParamInstance {
6738
6725
  schema?: string;
6739
6726
  table: string;
6727
+ nameInDb?: string;
6740
6728
  columns: PickQueryShape;
6741
6729
  }
6742
6730
  interface TableParam {
@@ -6828,6 +6816,12 @@ declare namespace Column {
6828
6816
  skipValueToArray?: boolean;
6829
6817
  }
6830
6818
  export namespace Data {
6819
+ interface Default {
6820
+ data: {
6821
+ default: true;
6822
+ optional: true;
6823
+ };
6824
+ }
6831
6825
  interface Check {
6832
6826
  sql: RawSqlBase;
6833
6827
  name?: string;
@@ -6854,7 +6848,7 @@ declare namespace Column {
6854
6848
  export type AsTypeArg<Schema> = AsTypeArgWithType<Schema> | AsTypeArgWithoutType<Schema>;
6855
6849
  export {};
6856
6850
  }
6857
- declare function makeColumnNullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema>(column: T, inputSchema: InputSchema, outputSchema: OutputSchema, querySchema: QuerySchema): Column.Modifiers.Nullable<T, InputSchema, OutputSchema, QuerySchema>;
6851
+ declare function makeColumnNullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema>(column: T, inputSchema: InputSchema, outputSchema: OutputSchema, querySchema: QuerySchema): Column.Modifiers.NullableWithSchema<T, InputSchema, OutputSchema, QuerySchema>;
6858
6852
  declare const setColumnData: <T extends Column.Pick.Data, K extends keyof T["data"]>(q: T, key: K, value: T["data"][K]) => T;
6859
6853
  declare const setDataValue: <T extends Column.Pick.Data, Key extends string, Value>(item: T, key: Key, value: Value, params?: Column.Error.StringOrMessage) => T;
6860
6854
  declare function setCurrentColumnName(name: string): void;
@@ -6904,13 +6898,13 @@ declare abstract class Column {
6904
6898
  *
6905
6899
  * @param value - default value or a function returning a value
6906
6900
  */
6907
- default<T extends Column.Pick.DataAndInputType, Value extends T['__inputType'] | null | RawSqlBase | (() => T['__inputType'])>(this: T, value: Value): Column.Modifiers.Default<T, Value>;
6901
+ default<T extends Column.Pick.DataAndInputType, Value extends T['__inputType'] | null | RawSqlBase | (() => T['__inputType'])>(this: T, value: Value): Column.Modifiers.HasDefault<T>;
6908
6902
  /**
6909
6903
  * Use `hasDefault` to let the column be omitted when creating records.
6910
6904
  *
6911
6905
  * It's better to use {@link default} instead so the value is explicit and serves as a hint.
6912
6906
  */
6913
- hasDefault<T extends Column.Pick.Data>(this: T): Column.Modifiers.Default<T, RawSqlBase>;
6907
+ hasDefault<T extends Column.Pick.Data>(this: T): Column.Modifiers.HasDefault<T>;
6914
6908
  /**
6915
6909
  * Set a database-level validation check to a column. `check` accepts a raw SQL.
6916
6910
  *
@@ -8749,11 +8743,13 @@ declare const getColumnBaseType: (column: Column.Pick.Data, domainsMap: DbStruct
8749
8743
  interface ColumnDataComputedProp extends ColumnDataSelectSqlProp {
8750
8744
  computed?: Expression;
8751
8745
  }
8752
- type ComputedColumnsFromOptions<T extends ComputedOptionsFactory<never, never> | undefined> = T extends ((...args: any[]) => infer R extends ComputedOptionsConfig) ? { [K in keyof R]: R[K] extends QueryOrExpression<unknown> ? R[K]['result']['value'] : R[K] extends (() => {
8746
+ type ComputedColumnsFromOptions<Shape, Options> = Options extends {
8747
+ computed: (...args: any) => infer R;
8748
+ } ? { [K in (keyof Shape | keyof R) & string]: K extends keyof Shape ? Shape[K] : K extends keyof R ? R[K] extends QueryOrExpression<unknown> ? R[K]['result']['value'] : R[K] extends (() => {
8753
8749
  result: {
8754
8750
  value: infer Value extends Column.Pick.QueryColumn;
8755
8751
  };
8756
- }) ? Value : never } : EmptyObject;
8752
+ }) ? Value : never : never } : Shape;
8757
8753
  interface ComputedOptionsConfig {
8758
8754
  [K: string]: QueryOrExpression<unknown> | ReturnsQueryOrExpression<unknown>;
8759
8755
  }
@@ -8975,6 +8971,7 @@ interface QueryData extends QueryDataAliases, PickQueryDataParsers, HasHookSelec
8975
8971
  type: QueryType;
8976
8972
  adapter: Adapter;
8977
8973
  selectShape: ColumnsShape;
8974
+ nameInDb?: string;
8978
8975
  handleResult: HandleResult;
8979
8976
  catch?: boolean;
8980
8977
  returnType: QueryReturnType;
@@ -9837,6 +9834,12 @@ declare class QueryUpsert {
9837
9834
  */
9838
9835
  upsert<T extends UpsertThis, Update extends UpdateData<T>>(this: T, data: UpsertData<T, Update>): UpsertResult<T>;
9839
9836
  }
9837
+ interface QueryGetSelf extends PickQuerySelectable, PickQueryRelationsWithData {}
9838
+ type GetArg<T extends QueryGetSelf> = GetStringArg<T> | Expression | ((q: SelectAsFnArg<T>) => Expression | Query.Pick.SingleValueResult);
9839
+ type GetStringArg<T extends PickQuerySelectable> = keyof T['__selectable'] & string;
9840
+ type ResolveGetArgColumn<Arg> = Arg extends Expression ? Arg['result']['value'] : Arg extends ((q: never) => infer R) ? R extends Expression ? R['result']['value'] : R extends Query.Pick.SingleValueResult ? R['result']['value'] : never : never;
9841
+ type GetResult<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOrThrow<T, Arg> : SetQueryReturnsColumnOrThrow<T, ResolveGetArgColumn<Arg>>;
9842
+ type GetResultOptional<T extends QueryGetSelf, Arg extends GetArg<T>> = Arg extends string ? SetQueryReturnsValueOptional<T, Arg> : SetQueryReturnsColumnOptional<T, ResolveGetArgColumn<Arg>>;
9840
9843
  declare class QueryGet {
9841
9844
  /**
9842
9845
  * `.get` returns a single value, adds `LIMIT 1` to the query, and accepts a column name or a raw SQL expression.
@@ -10118,6 +10121,28 @@ declare class QueryTruncate {
10118
10121
  cascade?: boolean;
10119
10122
  }): SetQueryReturnsVoid<T>;
10120
10123
  }
10124
+ declare class QueryExistsMethods {
10125
+ /**
10126
+ * Use `exists()` to check if there is at least one record-matching condition.
10127
+ *
10128
+ * It will discard previous `select` statements if any. Returns a boolean.
10129
+ *
10130
+ * ```ts
10131
+ * const exists: boolean = await db.table.where(...conditions).exists();
10132
+ * ```
10133
+ */
10134
+ exists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
10135
+ /**
10136
+ * Use `notExists()` to check if there are no matching records.
10137
+ *
10138
+ * It will discard previous `select` statements if any. Returns a boolean.
10139
+ *
10140
+ * ```ts
10141
+ * const exists: boolean = await db.table.where(...conditions).notExists();
10142
+ * ```
10143
+ */
10144
+ notExists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
10145
+ }
10121
10146
  type GroupArgs<T extends PickQueryResult> = ({ [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K }[keyof T['result']] | Expression)[];
10122
10147
  interface QueryHelperQuery<T extends PickQuerySelectableShapeAs> extends MergeQueryArg {
10123
10148
  returnType: QueryReturnType;
@@ -10156,7 +10181,7 @@ interface NarrowPluckTypeResult<T extends PickQueryResultReturnType, Narrow> ext
10156
10181
  }
10157
10182
  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.Modifiers.QueryColumnToOptional<R['result'][K]> } : K extends 'then' ? QueryIfResultThen<T, R> : T[K] };
10158
10183
  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>;
10159
- 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, QueryUpsert, QueryOrCreate, QueryGet, QueryPluck, MergeQueryMethods, QuerySql<ColumnTypes>, QueryTransform, QueryMap, QueryScope, SoftDeleteMethods, QueryExpressions, QueryWrap, QueryWindow {}
10184
+ 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, QueryUpsert, QueryOrCreate, QueryGet, QueryPluck, MergeQueryMethods, QuerySql<ColumnTypes>, QueryTransform, QueryMap, QueryScope, SoftDeleteMethods, QueryExpressions, QueryWrap, QueryWindow, QueryExistsMethods {}
10160
10185
  declare class QueryMethods<ColumnTypes> {
10161
10186
  /**
10162
10187
  * `.all` is a default behavior, that returns an array of objects:
@@ -10219,6 +10244,15 @@ declare class QueryMethods<ColumnTypes> {
10219
10244
  * ```
10220
10245
  */
10221
10246
  exec<T>(this: T): SetQueryReturnsVoid<T>;
10247
+ /**
10248
+ * For relation selects, `require` changes LEFT JOIN LATERAL to JOIN LATERAL.
10249
+ *
10250
+ * ```ts
10251
+ * // only the records that have `related` will be loaded:
10252
+ * await db.table.select({ related: (q) => q.related.required() });
10253
+ * ```
10254
+ */
10255
+ require<T extends PickQueryResultReturnType>(this: T): QueryRequire<T>;
10222
10256
  /**
10223
10257
  * Call `toSQL` on a query to get an object with a `text` SQL string and a `values` array of binding values:
10224
10258
  *
@@ -10407,7 +10441,7 @@ declare class QueryMethods<ColumnTypes> {
10407
10441
  * // all the following queries will resolve into empty arrays
10408
10442
  *
10409
10443
  * await db.user.select({
10410
- * pets: (q) => q.pets.join().none(),
10444
+ * pets: (q) => q.pets.require().none(),
10411
10445
  * });
10412
10446
  *
10413
10447
  * await db.user.join((q) => q.pets.none());
@@ -10479,7 +10513,7 @@ declare class QueryMethods<ColumnTypes> {
10479
10513
  *
10480
10514
  * @param fn - helper function
10481
10515
  */
10482
- makeHelper<T extends PickQuerySelectableShapeAs, Args extends unknown[], Result extends MergeQueryArg>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
10516
+ makeHelper<T extends PickQuerySelectableShapeAs, Args extends unknown[], Result extends MergeQueryArg | Expression>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
10483
10517
  /**
10484
10518
  * `useHelper` allows to use {@link makeHelper} in different queries:
10485
10519
  *
@@ -10688,6 +10722,9 @@ declare namespace Query {
10688
10722
  type Args<T extends Order.ArgThis> = Order.Args<T>;
10689
10723
  }
10690
10724
  namespace Pick {
10725
+ interface ReturnType {
10726
+ returnType: QueryReturnType;
10727
+ }
10691
10728
  interface SingleValueResult {
10692
10729
  result: {
10693
10730
  value: Column.Pick.OutputType;
@@ -10708,6 +10745,7 @@ type SetQueryReturnsAll<T extends PickQueryResult> = { [K in keyof T]: K extends
10708
10745
  type SetQueryReturnsAllResult<T extends PickQueryResult, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'result' ? Result : K extends 'then' ? QueryThenShallowSimplifyArr<T['result']> : T[K] } & QueryHasWhere;
10709
10746
  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.Output<T['result']>> : T[K] };
10710
10747
  type QueryManyTakeOptional<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnsShape.Output<T['result']>> : T[K] };
10748
+ 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.Output<T['result']>> : T[K] };
10711
10749
  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.Output<T['result']>> : T[K] };
10712
10750
  type QueryManyTake<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K] };
10713
10751
  type SetQueryReturnsOne<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K] };
@@ -11113,4 +11151,4 @@ declare const testTransaction: {
11113
11151
  */
11114
11152
  close(arg: Arg$1): Promise<void>;
11115
11153
  };
11116
- 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, 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, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, 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, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, type OperatorsText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, 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 RefreshMaterializedViewOptions, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, 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, TextBaseColumn, 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 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, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, 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, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
11154
+ 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, 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, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, 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, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, type OperatorsText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, 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 RefreshMaterializedViewOptions, 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, TextBaseColumn, 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 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, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, 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, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };