pqb 0.71.4 → 0.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bun.d.ts +1 -4
- package/dist/bun.js.map +1 -1
- package/dist/bun.mjs.map +1 -1
- package/dist/index.d.ts +546 -594
- package/dist/index.js +267 -212
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +262 -212
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +6576 -6631
- package/dist/internal.js +6158 -0
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +6136 -7
- package/dist/internal.mjs.map +1 -1
- package/dist/node-postgres.d.ts +1 -4
- package/dist/node-postgres.js +1 -1
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.js +1 -1
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface RecordOptionalString {
|
|
|
21
21
|
interface RecordUnknown {
|
|
22
22
|
[K: string]: unknown;
|
|
23
23
|
}
|
|
24
|
-
type ShallowSimplify<T> = T extends any ? { [K in keyof T]: T[K] } : T;
|
|
24
|
+
type ShallowSimplify<T> = T extends any ? { [K in keyof T]: T[K]; } : T;
|
|
25
25
|
/**
|
|
26
26
|
* Merge methods from multiple class into another class.
|
|
27
27
|
* @param derivedCtor - target class to merge methods into
|
|
@@ -241,7 +241,7 @@ declare abstract class QueryError<T extends PickQueryShape = PickQueryShape> ext
|
|
|
241
241
|
line: string | undefined;
|
|
242
242
|
routine: string | undefined;
|
|
243
243
|
get isUnique(): boolean;
|
|
244
|
-
get columns(): { [K in keyof T["shape"]]?: true | undefined };
|
|
244
|
+
get columns(): { [K in keyof T["shape"]]?: true | undefined; };
|
|
245
245
|
}
|
|
246
246
|
interface QueryLogObject {
|
|
247
247
|
colors: boolean;
|
|
@@ -265,7 +265,7 @@ declare const logColors: {
|
|
|
265
265
|
boldMagenta: (message: string) => string;
|
|
266
266
|
boldRed: (message: string) => string;
|
|
267
267
|
};
|
|
268
|
-
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions[
|
|
268
|
+
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions['log']) => QueryLogObject | undefined;
|
|
269
269
|
declare class QueryLog {
|
|
270
270
|
/**
|
|
271
271
|
* Override the `log` option, which can also be set in `createDb` or when creating a table instance:
|
|
@@ -909,7 +909,7 @@ interface TableDataMethods<Key extends PropertyKey> {
|
|
|
909
909
|
};
|
|
910
910
|
unique<Columns extends [Key | TableData.Index.ColumnOrExpressionOptions<Key>, ...(Key | TableData.Index.ColumnOrExpressionOptions<Key>)[]], Name extends string>(columns: Columns, options?: TableData.Index.UniqueOptionsArg<Name>): {
|
|
911
911
|
tableDataItem: true;
|
|
912
|
-
columns: Columns extends (Key | TableData.Index.ColumnOptionsForColumn<Key>)[] ? { [I in keyof Columns]: 'column' extends keyof Columns[I] ? Columns[I]['column'] : Columns[I] } : never;
|
|
912
|
+
columns: Columns extends (Key | TableData.Index.ColumnOptionsForColumn<Key>)[] ? { [I in keyof Columns]: 'column' extends keyof Columns[I] ? Columns[I]['column'] : Columns[I]; } : never;
|
|
913
913
|
name: string extends Name ? never : Name;
|
|
914
914
|
};
|
|
915
915
|
index(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], options?: TableData.Index.OptionsArg): NonUniqDataItem;
|
|
@@ -984,17 +984,22 @@ interface TableDataMethods<Key extends PropertyKey> {
|
|
|
984
984
|
* ```
|
|
985
985
|
*/
|
|
986
986
|
exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<Key>[], options?: TableData.Exclude.Options): NonUniqDataItem;
|
|
987
|
-
foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () =>
|
|
988
|
-
columns
|
|
987
|
+
foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () => Column.ForeignKey.TableParam & {
|
|
988
|
+
columns?: {
|
|
989
989
|
shape: Shape;
|
|
990
990
|
};
|
|
991
|
+
instance?: () => {
|
|
992
|
+
columns: {
|
|
993
|
+
shape: Shape;
|
|
994
|
+
};
|
|
995
|
+
};
|
|
991
996
|
}, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options): NonUniqDataItem;
|
|
992
997
|
foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): NonUniqDataItem;
|
|
993
998
|
check(check: RawSqlBase, name?: string): NonUniqDataItem;
|
|
994
999
|
sql: SqlFn;
|
|
995
1000
|
}
|
|
996
|
-
type TableDataItemsUniqueColumns<Shape extends Column.QueryColumns, T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem<Shape> ? ItemUniqueColumns<Shape, T> : T extends unknown[] ? { [Item in T[number] as PropertyKey]: Item extends UniqueTableDataItem<Shape> ? ItemUniqueColumns<Shape, Item> : never }[PropertyKey] : never;
|
|
997
|
-
type ItemUniqueColumns<Shape extends Column.QueryColumns, T extends UniqueTableDataItem<Shape>> = { [Column in T['columns'][number]]: UniqueQueryTypeOrExpression<Shape[Column]['__queryType']
|
|
1001
|
+
type TableDataItemsUniqueColumns<Shape extends Column.QueryColumns, T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem<Shape> ? ItemUniqueColumns<Shape, T> : T extends unknown[] ? { [Item in T[number] as PropertyKey]: Item extends UniqueTableDataItem<Shape> ? ItemUniqueColumns<Shape, Item> : never; }[PropertyKey] : never;
|
|
1002
|
+
type ItemUniqueColumns<Shape extends Column.QueryColumns, T extends UniqueTableDataItem<Shape>> = { [Column in T['columns'][number]]: UniqueQueryTypeOrExpression<Shape[Column]['__queryType']>; };
|
|
998
1003
|
type TableDataItemsUniqueColumnTuples<Shape extends Column.QueryColumns, T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem<Shape> ? T['columns'] : T extends TableDataItem[] ? Exclude<T[number]['columns'], []> : never;
|
|
999
1004
|
type UniqueQueryTypeOrExpression<T> = T | Expression<Column.Pick.QueryColumnOfType<T>>;
|
|
1000
1005
|
type TableDataItemsUniqueConstraints<T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem ? T['name'] : T extends UniqueTableDataItem[] ? T[number]['name'] : never;
|
|
@@ -1059,6 +1064,8 @@ interface ColumnToCodeCtx {
|
|
|
1059
1064
|
currentSchema: string;
|
|
1060
1065
|
migration?: boolean;
|
|
1061
1066
|
snakeCase?: boolean;
|
|
1067
|
+
sql?: string;
|
|
1068
|
+
isSqlUsed?: boolean;
|
|
1062
1069
|
}
|
|
1063
1070
|
/**
|
|
1064
1071
|
* Push code: this will append a code string to the last code array element when possible.
|
|
@@ -1078,14 +1085,12 @@ declare const columnsShapeToCode: (ctx: ColumnToCodeCtx, shape: Column.Shape.Que
|
|
|
1078
1085
|
declare const pushTableDataCode: (code: Codes, ast: TableData) => Codes;
|
|
1079
1086
|
declare const primaryKeyInnerToCode: (primaryKey: TableData.PrimaryKey, t: string) => string;
|
|
1080
1087
|
declare const indexInnerToCode: (index: TableData.Index, t: string) => Codes;
|
|
1088
|
+
declare const indexToCode: (item: TableData.Index, t: string, prefix?: string) => Codes;
|
|
1081
1089
|
declare const excludeInnerToCode: (item: TableData.Exclude, t: string) => Codes;
|
|
1082
|
-
declare const
|
|
1083
|
-
declare const
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
foreignColumns,
|
|
1087
|
-
options
|
|
1088
|
-
}: Exclude<TableData.Constraint["references"], undefined>, name?: string | false, m?: boolean) => Codes;
|
|
1090
|
+
declare const excludeToCode: (item: TableData.Exclude, t: string, prefix?: string) => Codes;
|
|
1091
|
+
declare const constraintToCode: (item: TableData.Constraint, t: string, m?: boolean, prefix?: string, ctx?: ColumnToCodeCtx) => Codes;
|
|
1092
|
+
declare const constraintInnerToCode: (item: TableData.Constraint, t: string, m?: boolean, ctx?: ColumnToCodeCtx) => Codes;
|
|
1093
|
+
declare const referencesArgsToCode: ({ columns, fnOrTable, foreignColumns, options }: Exclude<TableData.Constraint['references'], undefined>, name?: string | false, m?: boolean) => Codes;
|
|
1089
1094
|
interface NumberColumnData extends BaseNumberData, Column.Data {
|
|
1090
1095
|
identity?: TableData.Identity;
|
|
1091
1096
|
}
|
|
@@ -1130,46 +1135,46 @@ declare class DecimalColumn<Schema extends ColumnSchemaConfig> extends NumberAsS
|
|
|
1130
1135
|
data: DecimalColumnData;
|
|
1131
1136
|
querySchema: ReturnType<Schema['stringSchema']>;
|
|
1132
1137
|
operators: OperatorsNumber;
|
|
1133
|
-
dataType:
|
|
1138
|
+
dataType: 'numeric';
|
|
1134
1139
|
constructor(schema: Schema, numericPrecision?: number, numericScale?: number);
|
|
1135
1140
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1136
1141
|
toSQL(): string;
|
|
1137
1142
|
}
|
|
1138
1143
|
declare class SmallIntColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
1139
|
-
dataType:
|
|
1144
|
+
dataType: 'int2';
|
|
1140
1145
|
querySchema: ReturnType<Schema['int']>;
|
|
1141
1146
|
constructor(schema: Schema);
|
|
1142
1147
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1143
|
-
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.
|
|
1148
|
+
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.HasDefault<T>;
|
|
1144
1149
|
}
|
|
1145
1150
|
declare class IntegerColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
1146
|
-
dataType:
|
|
1151
|
+
dataType: 'int4';
|
|
1147
1152
|
querySchema: ReturnType<Schema['int']>;
|
|
1148
1153
|
constructor(schema: Schema);
|
|
1149
1154
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1150
|
-
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.
|
|
1155
|
+
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.HasDefault<T>;
|
|
1151
1156
|
}
|
|
1152
1157
|
declare class BigIntColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema, string | number | bigint> {
|
|
1153
|
-
dataType:
|
|
1158
|
+
dataType: 'int8';
|
|
1154
1159
|
querySchema: ReturnType<Schema['stringSchema']>;
|
|
1155
1160
|
constructor(schema: Schema);
|
|
1156
1161
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1157
|
-
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.
|
|
1162
|
+
identity<T extends Column.Pick.Data>(this: T, options?: TableData.Identity): Column.HasDefault<T>;
|
|
1158
1163
|
}
|
|
1159
1164
|
declare class RealColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['number']>> {
|
|
1160
|
-
dataType:
|
|
1165
|
+
dataType: 'float4';
|
|
1161
1166
|
querySchema: ReturnType<Schema['number']>;
|
|
1162
1167
|
constructor(schema: Schema);
|
|
1163
1168
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1164
1169
|
}
|
|
1165
1170
|
declare class DoublePrecisionColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
|
|
1166
|
-
dataType:
|
|
1171
|
+
dataType: 'float8';
|
|
1167
1172
|
querySchema: ReturnType<Schema['stringSchema']>;
|
|
1168
1173
|
constructor(schema: Schema);
|
|
1169
1174
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1170
1175
|
}
|
|
1171
1176
|
declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
1172
|
-
dataType:
|
|
1177
|
+
dataType: 'int2';
|
|
1173
1178
|
data: SerialColumnData;
|
|
1174
1179
|
querySchema: ReturnType<Schema['int']>;
|
|
1175
1180
|
constructor(schema: Schema);
|
|
@@ -1177,7 +1182,7 @@ declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends Integ
|
|
|
1177
1182
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1178
1183
|
}
|
|
1179
1184
|
declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
1180
|
-
dataType:
|
|
1185
|
+
dataType: 'int4';
|
|
1181
1186
|
data: SerialColumnData;
|
|
1182
1187
|
querySchema: ReturnType<Schema['int']>;
|
|
1183
1188
|
constructor(schema: Schema);
|
|
@@ -1185,7 +1190,7 @@ declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBas
|
|
|
1185
1190
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1186
1191
|
}
|
|
1187
1192
|
declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
|
|
1188
|
-
dataType:
|
|
1193
|
+
dataType: 'int8';
|
|
1189
1194
|
data: SerialColumnData;
|
|
1190
1195
|
querySchema: ReturnType<Schema['stringSchema']>;
|
|
1191
1196
|
constructor(schema: Schema);
|
|
@@ -1193,14 +1198,16 @@ declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberA
|
|
|
1193
1198
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1194
1199
|
}
|
|
1195
1200
|
type DateColumnInput = string | number | Date;
|
|
1201
|
+
declare const parseStringOrDateToNumber: (value: unknown) => number;
|
|
1196
1202
|
declare const getDateAsNumberFn: (column: {
|
|
1197
1203
|
data: Column.Data;
|
|
1198
1204
|
dateParsedByDriver?: boolean;
|
|
1199
|
-
}) =>
|
|
1205
|
+
}) => typeof parseStringOrDateToNumber;
|
|
1206
|
+
declare const parseDateToDate: (value: unknown) => Date;
|
|
1200
1207
|
declare const getDateAsDateFn: (column: {
|
|
1201
1208
|
data: Column.Data;
|
|
1202
1209
|
dateParsedByDriver?: boolean;
|
|
1203
|
-
}) =>
|
|
1210
|
+
}) => typeof parseDateToDate;
|
|
1204
1211
|
declare abstract class DateBaseColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1205
1212
|
dateParsedByDriver?: boolean | undefined;
|
|
1206
1213
|
__schema: Schema;
|
|
@@ -1218,7 +1225,7 @@ declare abstract class DateBaseColumn<Schema extends ColumnSchemaConfig> extends
|
|
|
1218
1225
|
constructor(schema: Schema, dateParsedByDriver?: boolean | undefined);
|
|
1219
1226
|
}
|
|
1220
1227
|
declare class DateColumn<Schema extends ColumnSchemaConfig> extends DateBaseColumn<Schema> {
|
|
1221
|
-
dataType:
|
|
1228
|
+
dataType: 'date';
|
|
1222
1229
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1223
1230
|
}
|
|
1224
1231
|
declare abstract class DateTimeBaseClass<Schema extends ColumnSchemaConfig> extends DateBaseColumn<Schema> {
|
|
@@ -1233,12 +1240,12 @@ declare abstract class DateTimeTzBaseClass<Schema extends ColumnSchemaConfig> ex
|
|
|
1233
1240
|
toSQL(): string;
|
|
1234
1241
|
}
|
|
1235
1242
|
declare class TimestampColumn<Schema extends ColumnSchemaConfig> extends DateTimeBaseClass<Schema> {
|
|
1236
|
-
dataType:
|
|
1243
|
+
dataType: 'timestamp';
|
|
1237
1244
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1238
1245
|
}
|
|
1239
1246
|
declare class TimestampTZColumn<Schema extends ColumnSchemaConfig> extends DateTimeTzBaseClass<Schema> {
|
|
1240
|
-
dataType:
|
|
1241
|
-
baseDataType:
|
|
1247
|
+
dataType: 'timestamptz';
|
|
1248
|
+
baseDataType: 'timestamp';
|
|
1242
1249
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1243
1250
|
}
|
|
1244
1251
|
declare class TimeColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
@@ -1253,7 +1260,7 @@ declare class TimeColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1253
1260
|
outputSchema: ReturnType<Schema['stringSchema']>;
|
|
1254
1261
|
__queryType: string;
|
|
1255
1262
|
querySchema: ReturnType<Schema['stringSchema']>;
|
|
1256
|
-
dataType:
|
|
1263
|
+
dataType: 'time';
|
|
1257
1264
|
operators: OperatorsTime;
|
|
1258
1265
|
constructor(schema: Schema, dateTimePrecision?: number);
|
|
1259
1266
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
@@ -1271,7 +1278,7 @@ declare class IntervalColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1271
1278
|
outputSchema: ReturnType<Schema['timeInterval']>;
|
|
1272
1279
|
__queryType: PostgresInterval;
|
|
1273
1280
|
querySchema: ReturnType<Schema['timeInterval']>;
|
|
1274
|
-
dataType:
|
|
1281
|
+
dataType: 'interval';
|
|
1275
1282
|
operators: OperatorsDate;
|
|
1276
1283
|
constructor(schema: Schema, fields?: string, precision?: number, parse?: (input: string) => PostgresInterval);
|
|
1277
1284
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
@@ -1312,8 +1319,8 @@ interface ArrayData<Item extends ArrayColumnValue> extends Column.Data, ArrayMet
|
|
|
1312
1319
|
}
|
|
1313
1320
|
declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends ArrayColumnValue, InputType, OutputType, QueryType> extends Column {
|
|
1314
1321
|
__schema: Schema;
|
|
1315
|
-
dataType:
|
|
1316
|
-
operators: OperatorsArray<Item[
|
|
1322
|
+
dataType: 'array';
|
|
1323
|
+
operators: OperatorsArray<Item['__queryType']>;
|
|
1317
1324
|
data: ArrayData<Item>;
|
|
1318
1325
|
__type: Item['__type'][];
|
|
1319
1326
|
__inputType: Item['__type'][];
|
|
@@ -1328,7 +1335,7 @@ declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends Array
|
|
|
1328
1335
|
}
|
|
1329
1336
|
declare class JSONColumn<T, Schema extends ColumnTypeSchemaArg, InputSchema = Schema['__schemaType']> extends Column {
|
|
1330
1337
|
__schema: Schema;
|
|
1331
|
-
dataType:
|
|
1338
|
+
dataType: 'jsonb';
|
|
1332
1339
|
__type: T;
|
|
1333
1340
|
__inputType: T;
|
|
1334
1341
|
inputSchema: InputSchema;
|
|
@@ -1342,7 +1349,7 @@ declare class JSONColumn<T, Schema extends ColumnTypeSchemaArg, InputSchema = Sc
|
|
|
1342
1349
|
}
|
|
1343
1350
|
declare class JSONTextColumn<T, Schema extends ColumnTypeSchemaArg, InputSchema = Schema['__schemaType']> extends Column {
|
|
1344
1351
|
__schema: Schema;
|
|
1345
|
-
dataType:
|
|
1352
|
+
dataType: 'json';
|
|
1346
1353
|
__type: T;
|
|
1347
1354
|
__inputType: T;
|
|
1348
1355
|
inputSchema: InputSchema;
|
|
@@ -1357,10 +1364,10 @@ declare class JSONTextColumn<T, Schema extends ColumnTypeSchemaArg, InputSchema
|
|
|
1357
1364
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1358
1365
|
}
|
|
1359
1366
|
interface DefaultSchemaConfig extends ColumnSchemaConfig<Column> {
|
|
1360
|
-
nullable<T extends Column.Pick.ForNullable>(this: T): Column.
|
|
1361
|
-
parse<T extends Column.Pick.ForParse, Output>(this: T, fn: (input: T['__type']) => Output): Column.
|
|
1362
|
-
parseNull<T extends Column.Pick.ForParseNull, Output>(this: T, fn: () => Output): Column.
|
|
1363
|
-
encode<T extends Column.Pick.Type, Input>(this: T, fn: (input: Input) => unknown): Column.
|
|
1367
|
+
nullable<T extends Column.Pick.ForNullable>(this: T): Column.Nullable<T>;
|
|
1368
|
+
parse<T extends Column.Pick.ForParse, Output>(this: T, fn: (input: T['__type']) => Output): Column.Parse<T, unknown, Output>;
|
|
1369
|
+
parseNull<T extends Column.Pick.ForParseNull, Output>(this: T, fn: () => Output): Column.ParseNull<T, unknown, Output>;
|
|
1370
|
+
encode<T extends Column.Pick.Type, Input>(this: T, fn: (input: Input) => unknown): Column.Encode<T, unknown, Input>;
|
|
1364
1371
|
/**
|
|
1365
1372
|
* @deprecated use narrowType instead
|
|
1366
1373
|
*/
|
|
@@ -1374,12 +1381,12 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<Column> {
|
|
|
1374
1381
|
__inputType: Input;
|
|
1375
1382
|
__outputType: Output;
|
|
1376
1383
|
__queryType: Query;
|
|
1377
|
-
}) => Types): { [K in keyof T]: K extends '__type' ? Types['type'] : K extends keyof Types ? Types[K] : T[K] };
|
|
1378
|
-
narrowType<T extends Column.InputOutputQueryTypes, Types extends Column.InputOutputQueryTypes>(this: T, _fn: (type: <Type extends
|
|
1384
|
+
}) => Types): { [K in keyof T]: K extends '__type' ? Types['type'] : K extends keyof Types ? Types[K] : T[K]; };
|
|
1385
|
+
narrowType<T extends Column.InputOutputQueryTypes, Types extends Column.InputOutputQueryTypes>(this: T, _fn: (type: <Type extends T['__inputType'] extends T['__outputType'] & T['__queryType'] ? T['__outputType'] & T['__queryType'] : T['__inputType'] & T['__outputType'] & T['__queryType']>() => {
|
|
1379
1386
|
__inputType: T['__inputType'] extends never ? never : Type;
|
|
1380
1387
|
__outputType: Type;
|
|
1381
1388
|
__queryType: Type;
|
|
1382
|
-
}) => Types): { [K in keyof T]: K extends keyof Types ? Types[K] : T[K] };
|
|
1389
|
+
}) => Types): { [K in keyof T]: K extends keyof Types ? Types[K] : T[K]; };
|
|
1383
1390
|
narrowAllTypes<T extends Column.InputOutputQueryTypes, Types extends Column.InputOutputQueryTypes>(this: T, _fn: (type: <Types extends {
|
|
1384
1391
|
input?: T['__inputType'];
|
|
1385
1392
|
output?: T['__outputType'];
|
|
@@ -1388,9 +1395,9 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<Column> {
|
|
|
1388
1395
|
__inputType: undefined extends Types['input'] ? T['__inputType'] : Types['input'];
|
|
1389
1396
|
__outputType: undefined extends Types['output'] ? T['__outputType'] : Types['output'];
|
|
1390
1397
|
__queryType: undefined extends Types['query'] ? T['__queryType'] : Types['query'];
|
|
1391
|
-
}) => Types): { [K in keyof T]: K extends keyof Types ? Types[K] : T[K] };
|
|
1392
|
-
dateAsNumber<T extends Column.Pick.ForParse>(this: T): Column.
|
|
1393
|
-
dateAsDate<T extends Column.Pick.ForParse>(this: T): Column.
|
|
1398
|
+
}) => Types): { [K in keyof T]: K extends keyof Types ? Types[K] : T[K]; };
|
|
1399
|
+
dateAsNumber<T extends Column.Pick.ForParse>(this: T): Column.Parse<T, unknown, number>;
|
|
1400
|
+
dateAsDate<T extends Column.Pick.ForParse>(this: T): Column.Parse<T, unknown, Date>;
|
|
1394
1401
|
enum<const T extends readonly [string, ...string[]]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, T>;
|
|
1395
1402
|
array<Item extends ArrayColumnValue>(item: Item): ArrayColumn<DefaultSchemaConfig, Item, unknown, unknown, unknown>;
|
|
1396
1403
|
json<T>(): JSONColumn<unknown extends T ? MaybeArray<string | number | boolean | object> : T, DefaultSchemaConfig>;
|
|
@@ -1443,7 +1450,7 @@ declare abstract class LimitedTextBaseColumn<Schema extends ColumnSchemaConfig>
|
|
|
1443
1450
|
toSQL(): string;
|
|
1444
1451
|
}
|
|
1445
1452
|
declare class VarCharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
|
|
1446
|
-
dataType:
|
|
1453
|
+
dataType: 'varchar';
|
|
1447
1454
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1448
1455
|
}
|
|
1449
1456
|
declare class StringColumn<Schema extends ColumnSchemaConfig> extends VarCharColumn<Schema> {
|
|
@@ -1451,7 +1458,7 @@ declare class StringColumn<Schema extends ColumnSchemaConfig> extends VarCharCol
|
|
|
1451
1458
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1452
1459
|
}
|
|
1453
1460
|
declare class TextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema, OperatorsOrdinalText> {
|
|
1454
|
-
dataType:
|
|
1461
|
+
dataType: 'text';
|
|
1455
1462
|
data: TextColumnData & {
|
|
1456
1463
|
minArg?: number;
|
|
1457
1464
|
maxArg?: number;
|
|
@@ -1465,7 +1472,7 @@ declare class TextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColu
|
|
|
1465
1472
|
}
|
|
1466
1473
|
declare class ByteaColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1467
1474
|
__schema: Schema;
|
|
1468
|
-
dataType:
|
|
1475
|
+
dataType: 'bytea';
|
|
1469
1476
|
operators: OperatorsOrdinalText;
|
|
1470
1477
|
__type: string;
|
|
1471
1478
|
__inputType: Buffer;
|
|
@@ -1479,7 +1486,7 @@ declare class ByteaColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1479
1486
|
}
|
|
1480
1487
|
declare class PointColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1481
1488
|
__schema: Schema;
|
|
1482
|
-
dataType:
|
|
1489
|
+
dataType: 'point';
|
|
1483
1490
|
__type: string;
|
|
1484
1491
|
__inputType: string;
|
|
1485
1492
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1493,7 +1500,7 @@ declare class PointColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1493
1500
|
}
|
|
1494
1501
|
declare class LineColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1495
1502
|
__schema: Schema;
|
|
1496
|
-
dataType:
|
|
1503
|
+
dataType: 'line';
|
|
1497
1504
|
__type: string;
|
|
1498
1505
|
__inputType: string;
|
|
1499
1506
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1507,7 +1514,7 @@ declare class LineColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1507
1514
|
}
|
|
1508
1515
|
declare class LsegColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1509
1516
|
__schema: Schema;
|
|
1510
|
-
dataType:
|
|
1517
|
+
dataType: 'lseg';
|
|
1511
1518
|
__type: string;
|
|
1512
1519
|
__inputType: string;
|
|
1513
1520
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1521,7 +1528,7 @@ declare class LsegColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1521
1528
|
}
|
|
1522
1529
|
declare class BoxColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1523
1530
|
__schema: Schema;
|
|
1524
|
-
dataType:
|
|
1531
|
+
dataType: 'box';
|
|
1525
1532
|
__type: string;
|
|
1526
1533
|
__inputType: string;
|
|
1527
1534
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1535,7 +1542,7 @@ declare class BoxColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1535
1542
|
}
|
|
1536
1543
|
declare class PathColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1537
1544
|
__schema: Schema;
|
|
1538
|
-
dataType:
|
|
1545
|
+
dataType: 'path';
|
|
1539
1546
|
__type: string;
|
|
1540
1547
|
__inputType: string;
|
|
1541
1548
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1549,7 +1556,7 @@ declare class PathColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1549
1556
|
}
|
|
1550
1557
|
declare class PolygonColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1551
1558
|
__schema: Schema;
|
|
1552
|
-
dataType:
|
|
1559
|
+
dataType: 'polygon';
|
|
1553
1560
|
__type: string;
|
|
1554
1561
|
__inputType: string;
|
|
1555
1562
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1563,7 +1570,7 @@ declare class PolygonColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1563
1570
|
}
|
|
1564
1571
|
declare class CircleColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1565
1572
|
__schema: Schema;
|
|
1566
|
-
dataType:
|
|
1573
|
+
dataType: 'circle';
|
|
1567
1574
|
__type: string;
|
|
1568
1575
|
__inputType: string;
|
|
1569
1576
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1577,7 +1584,7 @@ declare class CircleColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1577
1584
|
}
|
|
1578
1585
|
declare class MoneyColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1579
1586
|
__schema: Schema;
|
|
1580
|
-
dataType:
|
|
1587
|
+
dataType: 'money';
|
|
1581
1588
|
__type: string;
|
|
1582
1589
|
data: NumberColumnData;
|
|
1583
1590
|
__inputType: string | number;
|
|
@@ -1592,7 +1599,7 @@ declare class MoneyColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1592
1599
|
}
|
|
1593
1600
|
declare class CidrColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1594
1601
|
__schema: Schema;
|
|
1595
|
-
dataType:
|
|
1602
|
+
dataType: 'cidr';
|
|
1596
1603
|
__type: string;
|
|
1597
1604
|
__inputType: string;
|
|
1598
1605
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1606,7 +1613,7 @@ declare class CidrColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1606
1613
|
}
|
|
1607
1614
|
declare class InetColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1608
1615
|
__schema: Schema;
|
|
1609
|
-
dataType:
|
|
1616
|
+
dataType: 'inet';
|
|
1610
1617
|
__type: string;
|
|
1611
1618
|
__inputType: string;
|
|
1612
1619
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1620,7 +1627,7 @@ declare class InetColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1620
1627
|
}
|
|
1621
1628
|
declare class MacAddrColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1622
1629
|
__schema: Schema;
|
|
1623
|
-
dataType:
|
|
1630
|
+
dataType: 'macaddr';
|
|
1624
1631
|
__type: string;
|
|
1625
1632
|
__inputType: string;
|
|
1626
1633
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1634,7 +1641,7 @@ declare class MacAddrColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1634
1641
|
}
|
|
1635
1642
|
declare class MacAddr8Column<Schema extends ColumnSchemaConfig> extends Column {
|
|
1636
1643
|
__schema: Schema;
|
|
1637
|
-
dataType:
|
|
1644
|
+
dataType: 'macaddr8';
|
|
1638
1645
|
__type: string;
|
|
1639
1646
|
__inputType: string;
|
|
1640
1647
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1648,7 +1655,7 @@ declare class MacAddr8Column<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1648
1655
|
}
|
|
1649
1656
|
declare class BitColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1650
1657
|
__schema: Schema;
|
|
1651
|
-
dataType:
|
|
1658
|
+
dataType: 'bit';
|
|
1652
1659
|
__type: string;
|
|
1653
1660
|
__inputType: string;
|
|
1654
1661
|
inputSchema: ReturnType<Schema['bit']>;
|
|
@@ -1666,7 +1673,7 @@ declare class BitColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1666
1673
|
}
|
|
1667
1674
|
declare class BitVaryingColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1668
1675
|
__schema: Schema;
|
|
1669
|
-
dataType:
|
|
1676
|
+
dataType: 'varbit';
|
|
1670
1677
|
__type: string;
|
|
1671
1678
|
__inputType: string;
|
|
1672
1679
|
inputSchema: ReturnType<Schema['bit']>;
|
|
@@ -1686,7 +1693,7 @@ type TsVectorGeneratedColumns = string[] | SearchWeightRecord;
|
|
|
1686
1693
|
declare class TsVectorColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1687
1694
|
defaultLanguage: string;
|
|
1688
1695
|
__schema: Schema;
|
|
1689
|
-
dataType:
|
|
1696
|
+
dataType: 'tsvector';
|
|
1690
1697
|
__type: string;
|
|
1691
1698
|
__inputType: string;
|
|
1692
1699
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1721,11 +1728,11 @@ declare class TsVectorColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1721
1728
|
*
|
|
1722
1729
|
* @param args
|
|
1723
1730
|
*/
|
|
1724
|
-
generated<T extends Column.Pick.Data>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): Column.
|
|
1731
|
+
generated<T extends Column.Pick.Data>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): Column.Generated<T>;
|
|
1725
1732
|
}
|
|
1726
1733
|
declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1727
1734
|
__schema: Schema;
|
|
1728
|
-
dataType:
|
|
1735
|
+
dataType: 'tsquery';
|
|
1729
1736
|
__type: string;
|
|
1730
1737
|
__inputType: string;
|
|
1731
1738
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1739,7 +1746,7 @@ declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1739
1746
|
}
|
|
1740
1747
|
declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1741
1748
|
__schema: Schema;
|
|
1742
|
-
dataType:
|
|
1749
|
+
dataType: 'uuid';
|
|
1743
1750
|
__type: string;
|
|
1744
1751
|
__inputType: string;
|
|
1745
1752
|
inputSchema: ReturnType<Schema['uuid']>;
|
|
@@ -1752,7 +1759,8 @@ declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1752
1759
|
/**
|
|
1753
1760
|
* see {@link Column.primaryKey}
|
|
1754
1761
|
*/
|
|
1755
|
-
primaryKey<T extends Column.Pick.Data, Name extends string>(this: T, name?: Name):
|
|
1762
|
+
primaryKey<T extends Column.Pick.Data, Name extends string>(this: T, name?: Name):
|
|
1763
|
+
// using & bc otherwise the return type doesn't match `primaryKey` in ColumnType and TS complains
|
|
1756
1764
|
T & {
|
|
1757
1765
|
data: {
|
|
1758
1766
|
primaryKey: Name;
|
|
@@ -1763,7 +1771,7 @@ declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1763
1771
|
}
|
|
1764
1772
|
declare class XMLColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1765
1773
|
__schema: Schema;
|
|
1766
|
-
dataType:
|
|
1774
|
+
dataType: 'xml';
|
|
1767
1775
|
__type: string;
|
|
1768
1776
|
__inputType: string;
|
|
1769
1777
|
inputSchema: ReturnType<Schema['stringSchema']>;
|
|
@@ -1779,7 +1787,7 @@ declare class XMLColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1779
1787
|
}
|
|
1780
1788
|
declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema, OperatorsOrdinalText> {
|
|
1781
1789
|
__schema: Schema;
|
|
1782
|
-
dataType:
|
|
1790
|
+
dataType: 'citext';
|
|
1783
1791
|
data: TextColumnData & {
|
|
1784
1792
|
minArg?: number;
|
|
1785
1793
|
maxArg?: number;
|
|
@@ -1791,7 +1799,7 @@ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseCo
|
|
|
1791
1799
|
}
|
|
1792
1800
|
declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1793
1801
|
__schema: Schema;
|
|
1794
|
-
dataType:
|
|
1802
|
+
dataType: 'bool';
|
|
1795
1803
|
operators: OperatorsBoolean;
|
|
1796
1804
|
__type: boolean;
|
|
1797
1805
|
__inputType: boolean;
|
|
@@ -1808,8 +1816,8 @@ declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
|
1808
1816
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
1809
1817
|
}
|
|
1810
1818
|
interface Timestamps<T extends Column.Pick.Data> {
|
|
1811
|
-
createdAt: Column.
|
|
1812
|
-
updatedAt: Column.
|
|
1819
|
+
createdAt: Column.HasDefault<T>;
|
|
1820
|
+
updatedAt: Column.HasDefault<T>;
|
|
1813
1821
|
}
|
|
1814
1822
|
interface TimestampHelpers {
|
|
1815
1823
|
/**
|
|
@@ -1858,6 +1866,7 @@ interface PostgisPoint {
|
|
|
1858
1866
|
lat: number;
|
|
1859
1867
|
srid?: number;
|
|
1860
1868
|
}
|
|
1869
|
+
declare const encode: ({ srid, lon, lat }: PostgisPoint) => string;
|
|
1861
1870
|
declare class PostgisGeographyPointColumn<Schema extends ColumnSchemaConfig> extends Column {
|
|
1862
1871
|
__schema: Schema;
|
|
1863
1872
|
dataType: string;
|
|
@@ -1869,11 +1878,7 @@ declare class PostgisGeographyPointColumn<Schema extends ColumnSchemaConfig> ext
|
|
|
1869
1878
|
__queryType: PostgisPoint;
|
|
1870
1879
|
querySchema: ReturnType<Schema['geographyPointSchema']>;
|
|
1871
1880
|
operators: OperatorsAny;
|
|
1872
|
-
static encode:
|
|
1873
|
-
srid,
|
|
1874
|
-
lon,
|
|
1875
|
-
lat
|
|
1876
|
-
}: PostgisPoint) => string;
|
|
1881
|
+
static encode: typeof encode;
|
|
1877
1882
|
static isDefaultPoint(typmod: number): boolean;
|
|
1878
1883
|
constructor(schema: Schema);
|
|
1879
1884
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
@@ -1892,7 +1897,7 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
|
|
|
1892
1897
|
decimal: SchemaConfig['decimal'];
|
|
1893
1898
|
real: SchemaConfig['real'];
|
|
1894
1899
|
doublePrecision: SchemaConfig['doublePrecision'];
|
|
1895
|
-
identity(options?: TableData.Identity): Column.
|
|
1900
|
+
identity(options?: TableData.Identity): Column.HasDefault<ReturnType<SchemaConfig['integer']>>;
|
|
1896
1901
|
smallSerial: SchemaConfig['smallSerial'];
|
|
1897
1902
|
serial: SchemaConfig['serial'];
|
|
1898
1903
|
bigSerial: SchemaConfig['bigSerial'];
|
|
@@ -2003,7 +2008,7 @@ interface BatchParser {
|
|
|
2003
2008
|
rows: unknown[];
|
|
2004
2009
|
}) => MaybePromise<void>;
|
|
2005
2010
|
}
|
|
2006
|
-
type ColumnsParsers = { [K in string]?: ColumnParser };
|
|
2011
|
+
type ColumnsParsers = { [K in string]?: ColumnParser; };
|
|
2007
2012
|
type BatchParsers = BatchParser[];
|
|
2008
2013
|
interface QueryThen<T> {
|
|
2009
2014
|
<TResult1 = T, TResult2 = never>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>;
|
|
@@ -2028,7 +2033,7 @@ type WithSelectable<W extends WithDataItem> = keyof W['shape'] | `${W['table']}.
|
|
|
2028
2033
|
* The first argument of all `join` and `joinLateral` methods.
|
|
2029
2034
|
* See argument of {@link join}.
|
|
2030
2035
|
*/
|
|
2031
|
-
type JoinFirstArg<T extends PickQueryRelationsWithData> = PickQueryResultAs | keyof T['relations'] | keyof T['withData'] | ((q: { [K in keyof T['relations']]: T['relations'][K]['query'] }) => PickQueryResultAs) | FnPickQueryResultAs;
|
|
2036
|
+
type JoinFirstArg<T extends PickQueryRelationsWithData> = PickQueryResultAs | keyof T['relations'] | keyof T['withData'] | ((q: { [K in keyof T['relations']]: T['relations'][K]['query']; }) => PickQueryResultAs) | FnPickQueryResultAs;
|
|
2032
2037
|
interface FnPickQueryResultAs {
|
|
2033
2038
|
(): PickQueryResultAs;
|
|
2034
2039
|
}
|
|
@@ -2036,7 +2041,7 @@ interface FnPickQueryResultAs {
|
|
|
2036
2041
|
* Arguments of `join` methods (not `joinLateral`).
|
|
2037
2042
|
* See {@link join}
|
|
2038
2043
|
*/
|
|
2039
|
-
type JoinArgs<T extends PickQuerySelectableShapeRelationsWithDataAs, Arg extends JoinFirstArg<T>> = Arg extends PickQueryResultAs ? [conditions: { [K in JoinSelectable<Arg>]: keyof T['__selectable'] | Expression } | Expression] | [leftColumn: JoinSelectable<Arg> | Expression, rightColumn: keyof T['__selectable'] | Expression] | [leftColumn: JoinSelectable<Arg> | Expression, op: string, rightColumn: keyof T['__selectable'] | Expression] : Arg extends keyof T['withData'] ? JoinWithArgs<T, T['withData'][Arg]> : EmptyTuple;
|
|
2044
|
+
type JoinArgs<T extends PickQuerySelectableShapeRelationsWithDataAs, Arg extends JoinFirstArg<T>> = Arg extends PickQueryResultAs ? [conditions: { [K in JoinSelectable<Arg>]: keyof T['__selectable'] | Expression; } | Expression] | [leftColumn: JoinSelectable<Arg> | Expression, rightColumn: keyof T['__selectable'] | Expression] | [leftColumn: JoinSelectable<Arg> | Expression, op: string, rightColumn: keyof T['__selectable'] | Expression] : Arg extends keyof T['withData'] ? JoinWithArgs<T, T['withData'][Arg]> : EmptyTuple;
|
|
2040
2045
|
/**
|
|
2041
2046
|
* Column names of the joined table that can be used to join.
|
|
2042
2047
|
* Derived from 'result', not from 'shape',
|
|
@@ -2047,16 +2052,16 @@ type JoinArgs<T extends PickQuerySelectableShapeRelationsWithDataAs, Arg extends
|
|
|
2047
2052
|
* And the selection becomes available to use in the `ON` and to select from the joined table.
|
|
2048
2053
|
*/
|
|
2049
2054
|
type JoinSelectable<Q extends PickQueryResultAs> = keyof Q['result'] | `${Q['__as']}.${keyof Q['result'] & string}`;
|
|
2050
|
-
type JoinWithArgs<T extends PickQuerySelectable, Arg extends WithDataItem> = [conditions: { [K in WithSelectable<Arg>]: keyof T['__selectable'] | Expression } | Expression] | [leftColumn: WithSelectable<Arg> | Expression, rightColumn: keyof T['__selectable'] | Expression] | [leftColumn: WithSelectable<Arg> | Expression, op: string, rightColumn: keyof T['__selectable'] | Expression];
|
|
2051
|
-
type JoinResultRequireMain<T extends PickQuerySelectable, JoinedSelectable> = { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & JoinedSelectable : T[K] };
|
|
2055
|
+
type JoinWithArgs<T extends PickQuerySelectable, Arg extends WithDataItem> = [conditions: { [K in WithSelectable<Arg>]: keyof T['__selectable'] | Expression; } | Expression] | [leftColumn: WithSelectable<Arg> | Expression, rightColumn: keyof T['__selectable'] | Expression] | [leftColumn: WithSelectable<Arg> | Expression, op: string, rightColumn: keyof T['__selectable'] | Expression];
|
|
2056
|
+
type JoinResultRequireMain<T extends PickQuerySelectable, JoinedSelectable> = { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & JoinedSelectable : T[K]; };
|
|
2052
2057
|
/**
|
|
2053
2058
|
* Result of all `join` methods, not `joinLateral`.
|
|
2054
2059
|
* Adds joined table columns from its 'result' to the '__selectable' of the query.
|
|
2055
2060
|
*/
|
|
2056
|
-
type JoinResult<T extends PickQuerySelectableRelationsResultReturnType, Joined extends PickQuerySelectableRelations, RequireMain> = RequireMain extends true ? { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & Joined['__selectable'] : K extends 'relations' ? { [K in keyof T['relations'] | keyof Joined['relations']]: K extends keyof Joined['relations'] ? Joined['relations'][K] : T['relations'][K] } : T[K] } : { [K in keyof T]: K extends '__selectable' ? { [K in keyof T['__selectable']]: {
|
|
2061
|
+
type JoinResult<T extends PickQuerySelectableRelationsResultReturnType, Joined extends PickQuerySelectableRelations, RequireMain> = RequireMain extends true ? { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & Joined['__selectable'] : K extends 'relations' ? { [K in keyof T['relations'] | keyof Joined['relations']]: K extends keyof Joined['relations'] ? Joined['relations'][K] : T['relations'][K]; } : T[K]; } : { [K in keyof T]: K extends '__selectable' ? { [K in keyof T['__selectable']]: {
|
|
2057
2062
|
as: T['__selectable'][K]['as'];
|
|
2058
|
-
column: Column.
|
|
2059
|
-
} } & Joined['__selectable'] : K extends 'result' ? { [K in keyof T['result']]: Column.
|
|
2063
|
+
column: Column.QueryColumnToNullable<T['__selectable'][K]['column']>;
|
|
2064
|
+
}; } & Joined['__selectable'] : K extends 'result' ? { [K in keyof T['result']]: Column.QueryColumnToNullable<T['result'][K]>; } : K extends 'then' ? QueryThenByQuery<T, { [K in keyof T['result']]: Column.QueryColumnToNullable<T['result'][K]>; }> : K extends 'relations' ? { [K in keyof T['relations'] | keyof Joined['relations']]: K extends keyof Joined['relations'] ? Joined['relations'][K] : T['relations'][K]; } : T[K]; };
|
|
2060
2065
|
/**
|
|
2061
2066
|
* Calls {@link JoinResult} with either callback result, if join has a callback,
|
|
2062
2067
|
* or with a query derived from the first join argument.
|
|
@@ -2095,19 +2100,19 @@ type JoinResultSelectable<Result extends Column.QueryColumns, As extends string,
|
|
|
2095
2100
|
} : {
|
|
2096
2101
|
as: K;
|
|
2097
2102
|
column: Result[K];
|
|
2098
|
-
} };
|
|
2099
|
-
relations: { [K in keyof JoinedRelations & string as `${As}.${K}`]: JoinedRelations[K] };
|
|
2103
|
+
}; };
|
|
2104
|
+
relations: { [K in keyof JoinedRelations & string as `${As}.${K}`]: JoinedRelations[K]; };
|
|
2100
2105
|
} : {
|
|
2101
2106
|
__selectable: { [K in '*' | (keyof Result & string) as `${As}.${K}`]: K extends '*' ? {
|
|
2102
2107
|
as: As;
|
|
2103
2108
|
column: ColumnsShape.MapToNullableObjectColumn<Result>;
|
|
2104
2109
|
} : {
|
|
2105
2110
|
as: K;
|
|
2106
|
-
column: Column.
|
|
2107
|
-
} };
|
|
2108
|
-
relations: { [K in keyof JoinedRelations & string as `${As}.${K}`]: JoinedRelations[K] };
|
|
2111
|
+
column: Column.QueryColumnToNullable<Result[K]>;
|
|
2112
|
+
}; };
|
|
2113
|
+
relations: { [K in keyof JoinedRelations & string as `${As}.${K}`]: JoinedRelations[K]; };
|
|
2109
2114
|
};
|
|
2110
|
-
type JoinAddSelectable<T extends PickQuerySelectable, Joined extends PickQuerySelectableRelations> = { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & Joined['__selectable'] : T[K] };
|
|
2115
|
+
type JoinAddSelectable<T extends PickQuerySelectable, Joined extends PickQuerySelectableRelations> = { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & Joined['__selectable'] : T[K]; };
|
|
2111
2116
|
/**
|
|
2112
2117
|
* Map the first argument of `join` or `joinLateral` to a query type.
|
|
2113
2118
|
*
|
|
@@ -2118,7 +2123,7 @@ type JoinAddSelectable<T extends PickQuerySelectable, Joined extends PickQuerySe
|
|
|
2118
2123
|
type JoinArgToQuery<T extends PickQueryRelationsWithData, Arg extends JoinFirstArg<T>> = Arg extends keyof T['withData'] ? T['withData'][Arg] extends WithDataItem ? { [K in 'result' | '__as' | keyof T]: K extends '__as' ? T['withData'][Arg]['table'] : K extends '__selectable' ? { [K in keyof T['withData'][Arg]['shape'] & string as `${T['withData'][Arg]['table']}.${K}`]: {
|
|
2119
2124
|
as: K;
|
|
2120
2125
|
column: T['withData'][Arg]['shape'][K];
|
|
2121
|
-
} } : K extends 'result' ? T['withData'][Arg]['shape'] : K extends keyof T ? T[K] : never } : never : Arg extends PickQuerySelectableResultAs ? Arg : Arg extends keyof T['relations'] ? T['relations'][Arg]['query'] : Arg extends JoinArgToQueryCallback ? ReturnType<Arg> : never;
|
|
2126
|
+
}; } : K extends 'result' ? T['withData'][Arg]['shape'] : K extends keyof T ? T[K] : never; } : never : Arg extends PickQuerySelectableResultAs ? Arg : Arg extends keyof T['relations'] ? T['relations'][Arg]['query'] : Arg extends JoinArgToQueryCallback ? ReturnType<Arg> : never;
|
|
2122
2127
|
interface JoinArgToQueryCallback {
|
|
2123
2128
|
(...args: any[]): IsQuery;
|
|
2124
2129
|
}
|
|
@@ -2199,36 +2204,21 @@ declare class QueryJoin {
|
|
|
2199
2204
|
* For the following examples, imagine you have a `User` table with `id` and `name`, and `Message` table with `id`, `text`, messages belongs to user via `userId` column:
|
|
2200
2205
|
*
|
|
2201
2206
|
* ```ts
|
|
2202
|
-
* export
|
|
2203
|
-
*
|
|
2204
|
-
*
|
|
2205
|
-
*
|
|
2206
|
-
*
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2209
|
-
* relations = {
|
|
2210
|
-
* messages: this.hasMany(() => MessageTable, {
|
|
2211
|
-
* primaryKey: 'id',
|
|
2212
|
-
* foreignKey: 'userId',
|
|
2213
|
-
* }),
|
|
2214
|
-
* };
|
|
2215
|
-
* }
|
|
2216
|
-
*
|
|
2217
|
-
* export class MessageTable extends BaseTable {
|
|
2218
|
-
* readonly table = 'message';
|
|
2219
|
-
* columns = this.setColumns((t) => ({
|
|
2220
|
-
* id: t.identity().primaryKey(),
|
|
2221
|
-
* text: t.text(),
|
|
2222
|
-
* ...t.timestamps(),
|
|
2223
|
-
* }));
|
|
2207
|
+
* export const UserTable = defineTable('user', (t) => ({
|
|
2208
|
+
* id: t.identity().primaryKey(),
|
|
2209
|
+
* name: t.text(),
|
|
2210
|
+
* })).relations((user) => ({
|
|
2211
|
+
* messages: user('id').hasMany(() => MessageTable('userId')),
|
|
2212
|
+
* }));
|
|
2224
2213
|
*
|
|
2225
|
-
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
2229
|
-
*
|
|
2230
|
-
*
|
|
2231
|
-
*
|
|
2214
|
+
* export const MessageTable = defineTable('message', (t) => ({
|
|
2215
|
+
* id: t.identity().primaryKey(),
|
|
2216
|
+
* userId: t.integer(),
|
|
2217
|
+
* text: t.text(),
|
|
2218
|
+
* ...t.timestamps(),
|
|
2219
|
+
* })).relations((message) => ({
|
|
2220
|
+
* user: message('userId').belongsTo(() => UserTable('id')),
|
|
2221
|
+
* }));
|
|
2232
2222
|
* ```
|
|
2233
2223
|
*
|
|
2234
2224
|
* `join` is a method for SQL `JOIN`, which is equivalent to `INNER JOIN`, `LEFT INNERT JOIN`.
|
|
@@ -2425,7 +2415,7 @@ declare class QueryJoin {
|
|
|
2425
2415
|
* ```ts
|
|
2426
2416
|
* db.user.join(
|
|
2427
2417
|
* db.message,
|
|
2428
|
-
* // `sql` can be imported from your
|
|
2418
|
+
* // `sql` can be imported from your table factory file
|
|
2429
2419
|
* sql`lower("message"."text") = lower("user"."name")`,
|
|
2430
2420
|
* );
|
|
2431
2421
|
* ```
|
|
@@ -2766,7 +2756,7 @@ declare class QueryJoin {
|
|
|
2766
2756
|
joinData<T extends PickQuerySelectableColumnTypes, As extends string, RecordType extends Column.QueryColumnsInit, Item extends ColumnsShape.Input<RecordType>>(this: T, as: As, fn: (types: T['columnTypes']) => RecordType, data: Item[]): { [K in keyof T]: K extends '__selectable' ? T['__selectable'] & { [K in keyof RecordType & string as `${As}.${K}`]: {
|
|
2767
2757
|
as: K;
|
|
2768
2758
|
column: RecordType[K];
|
|
2769
|
-
} } : T[K] };
|
|
2759
|
+
}; } : T[K]; };
|
|
2770
2760
|
}
|
|
2771
2761
|
type OnArgs<S extends QuerySelectable> = [leftColumn: keyof S, rightColumn: keyof S] | [leftColumn: keyof S, op: string, rightColumn: keyof S];
|
|
2772
2762
|
declare const pushQueryOnForOuter: <T extends PickQuerySelectable>(q: T, joinFrom: PickQuerySelectable, joinTo: PickQuerySelectable, leftColumn: string, rightColumn: string) => T;
|
|
@@ -2774,13 +2764,13 @@ type OnJsonPathEqualsArgs<S extends QuerySelectable> = [leftColumn: keyof S, lef
|
|
|
2774
2764
|
/**
|
|
2775
2765
|
* Mutative {@link OnMethods.prototype.on}
|
|
2776
2766
|
*/
|
|
2777
|
-
declare const _queryJoinOn: <T extends PickQuerySelectable>(q: T, args: OnArgs<T[
|
|
2767
|
+
declare const _queryJoinOn: <T extends PickQuerySelectable>(q: T, args: OnArgs<T['__selectable']>) => T;
|
|
2778
2768
|
/**
|
|
2779
2769
|
* Argument of join callback.
|
|
2780
2770
|
* It is a query object of table that you're joining, with ability to select main table's columns.
|
|
2781
2771
|
* Adds {@link OnMethods.prototype.on} method and similar to the query.
|
|
2782
2772
|
*/
|
|
2783
|
-
type JoinQueryBuilder<T extends PickQuerySelectableShape, J extends PickQuerySelectableResultAs> = { [K in keyof J | keyof OnMethods]: K extends '__selectable' ? SelectableFromShape<J['result'], J['__as']> & Omit<T['__selectable'], keyof T['shape']> : K extends keyof OnMethods ? OnMethods[K] : K extends keyof J ? J[K] : never };
|
|
2773
|
+
type JoinQueryBuilder<T extends PickQuerySelectableShape, J extends PickQuerySelectableResultAs> = { [K in keyof J | keyof OnMethods]: K extends '__selectable' ? SelectableFromShape<J['result'], J['__as']> & Omit<T['__selectable'], keyof T['shape']> : K extends keyof OnMethods ? OnMethods[K] : K extends keyof J ? J[K] : never; };
|
|
2784
2774
|
declare class OnMethods {
|
|
2785
2775
|
/**
|
|
2786
2776
|
* Use `on` to specify columns to join records.
|
|
@@ -2897,10 +2887,10 @@ interface QueryDataSources {
|
|
|
2897
2887
|
}
|
|
2898
2888
|
declare namespace Order {
|
|
2899
2889
|
export interface ArgThis extends PickQuerySelectable, PickQueryResult, PickQueryTsQuery {}
|
|
2900
|
-
export type Arg<T extends ArgThis> = ArgKey<T> | ArgTsQuery<T> | { [K in ArgKey<T> | ArgTsQuery<T>]?: K extends ArgTsQuery<T> ? OrderTsQueryConfig : SortDir } | Expression;
|
|
2890
|
+
export type Arg<T extends ArgThis> = ArgKey<T> | ArgTsQuery<T> | { [K in ArgKey<T> | ArgTsQuery<T>]?: K extends ArgTsQuery<T> ? OrderTsQueryConfig : SortDir; } | Expression;
|
|
2901
2891
|
export type Args<T extends ArgThis> = Arg<T>[];
|
|
2902
2892
|
type ArgTsQuery<T extends ArgThis> = string | undefined extends T['__tsQuery'] ? never : Exclude<T['__tsQuery'], undefined>;
|
|
2903
|
-
type ArgKey<T extends ArgThis> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['__queryType'] extends undefined ? never : K }[keyof T['__selectable']] | { [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K }[keyof T['result']];
|
|
2893
|
+
type ArgKey<T extends ArgThis> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['__queryType'] extends undefined ? never : K; }[keyof T['__selectable']] | { [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K; }[keyof T['result']];
|
|
2904
2894
|
export {};
|
|
2905
2895
|
}
|
|
2906
2896
|
declare class QueryOrder {
|
|
@@ -2961,7 +2951,7 @@ interface WindowArgDeclaration<T extends Order.ArgThis = Order.ArgThis> {
|
|
|
2961
2951
|
order?: Order.Arg<T>;
|
|
2962
2952
|
}
|
|
2963
2953
|
type WindowResult<T, W extends RecordUnknown> = T & {
|
|
2964
|
-
windows: { [K in keyof W]: true };
|
|
2954
|
+
windows: { [K in keyof W]: true; };
|
|
2965
2955
|
};
|
|
2966
2956
|
declare class QueryWindow {
|
|
2967
2957
|
/**
|
|
@@ -3089,9 +3079,9 @@ type SearchArg<T extends PickQuerySelectable, As extends string> = {
|
|
|
3089
3079
|
}) & ({
|
|
3090
3080
|
text: string | Expression;
|
|
3091
3081
|
} | {
|
|
3092
|
-
in: MaybeArray<keyof T['__selectable']> | { [K in keyof T['__selectable']]?: SearchWeight };
|
|
3082
|
+
in: MaybeArray<keyof T['__selectable']> | { [K in keyof T['__selectable']]?: SearchWeight; };
|
|
3093
3083
|
} | {
|
|
3094
|
-
vector: { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['dataType'] extends 'tsvector' ? K : never }[keyof T['__selectable']];
|
|
3084
|
+
vector: { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['dataType'] extends 'tsvector' ? K : never; }[keyof T['__selectable']];
|
|
3095
3085
|
}) & ({
|
|
3096
3086
|
query: string | Expression;
|
|
3097
3087
|
} | {
|
|
@@ -3110,12 +3100,12 @@ declare class SearchMethods {
|
|
|
3110
3100
|
*
|
|
3111
3101
|
* By default, the search language is English.
|
|
3112
3102
|
*
|
|
3113
|
-
* You can set a different default language in the `
|
|
3103
|
+
* You can set a different default language in the `createTableFactory` config:
|
|
3114
3104
|
*
|
|
3115
3105
|
* ```ts
|
|
3116
|
-
* import {
|
|
3106
|
+
* import { createTableFactory } from 'orchid-orm';
|
|
3117
3107
|
*
|
|
3118
|
-
* export const
|
|
3108
|
+
* export const { defineTable, defineView, sql } = createTableFactory({
|
|
3119
3109
|
* language: 'swedish',
|
|
3120
3110
|
* });
|
|
3121
3111
|
* ```
|
|
@@ -3300,7 +3290,7 @@ interface OperatorsCount extends OperatorsNumber {
|
|
|
3300
3290
|
}
|
|
3301
3291
|
type CountColumn = Column.Pick.QueryColumnOfTypeAndOps<'int8', number, OperatorsCount>;
|
|
3302
3292
|
type CountReturn<T> = SetQueryReturnsColumnOrThrow<T, CountColumn> & OperatorsCount;
|
|
3303
|
-
type SelectableDataType<T extends PickQuerySelectable, DataType extends string> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['dataType'] extends DataType ? K : never }[keyof T['__selectable']] | Expression<Column.Pick.QueryColumnOfDataType<DataType>>;
|
|
3293
|
+
type SelectableDataType<T extends PickQuerySelectable, DataType extends string> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['dataType'] extends DataType ? K : never; }[keyof T['__selectable']] | Expression<Column.Pick.QueryColumnOfDataType<DataType>>;
|
|
3304
3294
|
type NumericReturn<T extends PickQuerySelectable, Arg> = Arg extends keyof T['__selectable'] ? SetQueryReturnsColumnOrThrow<T, Column.Pick.QueryColumnOfTypeAndOps<T['__selectable'][Arg]['column']['dataType'], T['__selectable'][Arg]['column']['__type'] | null, OperatorsNumber>> & OperatorsNumber : Arg extends Expression ? SetQueryReturnsColumnOrThrow<T, Column.Pick.QueryColumnOfTypeAndOps<Arg['result']['value']['dataType'], Arg['result']['value']['__type'] | null, OperatorsNumber>> & OperatorsNumber : never;
|
|
3305
3295
|
type NullableNumberReturn<T, DataType> = SetQueryReturnsColumnOrThrow<T, Column.Pick.QueryColumnOfTypeAndOps<DataType, number | null, OperatorsNumber>> & OperatorsNumber;
|
|
3306
3296
|
type BooleanQueryColumn = Column.Pick.QueryColumnOfTypeAndOps<'bool', boolean, OperatorsBoolean>;
|
|
@@ -3318,9 +3308,9 @@ interface RecordSelectableOrExpression<T extends PickQuerySelectable> {
|
|
|
3318
3308
|
}
|
|
3319
3309
|
type NullableJSONObjectReturn<T extends PickQuerySelectable, Obj extends RecordSelectableOrExpression<T>> = SetQueryReturnsColumnOrThrow<T, {
|
|
3320
3310
|
dataType: 'json';
|
|
3321
|
-
__type: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__type'] } | null;
|
|
3322
|
-
__outputType: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__outputType'] } | null;
|
|
3323
|
-
__queryType: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__queryType'] } | null;
|
|
3311
|
+
__type: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__type']; } | null;
|
|
3312
|
+
__outputType: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__outputType']; } | null;
|
|
3313
|
+
__queryType: { [K in keyof Obj]: ExpressionOutput<T, Obj[K]>['__queryType']; } | null;
|
|
3324
3314
|
operators: OperatorsAny;
|
|
3325
3315
|
}> & OperatorsAny;
|
|
3326
3316
|
type StringColumn$1 = Column.Pick.QueryColumnOfTypeAndOps<string, string, OperatorsText>;
|
|
@@ -3329,7 +3319,8 @@ type NullableStringReturn<T> = SetQueryReturnsColumnOrThrow<T, StringNullable> &
|
|
|
3329
3319
|
interface AggregateArgTypes {
|
|
3330
3320
|
minMax: 'citext' | 'date' | 'float4' | 'float8' | 'inet' | 'int2' | 'int4' | 'int8' | 'interval' | 'money' | 'numeric' | 'text' | 'time' | 'timestamp' | 'timestamptz';
|
|
3331
3321
|
sum: 'float4' | 'float8' | 'int2' | 'int4' | 'int8' | 'interval' | 'money' | 'numeric';
|
|
3332
|
-
avg:
|
|
3322
|
+
avg:
|
|
3323
|
+
// unlike sum, avg has no money
|
|
3333
3324
|
'float4' | 'float8' | 'int2' | 'int4' | 'int8' | 'interval' | 'numeric';
|
|
3334
3325
|
bit: 'bit' | 'int2' | 'int4' | 'int8';
|
|
3335
3326
|
bool: 'bool';
|
|
@@ -3747,11 +3738,11 @@ declare class OrExpression extends Expression<BooleanQueryColumn> {
|
|
|
3747
3738
|
interface QueryReturnsFnAdd<T extends PickQueryColumTypes> extends PickQueryHasSelect {
|
|
3748
3739
|
type<C extends Column.Pick.QueryColumn>(fn: (types: T['columnTypes']) => C): { [K in keyof T]: K extends 'result' ? {
|
|
3749
3740
|
value: C;
|
|
3750
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<C['__outputType']> : T[K] } & C['operators'];
|
|
3741
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<C['__outputType']> : T[K]; } & C['operators'];
|
|
3751
3742
|
}
|
|
3752
3743
|
type SetQueryReturnsFn<T extends PickQueryColumTypes, C extends Column.Pick.OutputType> = { [K in keyof T]: K extends 'result' ? {
|
|
3753
3744
|
value: C;
|
|
3754
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<C['__outputType']> : T[K] } & QueryReturnsFnAdd<T>;
|
|
3745
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<C['__outputType']> : T[K]; } & QueryReturnsFnAdd<T>;
|
|
3755
3746
|
declare class QueryExpressions {
|
|
3756
3747
|
/**
|
|
3757
3748
|
* `column` references a table column, this can be used in raw SQL or when building a column expression.
|
|
@@ -3844,7 +3835,7 @@ declare class QueryExpressions {
|
|
|
3844
3835
|
type WhereArg<T extends PickQuerySelectableRelations> = { [K in keyof T['__selectable'] | 'NOT' | 'OR' | 'IN']?: K extends 'NOT' ? WhereArg<T> | WhereArgs<T> : K extends 'OR' ? (WhereArg<T> | WhereArgs<T>)[] : K extends 'IN' ? MaybeArray<{
|
|
3845
3836
|
columns: (keyof T['__selectable'])[];
|
|
3846
3837
|
values: unknown[][] | IsQuery | Expression;
|
|
3847
|
-
}> : T['__selectable'][K]['column']['__queryType'] | null | { [O in keyof T['__selectable'][K]['column']['operators']]?: T['__selectable'][K]['column']['operators'][O]['_opType'] } | {
|
|
3838
|
+
}> : T['__selectable'][K]['column']['__queryType'] | null | { [O in keyof T['__selectable'][K]['column']['operators']]?: T['__selectable'][K]['column']['operators'][O]['_opType']; } | {
|
|
3848
3839
|
result: {
|
|
3849
3840
|
value: {
|
|
3850
3841
|
__queryType: T['__selectable'][K]['column']['__queryType'] | null;
|
|
@@ -3856,7 +3847,7 @@ type WhereArg<T extends PickQuerySelectableRelations> = { [K in keyof T['__selec
|
|
|
3856
3847
|
__queryType: T['__selectable'][K]['column']['__queryType'] | null;
|
|
3857
3848
|
};
|
|
3858
3849
|
};
|
|
3859
|
-
}) } | ((q: WhereQueryBuilder<T>) => QueryOrExpressionBooleanOrNullResult | WhereQueryBuilder<T>);
|
|
3850
|
+
}); } | ((q: WhereQueryBuilder<T>) => QueryOrExpressionBooleanOrNullResult | WhereQueryBuilder<T>);
|
|
3860
3851
|
/**
|
|
3861
3852
|
* Callback argument of `where`.
|
|
3862
3853
|
* It has `where` methods (`where`, `whereNot`, `whereExists`, etc.),
|
|
@@ -3865,16 +3856,16 @@ type WhereArg<T extends PickQuerySelectableRelations> = { [K in keyof T['__selec
|
|
|
3865
3856
|
* db.table.where((q) => q.relation.count().equals(10))
|
|
3866
3857
|
* ```
|
|
3867
3858
|
*/
|
|
3868
|
-
type WhereQueryBuilder<T extends PickQueryRelations> = EmptyObject extends T['relations'] ? { [K in keyof T]: K extends keyof Where | keyof QueryExpressions | 'table' | 'get' | 'columnTypes' | '__selectable' | 'relations' | 'useHelper' | 'modify' | 'result' | 'returnType' | 'withData' | 'windows' | 'then' ? T[K] : never } : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T & (keyof Where | keyof QueryExpressions | 'table' | 'get' | 'columnTypes' | '__selectable' | 'relations' | 'useHelper' | 'modify' | 'result' | 'returnType' | 'withData' | 'windows' | 'then') ? T[K] : never };
|
|
3859
|
+
type WhereQueryBuilder<T extends PickQueryRelations> = EmptyObject extends T['relations'] ? { [K in keyof T]: K extends keyof Where | keyof QueryExpressions | 'table' | 'get' | 'columnTypes' | '__selectable' | 'relations' | 'useHelper' | 'modify' | 'result' | 'returnType' | 'withData' | 'windows' | 'then' ? T[K] : never; } : { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T & (keyof Where | keyof QueryExpressions | 'table' | 'get' | 'columnTypes' | '__selectable' | 'relations' | 'useHelper' | 'modify' | 'result' | 'returnType' | 'withData' | 'windows' | 'then') ? T[K] : never; };
|
|
3869
3860
|
type WhereArgs<T extends PickQuerySelectableRelations> = WhereArg<T>[];
|
|
3870
3861
|
type WhereNotArgs<T extends PickQuerySelectableRelations> = [WhereArg<T>];
|
|
3871
3862
|
type WhereInColumn<T extends PickQuerySelectableRelations> = keyof T['__selectable'] | [keyof T['__selectable'], ...(keyof T['__selectable'])[]];
|
|
3872
|
-
type WhereInValues<T extends PickQuerySelectableRelations, Column> = Column extends keyof T['__selectable'] ? Iterable<T['__selectable'][Column]['column']['__queryType']> | IsQuery | Expression : ({ [I in keyof Column]: Column[I] extends keyof T['__selectable'] ? T['__selectable'][Column[I]]['column']['__queryType'] : never } & {
|
|
3863
|
+
type WhereInValues<T extends PickQuerySelectableRelations, Column> = Column extends keyof T['__selectable'] ? Iterable<T['__selectable'][Column]['column']['__queryType']> | IsQuery | Expression : ({ [I in keyof Column]: Column[I] extends keyof T['__selectable'] ? T['__selectable'][Column[I]]['column']['__queryType'] : never; } & {
|
|
3873
3864
|
length: Column extends {
|
|
3874
3865
|
length: number;
|
|
3875
3866
|
} ? Column['length'] : never;
|
|
3876
3867
|
})[] | IsQuery | Expression;
|
|
3877
|
-
type WhereInArg<T extends PickQuerySelectableRelations> = { [K in keyof T['__selectable']]?: Iterable<T['__selectable'][K]['column']['__queryType']> | IsQuery | Expression };
|
|
3868
|
+
type WhereInArg<T extends PickQuerySelectableRelations> = { [K in keyof T['__selectable']]?: Iterable<T['__selectable'][K]['column']['__queryType']> | IsQuery | Expression; };
|
|
3878
3869
|
interface QueryHasWhere {
|
|
3879
3870
|
__hasWhere: true;
|
|
3880
3871
|
}
|
|
@@ -3900,7 +3891,7 @@ declare class Where {
|
|
|
3900
3891
|
* Constructing `WHERE` conditions:
|
|
3901
3892
|
*
|
|
3902
3893
|
* ```ts
|
|
3903
|
-
* import { sql } from './
|
|
3894
|
+
* import { sql } from './table-factory';
|
|
3904
3895
|
*
|
|
3905
3896
|
* db.table.where({
|
|
3906
3897
|
* // column of the current table
|
|
@@ -3916,7 +3907,7 @@ declare class Where {
|
|
|
3916
3907
|
* },
|
|
3917
3908
|
*
|
|
3918
3909
|
* // where column equals to raw SQL
|
|
3919
|
-
* // import `sql` from your
|
|
3910
|
+
* // import `sql` from your table factory
|
|
3920
3911
|
* column: sql`sql expression`,
|
|
3921
3912
|
* // or use `(q) => sql` for the same
|
|
3922
3913
|
* column2: (q) => sql`sql expression`,
|
|
@@ -4513,7 +4504,7 @@ declare class Where {
|
|
|
4513
4504
|
*/
|
|
4514
4505
|
orWhereNotExists<T extends PickQuerySelectableShapeRelationsWithDataAs, Arg extends JoinFirstArg<T>>(this: T, arg: Arg, ...args: JoinArgs<T, Arg>): T & QueryHasWhere;
|
|
4515
4506
|
}
|
|
4516
|
-
type QueryScopes<Keys extends string> = { [K in Keys]: unknown };
|
|
4507
|
+
type QueryScopes<Keys extends string> = { [K in Keys]: unknown; };
|
|
4517
4508
|
interface ScopeArgumentQuery<Table extends string | undefined, Shape extends Column.QueryColumns> extends Where, PickQuerySelectableShapeRelationsWithData {
|
|
4518
4509
|
__isQuery: true;
|
|
4519
4510
|
table: Table;
|
|
@@ -4526,21 +4517,16 @@ interface ScopeArgumentQuery<Table extends string | undefined, Shape extends Col
|
|
|
4526
4517
|
* If you define a scope with name `default`, it will be applied for all table queries by default.
|
|
4527
4518
|
*
|
|
4528
4519
|
* ```ts
|
|
4529
|
-
* import {
|
|
4530
|
-
*
|
|
4531
|
-
* export class SomeTable extends BaseTable {
|
|
4532
|
-
* readonly table = 'some';
|
|
4533
|
-
* columns = this.setColumns((t) => ({
|
|
4534
|
-
* id: t.identity().primaryKey(),
|
|
4535
|
-
* hidden: t.boolean(),
|
|
4536
|
-
* active: t.boolean(),
|
|
4537
|
-
* }));
|
|
4520
|
+
* import { defineTable } from './table-factory';
|
|
4538
4521
|
*
|
|
4539
|
-
*
|
|
4540
|
-
*
|
|
4541
|
-
*
|
|
4542
|
-
*
|
|
4543
|
-
* }
|
|
4522
|
+
* export const SomeTable = defineTable('some', (t) => ({
|
|
4523
|
+
* id: t.identity().primaryKey(),
|
|
4524
|
+
* hidden: t.boolean(),
|
|
4525
|
+
* active: t.boolean(),
|
|
4526
|
+
* })).scopes({
|
|
4527
|
+
* default: (q) => q.where({ hidden: false }),
|
|
4528
|
+
* active: (q) => q.where({ active: true }),
|
|
4529
|
+
* });
|
|
4544
4530
|
*
|
|
4545
4531
|
* const db = orchidORM(
|
|
4546
4532
|
* { databaseURL: '...' },
|
|
@@ -4660,20 +4646,20 @@ interface NonDeletedScope {
|
|
|
4660
4646
|
* All queries on such table will filter out deleted records by default.
|
|
4661
4647
|
*
|
|
4662
4648
|
* ```ts
|
|
4663
|
-
* import {
|
|
4664
|
-
*
|
|
4665
|
-
* export class SomeTable extends BaseTable {
|
|
4666
|
-
* readonly table = 'some';
|
|
4667
|
-
* columns = this.setColumns((t) => ({
|
|
4668
|
-
* id: t.identity().primaryKey(),
|
|
4669
|
-
* deletedAt: t.timestamp().nullable(),
|
|
4670
|
-
* }));
|
|
4649
|
+
* import { defineTable } from './table-factory';
|
|
4671
4650
|
*
|
|
4651
|
+
* export const SomeTable = defineTable('some', (t) => ({
|
|
4652
|
+
* id: t.identity().primaryKey(),
|
|
4653
|
+
* deletedAt: t.timestamp().nullable(),
|
|
4654
|
+
* }))
|
|
4672
4655
|
* // true is for using `deletedAt` column
|
|
4673
|
-
*
|
|
4674
|
-
*
|
|
4675
|
-
*
|
|
4676
|
-
*
|
|
4656
|
+
* .softDelete();
|
|
4657
|
+
*
|
|
4658
|
+
* // or provide a different column name
|
|
4659
|
+
* export const OtherTable = defineTable('other', (t) => ({
|
|
4660
|
+
* id: t.identity().primaryKey(),
|
|
4661
|
+
* myDeletedAt: t.timestamp().nullable(),
|
|
4662
|
+
* })).softDelete('myDeletedAt');
|
|
4677
4663
|
*
|
|
4678
4664
|
* const db = orchidORM(
|
|
4679
4665
|
* { databaseURL: '...' },
|
|
@@ -4733,9 +4719,11 @@ declare namespace RlsPolicy {
|
|
|
4733
4719
|
export {};
|
|
4734
4720
|
}
|
|
4735
4721
|
declare namespace Rls {
|
|
4736
|
-
interface
|
|
4722
|
+
interface TableConfigBase {
|
|
4737
4723
|
enable?: boolean;
|
|
4738
4724
|
force?: boolean;
|
|
4725
|
+
}
|
|
4726
|
+
interface TableConfig extends TableConfigBase {
|
|
4739
4727
|
permit: [RlsPolicy.Policy, ...RlsPolicy.Policy[]];
|
|
4740
4728
|
restrict?: RlsPolicy.Policy[];
|
|
4741
4729
|
}
|
|
@@ -4801,14 +4789,14 @@ declare namespace DefaultPrivileges {
|
|
|
4801
4789
|
export {};
|
|
4802
4790
|
}
|
|
4803
4791
|
declare const DEFAULT_PRIVILEGE: {
|
|
4804
|
-
OBJECT_TYPES: readonly [
|
|
4792
|
+
OBJECT_TYPES: readonly ['TABLES', 'SEQUENCES', 'FUNCTIONS', 'TYPES', 'SCHEMAS', 'LARGE_OBJECTS'];
|
|
4805
4793
|
PRIVILEGES: {
|
|
4806
|
-
TABLE: readonly [
|
|
4807
|
-
SEQUENCE: readonly [
|
|
4808
|
-
FUNCTION: readonly [
|
|
4809
|
-
TYPE: readonly [
|
|
4810
|
-
SCHEMA: readonly [
|
|
4811
|
-
LARGE_OBJECT: readonly [
|
|
4794
|
+
TABLE: readonly ['ALL', 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER', 'MAINTAIN'];
|
|
4795
|
+
SEQUENCE: readonly ['ALL', 'USAGE', 'SELECT', 'UPDATE'];
|
|
4796
|
+
FUNCTION: readonly ['ALL', 'EXECUTE'];
|
|
4797
|
+
TYPE: readonly ['ALL', 'USAGE'];
|
|
4798
|
+
SCHEMA: readonly ['ALL', 'USAGE', 'CREATE'];
|
|
4799
|
+
LARGE_OBJECT: readonly ['ALL', 'SELECT', 'UPDATE'];
|
|
4812
4800
|
};
|
|
4813
4801
|
};
|
|
4814
4802
|
declare function getSupportedDefaultPrivileges(version: number): DefaultPrivileges.SupportedDefaultPrivileges;
|
|
@@ -4987,10 +4975,10 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4987
4975
|
*/
|
|
4988
4976
|
nestedCreateBatchMax: number;
|
|
4989
4977
|
}
|
|
4990
|
-
type ShapeHasPrimaryKeys<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? K : never }[keyof Shape];
|
|
4991
|
-
type TablePrimaryKeys<Shape extends Column.QueryColumnsInit> = ShapeHasPrimaryKeys<Shape> extends never ? never : { [K in ShapeHasPrimaryKeys<Shape>]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']
|
|
4992
|
-
type ShapeUniqueColumns<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? { [C in K]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']
|
|
4993
|
-
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];
|
|
4978
|
+
type ShapeHasPrimaryKeys<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? K : never; }[keyof Shape];
|
|
4979
|
+
type TablePrimaryKeys<Shape extends Column.QueryColumnsInit> = ShapeHasPrimaryKeys<Shape> extends never ? never : { [K in ShapeHasPrimaryKeys<Shape>]: UniqueQueryTypeOrExpression<Shape[K]['__queryType']>; };
|
|
4980
|
+
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];
|
|
4981
|
+
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];
|
|
4994
4982
|
type NoPrimaryKeyOption = 'error' | 'warning' | 'ignore';
|
|
4995
4983
|
interface DbSharedOptions extends QueryLogOptions {
|
|
4996
4984
|
autoPreparedStatements?: boolean;
|
|
@@ -5077,7 +5065,7 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
5077
5065
|
*/
|
|
5078
5066
|
nowSQL?: string;
|
|
5079
5067
|
}
|
|
5080
|
-
type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.QueryColumns, Keys extends string = string> = { [K in Keys]: (q: ScopeArgumentQuery<Table, Shape>) => IsQuery };
|
|
5068
|
+
type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.QueryColumns, Keys extends string = string> = { [K in Keys]: (q: ScopeArgumentQuery<Table, Shape>) => IsQuery; };
|
|
5081
5069
|
interface QueryBuilder extends Query.NotReadOnlyQuery {
|
|
5082
5070
|
returnType: undefined;
|
|
5083
5071
|
}
|
|
@@ -5096,14 +5084,14 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5096
5084
|
} ? true : undefined;
|
|
5097
5085
|
__hasSelect: boolean;
|
|
5098
5086
|
__hasWhere: boolean;
|
|
5099
|
-
__defaults: { [K in { [K in keyof Shape]: Shape[K]['data']['default'] extends true ? K : never }[keyof Shape]]: true };
|
|
5100
|
-
__scopes: { [K in keyof MapTableScopesOption<Options>]: true };
|
|
5087
|
+
__defaults: { [K in { [K in keyof Shape]: Shape[K]['data']['default'] extends true ? K : never; }[keyof Shape]]: true; };
|
|
5088
|
+
__scopes: { [K in keyof MapTableScopesOption<Options>]: true; };
|
|
5101
5089
|
__defaultSelect: ColumnsShape.DefaultSelectKeys<Shape>;
|
|
5102
5090
|
baseQuery: Query;
|
|
5103
5091
|
columns: (keyof Shape)[];
|
|
5104
5092
|
__outputType: ColumnsShape.DefaultSelectOutput<Shape>;
|
|
5105
5093
|
__inputType: ColumnsShape.Input<Shape>;
|
|
5106
|
-
result: { [K in ColumnsShape.DefaultSelectKeys<Shape>]: Shape[K] };
|
|
5094
|
+
result: { [K in ColumnsShape.DefaultSelectKeys<Shape>]: Shape[K]; };
|
|
5107
5095
|
returnType: undefined;
|
|
5108
5096
|
then: QueryThenShallowSimplifyArr<ColumnsShape.DefaultOutput<Shape>>;
|
|
5109
5097
|
windows: EmptyObject;
|
|
@@ -5113,7 +5101,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5113
5101
|
relationQueries: EmptyObject;
|
|
5114
5102
|
withData: EmptyObject;
|
|
5115
5103
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
|
|
5116
|
-
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>>;
|
|
5104
|
+
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>>;
|
|
5117
5105
|
catch: QueryCatch;
|
|
5118
5106
|
shape: ComputedColumnsFromOptions<Shape, Options>;
|
|
5119
5107
|
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']);
|
|
@@ -5287,15 +5275,7 @@ interface DbResult<ColumnTypes> extends Db<undefined, EmptyObject, never, Column
|
|
|
5287
5275
|
* })
|
|
5288
5276
|
* ```
|
|
5289
5277
|
*/
|
|
5290
|
-
declare const createDbWithAdapter: <SchemaConfig extends ColumnSchemaConfig = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({
|
|
5291
|
-
log,
|
|
5292
|
-
logger,
|
|
5293
|
-
snakeCase,
|
|
5294
|
-
schemaConfig: schemaConfigFn,
|
|
5295
|
-
columnTypes,
|
|
5296
|
-
schema,
|
|
5297
|
-
...options
|
|
5298
|
-
}: DbOptionsWithAdapter<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
5278
|
+
declare const createDbWithAdapter: <SchemaConfig extends ColumnSchemaConfig = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase, schemaConfig: schemaConfigFn, columnTypes, schema, ...options }: DbOptionsWithAdapter<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
5299
5279
|
declare function _createDbSqlMethod<ColumnTypes>(columnTypes: ColumnTypes): DbSqlMethod<ColumnTypes>;
|
|
5300
5280
|
declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, asyncStorage: AsyncLocalStorage<AsyncState>, commonOptions: DbTableOptions<unknown, undefined, Column.QueryColumns>, options: DbSharedOptions) => Db;
|
|
5301
5281
|
type SQLQueryArgs = TemplateLiteralArgs | [RawSqlBase];
|
|
@@ -5379,7 +5359,12 @@ declare class RawSql<T extends Column.Pick.QueryColumn = Column.Pick.QueryColumn
|
|
|
5379
5359
|
makeSQL(ctx: ToSqlValues, quotedAs?: string): string;
|
|
5380
5360
|
}
|
|
5381
5361
|
declare const isRawSQL: (arg: unknown) => arg is RawSqlBase;
|
|
5382
|
-
|
|
5362
|
+
interface RawSqlToCodeCtx {
|
|
5363
|
+
t: string;
|
|
5364
|
+
sql?: string;
|
|
5365
|
+
isSqlUsed?: boolean;
|
|
5366
|
+
}
|
|
5367
|
+
declare const rawSqlToCode: (rawSql: RawSqlBase, ctx: string | RawSqlToCodeCtx) => string;
|
|
5383
5368
|
interface DynamicRawSQL<T extends Column.Pick.QueryColumn> extends Expression<T>, ExpressionTypeMethod {}
|
|
5384
5369
|
declare class DynamicRawSQL<T extends Column.Pick.QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends Expression<T> {
|
|
5385
5370
|
fn: DynamicSQLArg<T>;
|
|
@@ -5501,14 +5486,14 @@ declare const rawSqlToSql: (sql: string | RawSqlBase) => SingleSql;
|
|
|
5501
5486
|
declare const sqlToRawSql: (sql: SingleSql) => RawSqlBase;
|
|
5502
5487
|
declare class QuerySql<ColumnTypes> {
|
|
5503
5488
|
/**
|
|
5504
|
-
* @deprecated: use `sql` exported from the
|
|
5489
|
+
* @deprecated: use `sql` exported from the table factory file.
|
|
5505
5490
|
*
|
|
5506
|
-
* When there is a need to use a piece of raw SQL, use the `sql` exported from the
|
|
5491
|
+
* When there is a need to use a piece of raw SQL, use the `sql` exported from the table factory file, it is also attached to query objects for convenience.
|
|
5507
5492
|
*
|
|
5508
5493
|
* When selecting a custom SQL, specify a resulting type with `<generic>` syntax:
|
|
5509
5494
|
*
|
|
5510
5495
|
* ```ts
|
|
5511
|
-
* import { sql } from './
|
|
5496
|
+
* import { sql } from './table-factory';
|
|
5512
5497
|
*
|
|
5513
5498
|
* const result: { num: number }[] = await db.table.select({
|
|
5514
5499
|
* num: sql<number>`random() * 100`,
|
|
@@ -5520,7 +5505,7 @@ declare class QuerySql<ColumnTypes> {
|
|
|
5520
5505
|
* This example assumes that the `timestamp` column was overridden with `asDate` as shown in [Override column types](/guide/columns-overview#override-column-types).
|
|
5521
5506
|
*
|
|
5522
5507
|
* ```ts
|
|
5523
|
-
* import { sql } from './
|
|
5508
|
+
* import { sql } from './table-factory';
|
|
5524
5509
|
*
|
|
5525
5510
|
* const result: { timestamp: Date }[] = await db.table.select({
|
|
5526
5511
|
* timestamp: sql`now()`.type((t) => t.timestamp()),
|
|
@@ -5670,7 +5655,7 @@ interface TopCTE {
|
|
|
5670
5655
|
append: string[][];
|
|
5671
5656
|
}
|
|
5672
5657
|
declare const addTopCteSql: (ctx: ToSQLCtx, as: string | undefined, sql: string) => string;
|
|
5673
|
-
declare const addTopCte: (place:
|
|
5658
|
+
declare const addTopCte: (place: 'before' | 'after', ctx: ToSQLCtx, q: SubQueryForSql, type: QueryData['type'], as?: string | ((as: string) => void), dontAddTableHook?: boolean) => string;
|
|
5674
5659
|
/**
|
|
5675
5660
|
* Function to turn the operator expression into SQL.
|
|
5676
5661
|
*
|
|
@@ -5685,7 +5670,7 @@ interface OperatorToSQL {
|
|
|
5685
5670
|
interface Operator<Value, Column extends Column.Pick.OutputTypeAndOperators = Column.Pick.OutputTypeAndOperators> {
|
|
5686
5671
|
<T extends PickQueryResult>(this: T, arg: Value): { [K in Exclude<keyof T, keyof T['result']['value']['operators']>]: K extends 'result' ? {
|
|
5687
5672
|
value: Column;
|
|
5688
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['__outputType']> : T[K] } & Column['operators'];
|
|
5673
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['__outputType']> : T[K]; } & Column['operators'];
|
|
5689
5674
|
_opType: Value;
|
|
5690
5675
|
}
|
|
5691
5676
|
interface Base$1<Value> {
|
|
@@ -5905,7 +5890,7 @@ interface OperatorsArray<T> extends Ord<T[]> {
|
|
|
5905
5890
|
hasSome: Operator<T[] | IsQuery | Expression, BooleanQueryColumn>;
|
|
5906
5891
|
containedIn: Operator<T[] | IsQuery | Expression, BooleanQueryColumn>;
|
|
5907
5892
|
length: {
|
|
5908
|
-
_opType: number | { [K in Exclude<keyof OperatorsNumber, '__hasSelect'>]?: OperatorsNumber[K]['_opType'] };
|
|
5893
|
+
_opType: number | { [K in Exclude<keyof OperatorsNumber, '__hasSelect'>]?: OperatorsNumber[K]['_opType']; };
|
|
5909
5894
|
};
|
|
5910
5895
|
}
|
|
5911
5896
|
declare const Operators: {
|
|
@@ -5923,24 +5908,24 @@ interface ColumnsShape {
|
|
|
5923
5908
|
[K: string]: Column;
|
|
5924
5909
|
}
|
|
5925
5910
|
declare namespace ColumnsShape {
|
|
5926
|
-
export type DefaultSelectKeys<S extends Column.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K }[keyof S];
|
|
5927
|
-
export type DefaultOutput<Set extends Column.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType'] };
|
|
5928
|
-
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'] };
|
|
5929
|
-
export type InputPartial<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType'] };
|
|
5930
|
-
export type Output<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5931
|
-
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'] };
|
|
5911
|
+
export type DefaultSelectKeys<S extends Column.QueryColumnsInit> = { [K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K; }[keyof S];
|
|
5912
|
+
export type DefaultOutput<Set extends Column.QueryColumnsInit> = { [K in DefaultSelectKeys<Set>]: Set[K]['__outputType']; };
|
|
5913
|
+
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']; };
|
|
5914
|
+
export type InputPartial<Shape extends Column.QueryColumnsInit> = { [K in keyof Shape]?: Shape[K]['__inputType']; };
|
|
5915
|
+
export type Output<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType']; };
|
|
5916
|
+
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']; };
|
|
5932
5917
|
export interface MapToObjectColumn<Shape extends Column.QueryColumns> {
|
|
5933
5918
|
dataType: 'object';
|
|
5934
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5919
|
+
__type: { [K in keyof Shape]: Shape[K]['__type']; };
|
|
5935
5920
|
__outputType: ShallowSimplify<ObjectOutput<Shape>>;
|
|
5936
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] };
|
|
5921
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType']; };
|
|
5937
5922
|
operators: OperatorsAny;
|
|
5938
5923
|
}
|
|
5939
5924
|
export interface MapToNullableObjectColumn<Shape extends Column.QueryColumns> {
|
|
5940
5925
|
dataType: 'object';
|
|
5941
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] };
|
|
5926
|
+
__type: { [K in keyof Shape]: Shape[K]['__type']; };
|
|
5942
5927
|
__outputType: ShallowSimplify<ObjectOutput<Shape>> | undefined;
|
|
5943
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] } | null;
|
|
5928
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType']; } | null;
|
|
5944
5929
|
operators: OperatorsAny;
|
|
5945
5930
|
}
|
|
5946
5931
|
export interface MapToPluckColumn<Shape extends Column.QueryColumns> {
|
|
@@ -5952,12 +5937,12 @@ declare namespace ColumnsShape {
|
|
|
5952
5937
|
}
|
|
5953
5938
|
export interface MapToObjectArrayColumn<Shape extends Column.QueryColumns> {
|
|
5954
5939
|
dataType: 'array';
|
|
5955
|
-
__type: { [K in keyof Shape]: Shape[K]['__type'] }[];
|
|
5940
|
+
__type: { [K in keyof Shape]: Shape[K]['__type']; }[];
|
|
5956
5941
|
__outputType: ShallowSimplify<ObjectOutput<Shape>>[];
|
|
5957
|
-
__queryType: { [K in keyof Shape]: Shape[K]['__queryType'] }[];
|
|
5942
|
+
__queryType: { [K in keyof Shape]: Shape[K]['__queryType']; }[];
|
|
5958
5943
|
operators: OperatorsAny;
|
|
5959
5944
|
}
|
|
5960
|
-
type ObjectOutput<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType'] };
|
|
5945
|
+
type ObjectOutput<Shape extends Column.QueryColumns> = { [K in keyof Shape]: Shape[K]['__outputType']; };
|
|
5961
5946
|
export {};
|
|
5962
5947
|
}
|
|
5963
5948
|
interface SelectSelf extends PickQuerySelectable, PickQueryHasSelect, PickQueryDefaultSelect, PickQueryShape, PickQueryRelations, PickQueryResult, PickQueryReturnType, PickQueryWithData {}
|
|
@@ -5965,7 +5950,7 @@ type SelectArgs<T extends SelectSelf> = ('*' | keyof T['__selectable'])[];
|
|
|
5965
5950
|
interface SubQueryAddition<T extends PickQueryWithData> extends IsSubQuery {
|
|
5966
5951
|
withData: T['withData'];
|
|
5967
5952
|
}
|
|
5968
|
-
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 };
|
|
5953
|
+
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; };
|
|
5969
5954
|
interface SelectAsArg<T extends SelectSelf> {
|
|
5970
5955
|
[K: string]: keyof T['__selectable'] | Expression | ((q: SelectAsFnArg<T>) => unknown);
|
|
5971
5956
|
}
|
|
@@ -5977,10 +5962,10 @@ interface SelectAsCheckReturnTypes {
|
|
|
5977
5962
|
[K: string]: PropertyKey | Expression | ((q: never) => SelectAsFnReturnType);
|
|
5978
5963
|
}
|
|
5979
5964
|
type SelectReturnType<T extends PickQueryReturnType> = T['returnType'] extends 'valueOrThrow' ? 'oneOrThrow' : T extends 'value' ? 'one' : T['returnType'] extends 'pluck' ? 'all' : T['returnType'];
|
|
5980
|
-
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] };
|
|
5981
|
-
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}`;
|
|
5982
|
-
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'
|
|
5983
|
-
{ [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] };
|
|
5965
|
+
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]; };
|
|
5966
|
+
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}`;
|
|
5967
|
+
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,
|
|
5968
|
+
? { [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]; };
|
|
5984
5969
|
interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
5985
5970
|
result: Column.QueryColumns;
|
|
5986
5971
|
returnType: 'value' | 'valueOrThrow' | 'one' | 'oneOrThrow';
|
|
@@ -5988,7 +5973,7 @@ interface AllowedRelationOneQueryForSelectable extends IsSubQuery {
|
|
|
5988
5973
|
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}`]: {
|
|
5989
5974
|
as: C;
|
|
5990
5975
|
column: R['returnType'] extends 'value' | 'valueOrThrow' ? R['result']['value'] : R['result'][C & keyof R['result']];
|
|
5991
|
-
} } : never }[keyof Obj]>;
|
|
5976
|
+
}; } : never; }[keyof Obj]>;
|
|
5992
5977
|
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;
|
|
5993
5978
|
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']>;
|
|
5994
5979
|
declare function _querySelect<T extends SelectSelf, Columns extends SelectArgs<T>>(q: T, columns: Columns): SelectResult<T, Columns>;
|
|
@@ -6094,15 +6079,6 @@ type QueryDataTransform = QueryDataTransformFn | {
|
|
|
6094
6079
|
interface QueryDataTransformFn {
|
|
6095
6080
|
(data: unknown, queryData: unknown): unknown;
|
|
6096
6081
|
}
|
|
6097
|
-
/**
|
|
6098
|
-
* See `transform` query method.
|
|
6099
|
-
* This helper applies all transform functions to a result.
|
|
6100
|
-
*
|
|
6101
|
-
* @param queryData - query data
|
|
6102
|
-
* @param returnType - return type of the query, for proper `map` handling
|
|
6103
|
-
* @param fns - array of transform functions, can be undefined
|
|
6104
|
-
* @param result - query result to transform
|
|
6105
|
-
*/
|
|
6106
6082
|
declare class QueryTransform {
|
|
6107
6083
|
/**
|
|
6108
6084
|
* Transform the result of the query right after loading it.
|
|
@@ -6161,7 +6137,7 @@ declare class QueryTransform {
|
|
|
6161
6137
|
then: QueryThen<infer Data>;
|
|
6162
6138
|
} ? Data : never, queryData: QueryData) => Result): { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
6163
6139
|
value: Column.Pick.QueryColumnOfType<Result>;
|
|
6164
|
-
} : K extends 'then' ? QueryThen<Result> : T[K] };
|
|
6140
|
+
} : K extends 'then' ? QueryThen<Result> : T[K]; };
|
|
6165
6141
|
}
|
|
6166
6142
|
type SelectableOrExpression<T extends PickQuerySelectable = PickQuerySelectable, C extends Column.Pick.QueryColumn = Column.Pick.QueryColumn> = '*' | keyof T['__selectable'] | Expression<C>;
|
|
6167
6143
|
type SelectableOrExpressions<T extends PickQuerySelectable = PickQuerySelectable, C extends Column.Pick.QueryColumn = Column.Pick.QueryColumn> = ('*' | keyof T['__selectable'] | Expression<C>)[];
|
|
@@ -6219,7 +6195,8 @@ declare abstract class ExpressionTypeMethod {
|
|
|
6219
6195
|
expr?: Expression;
|
|
6220
6196
|
};
|
|
6221
6197
|
columnTypes: unknown;
|
|
6222
|
-
}, C extends Column.Pick.QueryColumn>(this: T, fn: (types: T['columnTypes']) => C):
|
|
6198
|
+
}, C extends Column.Pick.QueryColumn>(this: T, fn: (types: T['columnTypes']) => C):
|
|
6199
|
+
// Omit is optimal
|
|
6223
6200
|
Omit<T, 'result'> & {
|
|
6224
6201
|
result: {
|
|
6225
6202
|
value: C;
|
|
@@ -6297,24 +6274,19 @@ type AfterCommitErrorResult = AfterCommitErrorFulfilledResult | AfterCommitError
|
|
|
6297
6274
|
* so later they can be identified when handling after commit errors.
|
|
6298
6275
|
*
|
|
6299
6276
|
* ```ts
|
|
6300
|
-
*
|
|
6301
|
-
*
|
|
6302
|
-
*
|
|
6303
|
-
*
|
|
6304
|
-
*
|
|
6305
|
-
*
|
|
6306
|
-
*
|
|
6307
|
-
* // anonymous funciton - has no name
|
|
6308
|
-
* this.afterCreateCommit([], async () => {
|
|
6309
|
-
* // ...
|
|
6310
|
-
* });
|
|
6277
|
+
* export const SomeTable = defineTable('someTable', (t) => ({
|
|
6278
|
+
* ...someColumns,
|
|
6279
|
+
* })).init((orm: typeof db, hooks) => {
|
|
6280
|
+
* // anonymous funciton - has no name
|
|
6281
|
+
* hooks.afterCreateCommit([], async () => {
|
|
6282
|
+
* // ...
|
|
6283
|
+
* });
|
|
6311
6284
|
*
|
|
6312
|
-
*
|
|
6313
|
-
*
|
|
6314
|
-
*
|
|
6315
|
-
*
|
|
6316
|
-
*
|
|
6317
|
-
* }
|
|
6285
|
+
* // named function
|
|
6286
|
+
* hooks.afterCreateCommit([], function myHook() {
|
|
6287
|
+
* // ...
|
|
6288
|
+
* });
|
|
6289
|
+
* });
|
|
6318
6290
|
* ```
|
|
6319
6291
|
*/
|
|
6320
6292
|
declare class AfterCommitError extends OrchidOrmError {
|
|
@@ -6553,7 +6525,7 @@ declare class QueryTransaction {
|
|
|
6553
6525
|
*/
|
|
6554
6526
|
recoverable<T>(this: T): T;
|
|
6555
6527
|
}
|
|
6556
|
-
type AfterHook<Select extends PropertyKey[], Shape extends Column.QueryColumns> = QueryAfterHook<{ [K in Select[number]]: K extends keyof Shape ? Shape[K]['__outputType'] : never }[]>;
|
|
6528
|
+
type AfterHook<Select extends PropertyKey[], Shape extends Column.QueryColumns> = QueryAfterHook<{ [K in Select[number]]: K extends keyof Shape ? Shape[K]['__outputType'] : never; }[]>;
|
|
6557
6529
|
type HookSelectArg<T extends PickQueryShape> = (keyof T['shape'] & string)[];
|
|
6558
6530
|
declare const _hookSelectColumns: (query: Query, columns: string[], asFn: (as: string[]) => void) => void;
|
|
6559
6531
|
declare class QueryHookUtils<T extends PickQueryInputType> {
|
|
@@ -6561,10 +6533,10 @@ declare class QueryHookUtils<T extends PickQueryInputType> {
|
|
|
6561
6533
|
columns: string[];
|
|
6562
6534
|
private key;
|
|
6563
6535
|
constructor(query: IsQuery, columns: string[], key: 'hookCreateSet' | 'hookUpdateSet');
|
|
6564
|
-
set: (data: { [K in keyof T[
|
|
6536
|
+
set: (data: { [K in keyof T['__inputType']]?: T['__inputType'][K] | (() => QueryOrExpression<T['__inputType'][K]>); }) => void;
|
|
6565
6537
|
}
|
|
6566
|
-
declare const _queryHookAfterCreate:
|
|
6567
|
-
declare const _queryHookAfterUpdate:
|
|
6538
|
+
declare const _queryHookAfterCreate: (q: PickQueryShape, select: HookSelectArg<PickQueryShape>, cb: AfterHook<HookSelectArg<PickQueryShape>, Column.QueryColumns>) => PickQueryShape;
|
|
6539
|
+
declare const _queryHookAfterUpdate: (q: PickQueryShape, select: HookSelectArg<PickQueryShape>, cb: AfterHook<HookSelectArg<PickQueryShape>, PickQueryShape['shape']>) => PickQueryShape;
|
|
6568
6540
|
declare abstract class QueryHooks {
|
|
6569
6541
|
/**
|
|
6570
6542
|
* Run the function before any kind of query.
|
|
@@ -6714,47 +6686,44 @@ interface ColumnDataSelectSqlProp {
|
|
|
6714
6686
|
interface SelectSqlCallback {
|
|
6715
6687
|
(column: ColumnRefExpression<Column.Pick.QueryColumn>): Expression;
|
|
6716
6688
|
}
|
|
6717
|
-
type SelectSqlColumn<T extends Column.Pick.DataAndDataType, Expr extends Expression> = unknown extends Expr['result']['value']['__outputType'] ? T : { [K in keyof T]: K extends '__outputType' ? Expr['result']['value']['__outputType'] : T[K] };
|
|
6689
|
+
type SelectSqlColumn<T extends Column.Pick.DataAndDataType, Expr extends Expression> = unknown extends Expr['result']['value']['__outputType'] ? T : { [K in keyof T]: K extends '__outputType' ? Expr['result']['value']['__outputType'] : T[K]; };
|
|
6718
6690
|
declare namespace Column {
|
|
6719
|
-
export
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
primaryKey: Name;
|
|
6723
|
-
};
|
|
6724
|
-
}
|
|
6725
|
-
export type IsUnique<Name extends string> = {
|
|
6726
|
-
data: {
|
|
6727
|
-
unique: Name;
|
|
6728
|
-
};
|
|
6691
|
+
export interface IsPrimaryKey<Name extends string> {
|
|
6692
|
+
data: {
|
|
6693
|
+
primaryKey: Name;
|
|
6729
6694
|
};
|
|
6730
|
-
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] };
|
|
6731
|
-
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] };
|
|
6732
|
-
export type QueryColumnToNullable<C> = { [K in keyof C]: K extends '__outputType' | '__queryType' ? C[K] | null : C[K] };
|
|
6733
|
-
export type QueryColumnToOptional<C> = { [K in keyof C]: K extends '__outputType' ? C[K] | undefined : C[K] };
|
|
6734
|
-
interface DataNullable {
|
|
6735
|
-
isNullable: true;
|
|
6736
|
-
optional: true;
|
|
6737
|
-
}
|
|
6738
|
-
export interface OperatorsNullable<Column extends Column.Pick.QueryColumn> {
|
|
6739
|
-
equals: Operator<Column['__queryType'] | null, Column>;
|
|
6740
|
-
not: Operator<Column['__queryType'] | null, Column>;
|
|
6741
|
-
isDistinctFrom: Operator<Column['__queryType'] | null, Column>;
|
|
6742
|
-
isNotDistinctFrom: Operator<Column['__queryType'] | null, Column>;
|
|
6743
|
-
}
|
|
6744
|
-
export type Encode<T, InputSchema, Input> = { [K in keyof T]: K extends '__inputType' ? Input : K extends 'inputSchema' ? InputSchema : T[K] };
|
|
6745
|
-
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] };
|
|
6746
|
-
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] };
|
|
6747
|
-
export type HasDefault<T extends Column.Pick.Data> = T & Column.Data.Default;
|
|
6748
|
-
type DefaultSelectData<T extends Column.Data, Value> = { [K in keyof T]: K extends 'explicitSelect' ? Value extends true ? false : true : T[K] };
|
|
6749
|
-
export type DefaultSelect<T extends Column.Pick.Data, Value extends boolean> = { [K in keyof T]: K extends 'data' ? DefaultSelectData<T['data'], Value> : T[K] };
|
|
6750
|
-
export interface IsAppReadOnly {
|
|
6751
|
-
data: {
|
|
6752
|
-
appReadOnly: true;
|
|
6753
|
-
};
|
|
6754
|
-
}
|
|
6755
|
-
export type Generated<T extends Column.Pick.Data> = { [K in keyof T]: K extends 'data' ? { [K in keyof T['data']]: K extends 'default' ? true : T['data'][K] } : K extends '__inputType' ? never : T[K] };
|
|
6756
|
-
export {};
|
|
6757
6695
|
}
|
|
6696
|
+
export type IsUnique<Name extends string> = {
|
|
6697
|
+
data: {
|
|
6698
|
+
unique: Name;
|
|
6699
|
+
};
|
|
6700
|
+
};
|
|
6701
|
+
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]; };
|
|
6702
|
+
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]; };
|
|
6703
|
+
export type QueryColumnToNullable<C> = { [K in keyof C]: K extends '__outputType' | '__queryType' ? C[K] | null : C[K]; };
|
|
6704
|
+
export type QueryColumnToOptional<C> = { [K in keyof C]: K extends '__outputType' ? C[K] | undefined : C[K]; };
|
|
6705
|
+
interface DataNullable {
|
|
6706
|
+
isNullable: true;
|
|
6707
|
+
optional: true;
|
|
6708
|
+
}
|
|
6709
|
+
export interface OperatorsNullable<Column extends Column.Pick.QueryColumn> {
|
|
6710
|
+
equals: Operator<Column['__queryType'] | null, Column>;
|
|
6711
|
+
not: Operator<Column['__queryType'] | null, Column>;
|
|
6712
|
+
isDistinctFrom: Operator<Column['__queryType'] | null, Column>;
|
|
6713
|
+
isNotDistinctFrom: Operator<Column['__queryType'] | null, Column>;
|
|
6714
|
+
}
|
|
6715
|
+
export type Encode<T, InputSchema, Input> = { [K in keyof T]: K extends '__inputType' ? Input : K extends 'inputSchema' ? InputSchema : T[K]; };
|
|
6716
|
+
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]; };
|
|
6717
|
+
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]; };
|
|
6718
|
+
export type HasDefault<T extends Column.Pick.Data> = T & Column.Data.Default;
|
|
6719
|
+
type DefaultSelectData<T extends Column.Data, Value> = { [K in keyof T]: K extends 'explicitSelect' ? Value extends true ? false : true : T[K]; };
|
|
6720
|
+
export type DefaultSelect<T extends Column.Pick.Data, Value extends boolean> = { [K in keyof T]: K extends 'data' ? DefaultSelectData<T['data'], Value> : T[K]; };
|
|
6721
|
+
export interface IsAppReadOnly {
|
|
6722
|
+
data: {
|
|
6723
|
+
appReadOnly: true;
|
|
6724
|
+
};
|
|
6725
|
+
}
|
|
6726
|
+
export type Generated<T extends Column.Pick.Data> = { [K in keyof T]: K extends 'data' ? { [K in keyof T['data']]: K extends 'default' ? true : T['data'][K]; } : K extends '__inputType' ? never : T[K]; };
|
|
6758
6727
|
export namespace Pick {
|
|
6759
6728
|
interface Data {
|
|
6760
6729
|
data: Column.Data;
|
|
@@ -6845,12 +6814,39 @@ declare namespace Column {
|
|
|
6845
6814
|
schema?: string;
|
|
6846
6815
|
table: string;
|
|
6847
6816
|
nameInDb?: string;
|
|
6848
|
-
columns:
|
|
6817
|
+
columns: {
|
|
6818
|
+
shape: unknown;
|
|
6819
|
+
};
|
|
6820
|
+
}
|
|
6821
|
+
interface TableParamInstanceInput {
|
|
6822
|
+
schema?: QuerySchema;
|
|
6823
|
+
table?: string;
|
|
6824
|
+
nameInDb?: string;
|
|
6825
|
+
columns: {
|
|
6826
|
+
shape: unknown;
|
|
6827
|
+
};
|
|
6849
6828
|
}
|
|
6850
|
-
interface
|
|
6851
|
-
|
|
6829
|
+
interface TableParamWithInstance {
|
|
6830
|
+
instance(): TableParamInstanceInput;
|
|
6852
6831
|
}
|
|
6853
|
-
|
|
6832
|
+
interface TableParamWithData {
|
|
6833
|
+
data: {
|
|
6834
|
+
columns: unknown;
|
|
6835
|
+
};
|
|
6836
|
+
instance(): TableParamInstanceInput;
|
|
6837
|
+
}
|
|
6838
|
+
type TableParam = (new () => TableParamInstance) | TableParamWithInstance | TableParamWithData;
|
|
6839
|
+
type ColumnNameOfTable<Table extends Column.ForeignKey.TableParam> = Table extends {
|
|
6840
|
+
data: {
|
|
6841
|
+
columns: infer R;
|
|
6842
|
+
};
|
|
6843
|
+
} ? keyof R : Table extends {
|
|
6844
|
+
instance(): {
|
|
6845
|
+
columns: {
|
|
6846
|
+
shape: infer R;
|
|
6847
|
+
};
|
|
6848
|
+
};
|
|
6849
|
+
} ? keyof R : Table extends (new () => {
|
|
6854
6850
|
columns: {
|
|
6855
6851
|
shape: infer R;
|
|
6856
6852
|
};
|
|
@@ -6968,8 +6964,8 @@ declare namespace Column {
|
|
|
6968
6964
|
export type AsTypeArg<Schema> = AsTypeArgWithType<Schema> | AsTypeArgWithoutType<Schema>;
|
|
6969
6965
|
export {};
|
|
6970
6966
|
}
|
|
6971
|
-
declare function makeColumnNullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema>(column: T, inputSchema: InputSchema, outputSchema: OutputSchema, querySchema: QuerySchema): Column.
|
|
6972
|
-
declare const setColumnData: <T extends Column.Pick.Data, K extends keyof T[
|
|
6967
|
+
declare function makeColumnNullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema>(column: T, inputSchema: InputSchema, outputSchema: OutputSchema, querySchema: QuerySchema): Column.NullableWithSchema<T, InputSchema, OutputSchema, QuerySchema>;
|
|
6968
|
+
declare const setColumnData: <T extends Column.Pick.Data, K extends keyof T['data']>(q: T, key: K, value: T['data'][K]) => T;
|
|
6973
6969
|
declare const setDataValue: <T extends Column.Pick.Data, Key extends string, Value>(item: T, key: Key, value: Value, params?: Column.Error.StringOrMessage) => T;
|
|
6974
6970
|
declare function setCurrentColumnName(name: string): void;
|
|
6975
6971
|
declare const consumeColumnName: () => string | undefined;
|
|
@@ -7000,31 +6996,28 @@ declare abstract class Column {
|
|
|
7000
6996
|
* Or you can specify a callback that returns a value. This function will be called for each creating record. Such a default won't be applied to a database.
|
|
7001
6997
|
*
|
|
7002
6998
|
* ```ts
|
|
7003
|
-
* export
|
|
7004
|
-
*
|
|
7005
|
-
*
|
|
7006
|
-
*
|
|
7007
|
-
* int: t.integer().default(123),
|
|
7008
|
-
* text: t.text().default('text'),
|
|
6999
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7000
|
+
* // values as defaults:
|
|
7001
|
+
* int: t.integer().default(123),
|
|
7002
|
+
* text: t.text().default('text'),
|
|
7009
7003
|
*
|
|
7010
|
-
*
|
|
7011
|
-
*
|
|
7004
|
+
* // raw SQL default:
|
|
7005
|
+
* timestamp: t.timestamp().default(t.sql`now()`),
|
|
7012
7006
|
*
|
|
7013
|
-
*
|
|
7014
|
-
*
|
|
7015
|
-
*
|
|
7016
|
-
* }
|
|
7007
|
+
* // runtime default, each new records gets a new random value:
|
|
7008
|
+
* random: t.numeric().default(() => Math.random()),
|
|
7009
|
+
* }));
|
|
7017
7010
|
* ```
|
|
7018
7011
|
*
|
|
7019
7012
|
* @param value - default value or a function returning a value
|
|
7020
7013
|
*/
|
|
7021
|
-
default<T extends Column.Pick.DataAndInputType, Value extends T['__inputType'] | null | RawSqlBase | (() => T['__inputType'])>(this: T, value: Value): Column.
|
|
7014
|
+
default<T extends Column.Pick.DataAndInputType, Value extends T['__inputType'] | null | RawSqlBase | (() => T['__inputType'])>(this: T, value: Value): Column.HasDefault<T>;
|
|
7022
7015
|
/**
|
|
7023
7016
|
* Use `hasDefault` to let the column be omitted when creating records.
|
|
7024
7017
|
*
|
|
7025
7018
|
* It's better to use {@link default} instead so the value is explicit and serves as a hint.
|
|
7026
7019
|
*/
|
|
7027
|
-
hasDefault<T extends Column.Pick.Data>(this: T): Column.
|
|
7020
|
+
hasDefault<T extends Column.Pick.Data>(this: T): Column.HasDefault<T>;
|
|
7028
7021
|
/**
|
|
7029
7022
|
* Set a database-level validation check to a column. `check` accepts a raw SQL.
|
|
7030
7023
|
*
|
|
@@ -7056,12 +7049,9 @@ declare abstract class Column {
|
|
|
7056
7049
|
* Nullable columns are optional when creating records.
|
|
7057
7050
|
*
|
|
7058
7051
|
* ```ts
|
|
7059
|
-
* export
|
|
7060
|
-
*
|
|
7061
|
-
*
|
|
7062
|
-
* name: t.integer().nullable(),
|
|
7063
|
-
* }));
|
|
7064
|
-
* }
|
|
7052
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7053
|
+
* name: t.integer().nullable(),
|
|
7054
|
+
* }));
|
|
7065
7055
|
* ```
|
|
7066
7056
|
*/
|
|
7067
7057
|
nullable: this['__schema']['nullable'];
|
|
@@ -7076,21 +7066,18 @@ declare abstract class Column {
|
|
|
7076
7066
|
* ```ts
|
|
7077
7067
|
* import { z } from 'zod';
|
|
7078
7068
|
*
|
|
7079
|
-
* export
|
|
7080
|
-
*
|
|
7081
|
-
*
|
|
7082
|
-
*
|
|
7083
|
-
*
|
|
7084
|
-
*
|
|
7085
|
-
*
|
|
7086
|
-
*
|
|
7087
|
-
*
|
|
7088
|
-
*
|
|
7089
|
-
*
|
|
7090
|
-
*
|
|
7091
|
-
* .encode((input: boolean | number | string) => String(input)),
|
|
7092
|
-
* }));
|
|
7093
|
-
* }
|
|
7069
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7070
|
+
* // encode boolean, number, or string to text before saving
|
|
7071
|
+
* column: t
|
|
7072
|
+
* .string()
|
|
7073
|
+
* // when having validation library, the first argument is a validation schema
|
|
7074
|
+
* .encode(
|
|
7075
|
+
* z.boolean().or(z.number()).or(z.string()),
|
|
7076
|
+
* (input: boolean | number | string) => String(input),
|
|
7077
|
+
* )
|
|
7078
|
+
* // no schema argument otherwise
|
|
7079
|
+
* .encode((input: boolean | number | string) => String(input)),
|
|
7080
|
+
* }));
|
|
7094
7081
|
*
|
|
7095
7082
|
* // numbers and booleans will be converted to a string:
|
|
7096
7083
|
* await db.table.create({ column: 123 });
|
|
@@ -7115,22 +7102,19 @@ declare abstract class Column {
|
|
|
7115
7102
|
* import { z } from 'zod';
|
|
7116
7103
|
* import { number, integer } from 'valibot';
|
|
7117
7104
|
*
|
|
7118
|
-
* export
|
|
7119
|
-
*
|
|
7120
|
-
*
|
|
7121
|
-
*
|
|
7122
|
-
*
|
|
7123
|
-
*
|
|
7124
|
-
*
|
|
7125
|
-
*
|
|
7126
|
-
*
|
|
7127
|
-
*
|
|
7128
|
-
*
|
|
7129
|
-
*
|
|
7130
|
-
*
|
|
7131
|
-
* .parse((input) => parseInt(input)),
|
|
7132
|
-
* }));
|
|
7133
|
-
* }
|
|
7105
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7106
|
+
* columnZod: t
|
|
7107
|
+
* .string()
|
|
7108
|
+
* // when having validation library, the first argument is a schema
|
|
7109
|
+
* .parse(z.number().int(), (input) => parseInt(input))
|
|
7110
|
+
* // no schema argument otherwise
|
|
7111
|
+
* .parse((input) => parseInt(input)),
|
|
7112
|
+
*
|
|
7113
|
+
* columnValibot: t
|
|
7114
|
+
* .string()
|
|
7115
|
+
* .parse(number([integer()]), (input) => parseInt(input))
|
|
7116
|
+
* .parse((input) => parseInt(input)),
|
|
7117
|
+
* }));
|
|
7134
7118
|
*
|
|
7135
7119
|
* // column will be parsed to a number
|
|
7136
7120
|
* const value: number = await db.table.get('column');
|
|
@@ -7145,16 +7129,13 @@ declare abstract class Column {
|
|
|
7145
7129
|
* The `parseNull` function is only triggered for `nullable` columns.
|
|
7146
7130
|
*
|
|
7147
7131
|
* ```ts
|
|
7148
|
-
* export
|
|
7149
|
-
*
|
|
7150
|
-
*
|
|
7151
|
-
*
|
|
7152
|
-
*
|
|
7153
|
-
*
|
|
7154
|
-
*
|
|
7155
|
-
* .nullable(),
|
|
7156
|
-
* }));
|
|
7157
|
-
* }
|
|
7132
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7133
|
+
* column: t
|
|
7134
|
+
* .integer()
|
|
7135
|
+
* .parse(String) // parse non-nulls to string
|
|
7136
|
+
* .parseNull(() => false), // replace nulls with false
|
|
7137
|
+
* .nullable(),
|
|
7138
|
+
* }));
|
|
7158
7139
|
*
|
|
7159
7140
|
* const record = await db.table.take()
|
|
7160
7141
|
* record.column // can be a string or boolean, not null
|
|
@@ -7164,23 +7145,20 @@ declare abstract class Column {
|
|
|
7164
7145
|
* first argument is a schema for validating the output.
|
|
7165
7146
|
*
|
|
7166
7147
|
* ```ts
|
|
7167
|
-
* export
|
|
7168
|
-
*
|
|
7169
|
-
*
|
|
7170
|
-
*
|
|
7171
|
-
*
|
|
7172
|
-
* .parse(z.string(), String) // parse non-nulls to string
|
|
7173
|
-
* .parseNull(z.literal(false), () => false), // replace nulls with false
|
|
7148
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7149
|
+
* column: t
|
|
7150
|
+
* .integer()
|
|
7151
|
+
* .parse(z.string(), String) // parse non-nulls to string
|
|
7152
|
+
* .parseNull(z.literal(false), () => false) // replace nulls with false
|
|
7174
7153
|
* .nullable(),
|
|
7175
|
-
*
|
|
7176
|
-
* }
|
|
7154
|
+
* }));
|
|
7177
7155
|
*
|
|
7178
|
-
* const record = await db.table.take()
|
|
7179
|
-
* record.column // can be a string or boolean, not null
|
|
7156
|
+
* const record = await db.table.take();
|
|
7157
|
+
* record.column; // can be a string or boolean, not null
|
|
7180
7158
|
*
|
|
7181
7159
|
* Table.outputSchema().parse({
|
|
7182
7160
|
* column: false, // the schema expects strings or `false` literals, not nulls
|
|
7183
|
-
* })
|
|
7161
|
+
* });
|
|
7184
7162
|
* ```
|
|
7185
7163
|
*/
|
|
7186
7164
|
parseNull: this['__schema']['parseNull'];
|
|
@@ -7222,12 +7200,9 @@ declare abstract class Column {
|
|
|
7222
7200
|
* When _not_ integrating with [validation libraries](/guide/columns-validation-methods), `narrowType` has the following syntax:
|
|
7223
7201
|
*
|
|
7224
7202
|
* ```ts
|
|
7225
|
-
* export
|
|
7226
|
-
*
|
|
7227
|
-
*
|
|
7228
|
-
* size: t.string().narrowType((t) => t<'small' | 'medium' | 'large'>()),
|
|
7229
|
-
* }));
|
|
7230
|
-
* }
|
|
7203
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7204
|
+
* size: t.string().narrowType((t) => t<'small' | 'medium' | 'large'>()),
|
|
7205
|
+
* }));
|
|
7231
7206
|
*
|
|
7232
7207
|
* // size will be typed as 'small' | 'medium' | 'large'
|
|
7233
7208
|
* const size = await db.table.get('size');
|
|
@@ -7246,12 +7221,9 @@ declare abstract class Column {
|
|
|
7246
7221
|
* z.literal('large'),
|
|
7247
7222
|
* ]);
|
|
7248
7223
|
*
|
|
7249
|
-
* export
|
|
7250
|
-
*
|
|
7251
|
-
*
|
|
7252
|
-
* size: t.text().narrowType(sizeSchema),
|
|
7253
|
-
* }));
|
|
7254
|
-
* }
|
|
7224
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7225
|
+
* size: t.text().narrowType(sizeSchema),
|
|
7226
|
+
* }));
|
|
7255
7227
|
*
|
|
7256
7228
|
* // size will be typed as 'small' | 'medium' | 'large'
|
|
7257
7229
|
* const size = await db.table.get('size');
|
|
@@ -7268,21 +7240,18 @@ declare abstract class Column {
|
|
|
7268
7240
|
* When _not_ integrating with [validation libraries](/guide/columns-validation-methods), `narrowAllTypes` has the following syntax:
|
|
7269
7241
|
*
|
|
7270
7242
|
* ```ts
|
|
7271
|
-
* export
|
|
7272
|
-
*
|
|
7273
|
-
*
|
|
7274
|
-
*
|
|
7275
|
-
*
|
|
7276
|
-
*
|
|
7277
|
-
*
|
|
7278
|
-
*
|
|
7279
|
-
*
|
|
7280
|
-
*
|
|
7281
|
-
*
|
|
7282
|
-
*
|
|
7283
|
-
* ),
|
|
7284
|
-
* }));
|
|
7285
|
-
* }
|
|
7243
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7244
|
+
* size: t.string().narrowAllTypes((t) =>
|
|
7245
|
+
* t<{
|
|
7246
|
+
* // what types are accepted when creating/updating
|
|
7247
|
+
* input: 'small' | 'medium' | 'large';
|
|
7248
|
+
* // how types are retured from a database
|
|
7249
|
+
* output: 'small' | 'medium' | 'large';
|
|
7250
|
+
* // what types the column accepts in `where` and similar
|
|
7251
|
+
* query: 'small' | 'medium' | 'large';
|
|
7252
|
+
* }>(),
|
|
7253
|
+
* ),
|
|
7254
|
+
* }));
|
|
7286
7255
|
*
|
|
7287
7256
|
* // size will be typed as 'small' | 'medium' | 'large'
|
|
7288
7257
|
* const size = await db.table.get('size');
|
|
@@ -7301,16 +7270,13 @@ declare abstract class Column {
|
|
|
7301
7270
|
* z.literal('large'),
|
|
7302
7271
|
* ]);
|
|
7303
7272
|
*
|
|
7304
|
-
* export
|
|
7305
|
-
*
|
|
7306
|
-
*
|
|
7307
|
-
*
|
|
7308
|
-
*
|
|
7309
|
-
*
|
|
7310
|
-
*
|
|
7311
|
-
* }),
|
|
7312
|
-
* }));
|
|
7313
|
-
* }
|
|
7273
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7274
|
+
* size: t.text().narrowAllTypes({
|
|
7275
|
+
* input: sizeSchema,
|
|
7276
|
+
* output: sizeSchema,
|
|
7277
|
+
* query: sizeSchema,
|
|
7278
|
+
* }),
|
|
7279
|
+
* }));
|
|
7314
7280
|
*
|
|
7315
7281
|
* // size will be typed as 'small' | 'medium' | 'large'
|
|
7316
7282
|
* const size = await db.table.get('size');
|
|
@@ -7321,13 +7287,13 @@ declare abstract class Column {
|
|
|
7321
7287
|
narrowAllTypes: this['__schema']['narrowAllTypes'];
|
|
7322
7288
|
input<T extends {
|
|
7323
7289
|
inputSchema: unknown;
|
|
7324
|
-
}, InputSchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['inputSchema']) => InputSchema): { [K in keyof T]: K extends 'inputSchema' ? InputSchema : T[K] };
|
|
7290
|
+
}, InputSchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['inputSchema']) => InputSchema): { [K in keyof T]: K extends 'inputSchema' ? InputSchema : T[K]; };
|
|
7325
7291
|
output<T extends {
|
|
7326
7292
|
outputSchema: unknown;
|
|
7327
|
-
}, OutputSchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['outputSchema']) => OutputSchema): { [K in keyof T]: K extends 'outputSchema' ? OutputSchema : T[K] };
|
|
7293
|
+
}, OutputSchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['outputSchema']) => OutputSchema): { [K in keyof T]: K extends 'outputSchema' ? OutputSchema : T[K]; };
|
|
7328
7294
|
query<T extends {
|
|
7329
7295
|
querySchema: unknown;
|
|
7330
|
-
}, QuerySchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['querySchema']) => QuerySchema): { [K in keyof T]: K extends 'querySchema' ? QuerySchema : T[K] };
|
|
7296
|
+
}, QuerySchema extends this['__schema']['__schemaType']>(this: T, fn: (schema: T['querySchema']) => QuerySchema): { [K in keyof T]: K extends 'querySchema' ? QuerySchema : T[K]; };
|
|
7331
7297
|
/**
|
|
7332
7298
|
* Set a database column name.
|
|
7333
7299
|
*
|
|
@@ -7339,14 +7305,11 @@ declare abstract class Column {
|
|
|
7339
7305
|
* It won't be selected with `selectAll` or `select('*')` as well.
|
|
7340
7306
|
*
|
|
7341
7307
|
* ```ts
|
|
7342
|
-
* export
|
|
7343
|
-
*
|
|
7344
|
-
*
|
|
7345
|
-
*
|
|
7346
|
-
*
|
|
7347
|
-
* password: t.string().select(false),
|
|
7348
|
-
* }));
|
|
7349
|
-
* }
|
|
7308
|
+
* export const UserTable = defineTable('user', (t) => ({
|
|
7309
|
+
* id: t.identity().primaryKey(),
|
|
7310
|
+
* name: t.string(),
|
|
7311
|
+
* password: t.string().select(false),
|
|
7312
|
+
* }));
|
|
7350
7313
|
*
|
|
7351
7314
|
* // only id and name are selected, without password
|
|
7352
7315
|
* const user = await db.user.find(123);
|
|
@@ -7369,7 +7332,7 @@ declare abstract class Column {
|
|
|
7369
7332
|
* const userWithPassword = await db.user.find(123).select('*', 'password');
|
|
7370
7333
|
* ```
|
|
7371
7334
|
*/
|
|
7372
|
-
select<T extends Column.Pick.Data, Value extends boolean>(this: T, value: Value): Column.
|
|
7335
|
+
select<T extends Column.Pick.Data, Value extends boolean>(this: T, value: Value): Column.DefaultSelect<T, Value>;
|
|
7373
7336
|
/**
|
|
7374
7337
|
* Set SQL to use when selecting this column.
|
|
7375
7338
|
*
|
|
@@ -7385,26 +7348,23 @@ declare abstract class Column {
|
|
|
7385
7348
|
* `readOnly` column can be used together with a `default`.
|
|
7386
7349
|
*
|
|
7387
7350
|
* ```ts
|
|
7388
|
-
* export
|
|
7389
|
-
*
|
|
7390
|
-
*
|
|
7391
|
-
*
|
|
7392
|
-
*
|
|
7393
|
-
*
|
|
7394
|
-
*
|
|
7395
|
-
*
|
|
7396
|
-
* init(orm: typeof db) {
|
|
7397
|
-
* this.beforeSave(({ set }) => {
|
|
7351
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7352
|
+
* id: t.identity().primaryKey(),
|
|
7353
|
+
* column: t.string().default(() => 'default value'),
|
|
7354
|
+
* another: t.string().nullable().readOnly(),
|
|
7355
|
+
* })).init((orm: typeof db, hooks) => {
|
|
7356
|
+
* hooks.beforeSave(({ columns, set }) => {
|
|
7357
|
+
* if (columns.include('column')) {
|
|
7398
7358
|
* set({ another: 'value' });
|
|
7399
|
-
* }
|
|
7400
|
-
* }
|
|
7401
|
-
* }
|
|
7359
|
+
* }
|
|
7360
|
+
* });
|
|
7361
|
+
* });
|
|
7402
7362
|
*
|
|
7403
7363
|
* // later in the code
|
|
7404
7364
|
* db.table.create({ column: 'value' }); // TS error, runtime error
|
|
7405
7365
|
* ```
|
|
7406
7366
|
*/
|
|
7407
|
-
readOnly<T>(this: T): T & Column.
|
|
7367
|
+
readOnly<T>(this: T): T & Column.IsAppReadOnly;
|
|
7408
7368
|
/**
|
|
7409
7369
|
* Set a column value when creating a record.
|
|
7410
7370
|
* This works for [readOnly](#readonly) columns as well.
|
|
@@ -7412,13 +7372,15 @@ declare abstract class Column {
|
|
|
7412
7372
|
* If no value or undefined is returned, the hook won't have any effect.
|
|
7413
7373
|
*
|
|
7414
7374
|
* ```ts
|
|
7415
|
-
* export
|
|
7416
|
-
*
|
|
7417
|
-
*
|
|
7418
|
-
*
|
|
7419
|
-
*
|
|
7420
|
-
*
|
|
7421
|
-
*
|
|
7375
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7376
|
+
* id: t.identity().primaryKey(),
|
|
7377
|
+
* some: t.number(),
|
|
7378
|
+
* column: t
|
|
7379
|
+
* .string()
|
|
7380
|
+
* .setOnCreate(({ columns }) =>
|
|
7381
|
+
* columns.include('some') ? 'value' : undefined,
|
|
7382
|
+
* ),
|
|
7383
|
+
* }));
|
|
7422
7384
|
* ```
|
|
7423
7385
|
*/
|
|
7424
7386
|
setOnCreate<T extends Column.Pick.QueryInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['__inputType'] | void): T;
|
|
@@ -7429,13 +7391,15 @@ declare abstract class Column {
|
|
|
7429
7391
|
* If no value or undefined is returned, the hook won't have any effect.
|
|
7430
7392
|
*
|
|
7431
7393
|
* ```ts
|
|
7432
|
-
* export
|
|
7433
|
-
*
|
|
7434
|
-
*
|
|
7435
|
-
*
|
|
7436
|
-
*
|
|
7437
|
-
*
|
|
7438
|
-
*
|
|
7394
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7395
|
+
* id: t.identity().primaryKey(),
|
|
7396
|
+
* some: t.number(),
|
|
7397
|
+
* column: t
|
|
7398
|
+
* .string()
|
|
7399
|
+
* .setOnUpdate(({ columns }) =>
|
|
7400
|
+
* columns.include('some') ? 'value' : undefined,
|
|
7401
|
+
* ),
|
|
7402
|
+
* }));
|
|
7439
7403
|
* ```
|
|
7440
7404
|
*/
|
|
7441
7405
|
setOnUpdate<T extends Column.Pick.QueryInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['__inputType'] | void): T;
|
|
@@ -7446,13 +7410,15 @@ declare abstract class Column {
|
|
|
7446
7410
|
* If no value or undefined is returned, the hook won't have any effect.
|
|
7447
7411
|
*
|
|
7448
7412
|
* ```ts
|
|
7449
|
-
* export
|
|
7450
|
-
*
|
|
7451
|
-
*
|
|
7452
|
-
*
|
|
7453
|
-
*
|
|
7454
|
-
*
|
|
7455
|
-
*
|
|
7413
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7414
|
+
* id: t.identity().primaryKey(),
|
|
7415
|
+
* some: t.number(),
|
|
7416
|
+
* column: t
|
|
7417
|
+
* .string()
|
|
7418
|
+
* .setOnSave(({ columns }) =>
|
|
7419
|
+
* columns.include('some') ? 'value' : undefined,
|
|
7420
|
+
* ),
|
|
7421
|
+
* }));
|
|
7456
7422
|
* ```
|
|
7457
7423
|
*/
|
|
7458
7424
|
setOnSave<T extends Column.Pick.QueryInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['__inputType'] | void): T;
|
|
@@ -7465,14 +7431,11 @@ declare abstract class Column {
|
|
|
7465
7431
|
* Using `primaryKey` on a `uuid` column will automatically add a [gen_random_uuid](https://www.postgresql.org/docs/current/functions-uuid.html) default.
|
|
7466
7432
|
*
|
|
7467
7433
|
* ```ts
|
|
7468
|
-
* export
|
|
7469
|
-
*
|
|
7470
|
-
*
|
|
7471
|
-
*
|
|
7472
|
-
*
|
|
7473
|
-
* id: t.uuid().primaryKey('primary_key_name'),
|
|
7474
|
-
* }));
|
|
7475
|
-
* }
|
|
7434
|
+
* export const Table = defineTable('table', (t) => ({
|
|
7435
|
+
* id: t.uuid().primaryKey(),
|
|
7436
|
+
* // optionally, specify a database-level constraint name:
|
|
7437
|
+
* id: t.uuid().primaryKey('primary_key_name'),
|
|
7438
|
+
* }));
|
|
7476
7439
|
*
|
|
7477
7440
|
* // primary key can be used by `find` later:
|
|
7478
7441
|
* db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
|
|
@@ -7480,7 +7443,7 @@ declare abstract class Column {
|
|
|
7480
7443
|
*
|
|
7481
7444
|
* @param name - to specify a constraint name
|
|
7482
7445
|
*/
|
|
7483
|
-
primaryKey<T extends Column.Pick.Data, Name extends string>(this: T, name?: Name): T & Column.
|
|
7446
|
+
primaryKey<T extends Column.Pick.Data, Name extends string>(this: T, name?: Name): T & Column.IsPrimaryKey<Name>;
|
|
7484
7447
|
/**
|
|
7485
7448
|
* Defines a reference between different tables to enforce data integrity.
|
|
7486
7449
|
*
|
|
@@ -7499,12 +7462,9 @@ declare abstract class Column {
|
|
|
7499
7462
|
* In the migration it's different from OrchidORM table code where a callback with a table is expected:
|
|
7500
7463
|
*
|
|
7501
7464
|
* ```ts
|
|
7502
|
-
* export
|
|
7503
|
-
*
|
|
7504
|
-
*
|
|
7505
|
-
* otherTableId: t.integer().foreignKey(() => OtherTable, 'id'),
|
|
7506
|
-
* }));
|
|
7507
|
-
* }
|
|
7465
|
+
* export const SomeTable = defineTable('someTable', (t) => ({
|
|
7466
|
+
* otherTableId: t.integer().foreignKey(() => OtherTable, 'id'),
|
|
7467
|
+
* }));
|
|
7508
7468
|
* ```
|
|
7509
7469
|
*
|
|
7510
7470
|
* Optionally you can pass the third argument to `foreignKey` with options:
|
|
@@ -7555,11 +7515,7 @@ declare abstract class Column {
|
|
|
7555
7515
|
* @param column - column in the foreign table to connect with
|
|
7556
7516
|
* @param options - {@link ForeignKeyOptions}
|
|
7557
7517
|
*/
|
|
7558
|
-
foreignKey<T,
|
|
7559
|
-
columns: {
|
|
7560
|
-
shape: Shape;
|
|
7561
|
-
};
|
|
7562
|
-
}, column: keyof Shape, options?: TableData.References.Options): T;
|
|
7518
|
+
foreignKey<T, Table extends Column.ForeignKey.TableParam>(this: T, fn: () => Table, column: Column.ForeignKey.ColumnNameOfTable<Table>, options?: TableData.References.Options): T;
|
|
7563
7519
|
foreignKey<T, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: TableData.References.Options): T;
|
|
7564
7520
|
toSQL(): string;
|
|
7565
7521
|
/**
|
|
@@ -7717,7 +7673,7 @@ declare abstract class Column {
|
|
|
7717
7673
|
data: Column['data'];
|
|
7718
7674
|
dataType: string;
|
|
7719
7675
|
}>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg]): T;
|
|
7720
|
-
unique<T extends Column.Pick.Data, const Options extends TableData.Index.UniqueColumnArg>(this: T, ...args: [options?: Options]): T & Column.
|
|
7676
|
+
unique<T extends Column.Pick.Data, const Options extends TableData.Index.UniqueColumnArg>(this: T, ...args: [options?: Options]): T & Column.IsUnique<Options['name'] & string>;
|
|
7721
7677
|
/**
|
|
7722
7678
|
* Add [EXCLUDE constraint](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE) to the column.
|
|
7723
7679
|
*
|
|
@@ -7783,7 +7739,7 @@ declare abstract class Column {
|
|
|
7783
7739
|
*
|
|
7784
7740
|
* @param args - raw SQL
|
|
7785
7741
|
*/
|
|
7786
|
-
generated<T extends Column.Pick.Data>(this: T, ...args: StaticSQLArgs): Column.
|
|
7742
|
+
generated<T extends Column.Pick.Data>(this: T, ...args: StaticSQLArgs): Column.Generated<T>;
|
|
7787
7743
|
}
|
|
7788
7744
|
interface ColumnFromDbParams {
|
|
7789
7745
|
isNullable?: boolean;
|
|
@@ -7812,15 +7768,7 @@ type CreateManyFromResult<T extends CreateSelf> = T extends {
|
|
|
7812
7768
|
isCount: true;
|
|
7813
7769
|
} ? T : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAll<T> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetValueQueryReturnsPluckColumn<T> : T;
|
|
7814
7770
|
type InsertManyFromResult<T extends CreateSelf> = T['__hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAll<T> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetValueQueryReturnsPluckColumn<T> : T : SetQueryReturnsRowCountMany<T>;
|
|
7815
|
-
|
|
7816
|
-
* Function to collect column names from the inner query of create `from` methods.
|
|
7817
|
-
*
|
|
7818
|
-
* @param q - the creating query
|
|
7819
|
-
* @param from - inner query to grab the columns from.
|
|
7820
|
-
* @param obj - optionally passed object with specific data, only available when creating a single record.
|
|
7821
|
-
* @param many - whether it's for `createForEachFrom`. If no, throws if the inner query returns multiple records.
|
|
7822
|
-
*/
|
|
7823
|
-
declare const _queryCreateManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T>, keyof Q["result"]>[]) => CreateManyFromResult<T>;
|
|
7771
|
+
declare const _queryCreateManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T>, keyof Q['result']>[]) => CreateManyFromResult<T>;
|
|
7824
7772
|
declare class QueryCreateFrom {
|
|
7825
7773
|
/**
|
|
7826
7774
|
* Inserts a single record based on a query that selects a single record.
|
|
@@ -7873,14 +7821,14 @@ declare class QueryCreateFrom {
|
|
|
7873
7821
|
* @param query - query to create new records from
|
|
7874
7822
|
* @param data - additionally you can set some columns
|
|
7875
7823
|
*/
|
|
7876
|
-
createOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?:
|
|
7824
|
+
createOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: CreateDataOmit<T, Q['result'] extends never ? never : keyof Q['result']>): CreateRawOrFromResult<T>;
|
|
7877
7825
|
/**
|
|
7878
7826
|
* Works exactly as {@link createOneFrom}, except that it returns inserted row count by default.
|
|
7879
7827
|
*
|
|
7880
7828
|
* @param query - query to create new records from
|
|
7881
7829
|
* @param data - additionally you can set some columns
|
|
7882
7830
|
*/
|
|
7883
|
-
insertOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?:
|
|
7831
|
+
insertOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: CreateDataOmit<T, Q['result'] extends never ? never : keyof Q['result']>): InsertRawOrFromResult<T>;
|
|
7884
7832
|
/**
|
|
7885
7833
|
* Inserts multiple records based on a query that selects a single record.
|
|
7886
7834
|
*
|
|
@@ -7940,14 +7888,14 @@ declare class QueryCreateFrom {
|
|
|
7940
7888
|
* @param query - query to create new records from
|
|
7941
7889
|
* @param data - array of records to create
|
|
7942
7890
|
*/
|
|
7943
|
-
createManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data:
|
|
7891
|
+
createManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: CreateDataOmit<T, Q['result'] extends never ? never : keyof Q['result']>[]): CreateManyFromResult<T>;
|
|
7944
7892
|
/**
|
|
7945
7893
|
* Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
|
|
7946
7894
|
*
|
|
7947
7895
|
* @param query - query to create new records from
|
|
7948
7896
|
* @param data - array of records to create
|
|
7949
7897
|
*/
|
|
7950
|
-
insertManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data:
|
|
7898
|
+
insertManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: CreateDataOmit<T, Q['result'] extends never ? never : keyof Q['result']>[]): InsertManyFromResult<T>;
|
|
7951
7899
|
/**
|
|
7952
7900
|
* Inserts a single record per every record found in a given query.
|
|
7953
7901
|
*
|
|
@@ -7975,12 +7923,19 @@ declare class QueryCreateFrom {
|
|
|
7975
7923
|
}
|
|
7976
7924
|
interface CreateSelf extends PickQueryHasSelect, PickQueryDefaults, PickQueryResult, PickQueryRelations, PickQueryRelationsDataForCreate, PickQueryRelationsDataForCreateOptional, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryUniqueProperties, PickQueryInputType, Query.Pick.IsNotReadOnly {}
|
|
7977
7925
|
type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? CreateDataWithDefaults<T, keyof T['__defaults']> : CreateRelationsData<T>;
|
|
7978
|
-
type
|
|
7979
|
-
type
|
|
7926
|
+
type CreateDataOmit<T extends CreateSelf, OmitKeys> = EmptyObject extends T['relations'] ? CreateDataWithDefaultsOmit<T, keyof T['__defaults'], OmitKeys> : CreateRelationsDataOmit<T, OmitKeys>;
|
|
7927
|
+
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = { [K in keyof T['__inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K>; } & { [K in Defaults]?: K extends keyof T['__inputType'] ? CreateColumn<T, K> : never; };
|
|
7928
|
+
type CreateDataWithDefaultsOmit<T extends CreateSelf, Defaults extends PropertyKey, OmitKeys> = { [K in keyof T['__inputType'] as K extends Defaults | OmitKeys ? never : K]: K extends Defaults ? never : CreateColumn<T, K>; } & { [K in Defaults as K extends OmitKeys ? never : K]?: K extends keyof T['__inputType'] ? CreateColumn<T, K> : never; };
|
|
7929
|
+
type WritableForeignKeys<T extends CreateSelf, AllFKeys extends PropertyKey> = AllFKeys extends (infer K) ? K extends keyof T['shape'] ? T['shape'][K] extends {
|
|
7930
|
+
data: {
|
|
7931
|
+
makeColumnWritable: true;
|
|
7932
|
+
};
|
|
7933
|
+
} ? K : never : never : never;
|
|
7980
7934
|
type CreateColumn<T extends CreateSelf, K extends keyof T['__inputType']> = T['__inputType'][K] | ((q: T) => QueryOrExpression<T['__inputType'][K]>);
|
|
7981
|
-
type CreateRelationsData<T extends CreateSelf> =
|
|
7982
|
-
type
|
|
7983
|
-
type
|
|
7935
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsOmit<T, keyof T['__defaults'], Exclude<T['relations'][keyof T['relations']]['omitForeignKeyInCreate'], WritableForeignKeys<T, T['relations'][keyof T['relations']]['omitForeignKeyInCreate']>>> & CreateRelationsDataOmittingFKeys<T, T['relationsDataForCreate']> & T['relationsDataForCreateOptional'];
|
|
7936
|
+
type CreateRelationsDataOmit<T extends CreateSelf, OmitKeys> = CreateDataWithDefaultsOmit<T, keyof T['__defaults'], Exclude<T['relations'][keyof T['relations']]['omitForeignKeyInCreate'], WritableForeignKeys<T, T['relations'][keyof T['relations']]['omitForeignKeyInCreate']>> | OmitKeys> & CreateRelationsDataOmittingFKeys<T, T['relationsDataForCreate']> & T['relationsDataForCreateOptional'];
|
|
7937
|
+
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Data> = EmptyObject extends Data ? EmptyObject : { [K in keyof Data]: CreateRelationDataOmittingFKeys<T, Data[K]>; }[keyof Data] extends ((u: infer Obj) => void) ? Obj : never;
|
|
7938
|
+
type CreateRelationDataOmittingFKeys<T extends CreateSelf, Union> = (u: Union extends RelationConfigDataForCreate ? Union['columns'] extends keyof T['__defaults'] ? Pick<CreateDataWithDefaults<T, keyof T['__defaults']>, Union['columns']> & Partial<Union['nested']> : (Pick<{ [P in keyof T['__inputType']]: CreateColumn<T, P>; }, Union['columns'] & keyof T['__inputType']> & { [K in keyof Union['nested']]?: never; }) | Union['nested'] : Union) => void;
|
|
7984
7939
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7985
7940
|
isCount: true;
|
|
7986
7941
|
} ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneResult<T, NarrowCreateResult<T, Data>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnResult<T, NarrowCreateResult<T, Data>> : SetQueryResult<T, NarrowCreateResult<T, Data>>;
|
|
@@ -7995,12 +7950,12 @@ type InsertManyResult<T extends CreateSelf> = T['__hasSelect'] extends true ? T[
|
|
|
7995
7950
|
*
|
|
7996
7951
|
* The same should work as well with any non-null columns passed to `create`, but it's to be implemented later.
|
|
7997
7952
|
*/
|
|
7998
|
-
type NarrowCreateResult<T extends CreateSelf, Data> = EmptyObject extends T['relations'] ? T['result'] : { [K in keyof T['result']]: true extends { [R in keyof T['relations']]: K extends T['relations'][R]['omitForeignKeyInCreate'] ? R extends keyof Data ? true : T['relations'][R]['omitForeignKeyInCreate'] extends keyof Data ? null | undefined extends Data[T['relations'][R]['omitForeignKeyInCreate']] ? never : true : never : never }[keyof T['relations']] ? Column.Pick.QueryColumnOfTypeAndOps<string, Exclude<T['result'][K]['__outputType'], null>, T['result'][K]['operators']> : T['result'][K] };
|
|
7953
|
+
type NarrowCreateResult<T extends CreateSelf, Data> = EmptyObject extends T['relations'] ? T['result'] : { [K in keyof T['result']]: true extends { [R in keyof T['relations']]: K extends T['relations'][R]['omitForeignKeyInCreate'] ? R extends keyof Data ? true : T['relations'][R]['omitForeignKeyInCreate'] extends keyof Data ? null | undefined extends Data[T['relations'][R]['omitForeignKeyInCreate']] ? never : true : never : never; }[keyof T['relations']] ? Column.Pick.QueryColumnOfTypeAndOps<string, Exclude<T['result'][K]['__outputType'], null>, T['result'][K]['operators']> : T['result'][K]; };
|
|
7999
7954
|
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? QueryTakeOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
8000
7955
|
type OnConflictArg<T extends PickQueryUniqueProperties> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'] | Expression | {
|
|
8001
7956
|
constraint: T['internal']['uniqueConstraints'];
|
|
8002
7957
|
};
|
|
8003
|
-
type AddQueryDefaults<T extends CreateSelf, DefaultKeys extends PropertyKey> = { [K in keyof T]: K extends '__defaults' ? { [K in keyof T['__defaults'] | DefaultKeys]: true } : T[K] };
|
|
7958
|
+
type AddQueryDefaults<T extends CreateSelf, DefaultKeys extends PropertyKey> = { [K in keyof T]: K extends '__defaults' ? { [K in keyof T['__defaults'] | DefaultKeys]: true; } : T[K]; };
|
|
8004
7959
|
/**
|
|
8005
7960
|
* Used by ORM to access the context of current create query.
|
|
8006
7961
|
* Is passed to the `create` method of a {@link VirtualColumn}
|
|
@@ -8196,31 +8151,26 @@ declare class QueryCreate {
|
|
|
8196
8151
|
* A primary key or a unique index for a **single** column can be fined on a column:
|
|
8197
8152
|
*
|
|
8198
8153
|
* ```ts
|
|
8199
|
-
* export
|
|
8200
|
-
*
|
|
8201
|
-
*
|
|
8202
|
-
*
|
|
8203
|
-
* }));
|
|
8204
|
-
* }
|
|
8154
|
+
* export const MyTable = defineTable('myTable', (t) => ({
|
|
8155
|
+
* pkey: t.uuid().primaryKey(),
|
|
8156
|
+
* unique: t.string().unique(),
|
|
8157
|
+
* }));
|
|
8205
8158
|
* ```
|
|
8206
8159
|
*
|
|
8207
8160
|
* But for composite primary keys or indexes (having multiple columns), define it in a separate function:
|
|
8208
8161
|
*
|
|
8209
8162
|
* ```ts
|
|
8210
|
-
* export
|
|
8211
|
-
*
|
|
8212
|
-
*
|
|
8213
|
-
*
|
|
8214
|
-
*
|
|
8215
|
-
*
|
|
8216
|
-
*
|
|
8217
|
-
* (t) => [t.primaryKey(['one', 'two']), t.unique(['two', 'three'])],
|
|
8218
|
-
* );
|
|
8219
|
-
* }
|
|
8163
|
+
* export const MyTable = defineTable('myTable', (t) => ({
|
|
8164
|
+
* one: t.integer(),
|
|
8165
|
+
* two: t.string(),
|
|
8166
|
+
* three: t.boolean(),
|
|
8167
|
+
* }))
|
|
8168
|
+
* .primaryKey(['one', 'two'])
|
|
8169
|
+
* .unique(['two', 'three']);
|
|
8220
8170
|
* ```
|
|
8221
8171
|
* :::
|
|
8222
8172
|
*
|
|
8223
|
-
* You can use the `sql` function exported from your
|
|
8173
|
+
* You can use the `sql` function exported from your table factory file in onConflict.
|
|
8224
8174
|
* It can be useful to specify a condition when you have a partial index:
|
|
8225
8175
|
*
|
|
8226
8176
|
* ```ts
|
|
@@ -8296,7 +8246,7 @@ declare class QueryCreate {
|
|
|
8296
8246
|
*/
|
|
8297
8247
|
onConflictDoNothing<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): IgnoreResult<T>;
|
|
8298
8248
|
}
|
|
8299
|
-
type OnConflictSet$1<T extends CreateSelf> = { [K in keyof T['__inputType']]?: T['__inputType'][K] | (() => QueryOrExpression<T['__inputType'][K]>) };
|
|
8249
|
+
type OnConflictSet$1<T extends CreateSelf> = { [K in keyof T['__inputType']]?: T['__inputType'][K] | (() => QueryOrExpression<T['__inputType'][K]>); };
|
|
8300
8250
|
declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
|
|
8301
8251
|
private query;
|
|
8302
8252
|
private onConflict;
|
|
@@ -8365,11 +8315,11 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
8365
8315
|
}): T;
|
|
8366
8316
|
}
|
|
8367
8317
|
interface UpdateSelf extends PickQuerySelectable, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryInputType, PickQueryAs, PickQueryHasSelect, PickQueryHasWhere, Query.Pick.IsNotReadOnly {}
|
|
8368
|
-
type UpdateData<T extends UpdateSelf> = { [K in keyof T['__inputType'] | keyof T['relations']]?: K extends keyof T['__inputType'] ? T['__inputType'][K] | ((q: { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T ? T[K] : never }) => QueryOrExpression<T['__inputType'][K]>) : T['returnType'] extends undefined | 'all' ? T['relations'][K]['dataForUpdate'] : T['relations'][K]['dataForUpdateOne'] };
|
|
8318
|
+
type UpdateData<T extends UpdateSelf> = { [K in keyof T['__inputType'] | keyof T['relations']]?: K extends keyof T['__inputType'] ? T['__inputType'][K] | ((q: { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T ? T[K] : never; }) => QueryOrExpression<T['__inputType'][K]>) : T['returnType'] extends undefined | 'all' ? T['relations'][K]['dataForUpdate'] : T['relations'][K]['dataForUpdateOne']; };
|
|
8369
8319
|
type UpdateArg<T extends UpdateSelf> = T['__hasWhere'] extends true ? UpdateData<T> : 'Update statement must have where conditions. To update all prefix `update` with `all()`';
|
|
8370
8320
|
type UpdateResult<T extends UpdateSelf> = T['__hasSelect'] extends true ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsRowCountMany<T> : SetQueryReturnsRowCount<T>;
|
|
8371
|
-
type NumericColumns<T extends UpdateSelf> = { [K in keyof T['__inputType']]: Exclude<T['shape'][K]['__queryType'], string> extends number | bigint | null ? K : never }[keyof T['__inputType']];
|
|
8372
|
-
type ChangeCountArg<T extends UpdateSelf> = NumericColumns<T> | { [K in NumericColumns<T>]?: T['shape'][K]['__type'] extends number | null ? number : number | string | bigint };
|
|
8321
|
+
type NumericColumns<T extends UpdateSelf> = { [K in keyof T['__inputType']]: Exclude<T['shape'][K]['__queryType'], string> extends number | bigint | null ? K : never; }[keyof T['__inputType']];
|
|
8322
|
+
type ChangeCountArg<T extends UpdateSelf> = NumericColumns<T> | { [K in NumericColumns<T>]?: T['shape'][K]['__type'] extends number | null ? number : number | string | bigint; };
|
|
8373
8323
|
interface UpdateManyBySelf extends UpdateSelf {
|
|
8374
8324
|
internal: {
|
|
8375
8325
|
uniqueColumns: unknown;
|
|
@@ -8378,10 +8328,10 @@ interface UpdateManyBySelf extends UpdateSelf {
|
|
|
8378
8328
|
uniqueConstraints: unknown;
|
|
8379
8329
|
};
|
|
8380
8330
|
}
|
|
8381
|
-
type UpdateManyData<T extends UpdateSelf> = ({ [K in keyof T['shape'] as T['shape'][K] extends Column.
|
|
8331
|
+
type UpdateManyData<T extends UpdateSelf> = ({ [K in keyof T['shape'] as T['shape'][K] extends Column.IsPrimaryKey<string> ? K : never]: T['shape'][K]['__queryType'] | Expression; } & { [P in keyof T['__inputType']]?: T['__inputType'][P] | Expression; })[];
|
|
8382
8332
|
type UpdateManyByKeys<T extends UpdateManyBySelf> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'];
|
|
8383
8333
|
type UpdateManyByKeyColumns<K> = K extends string[] ? K[number] : K;
|
|
8384
|
-
type UpdateManyByData<T extends UpdateSelf, K> = ({ [P in K & keyof T['__inputType']]: T['__inputType'][P] } & { [P in keyof T['__inputType']]?: P extends K ? T['__inputType'][P] : T['__inputType'][P] | Expression })[];
|
|
8334
|
+
type UpdateManyByData<T extends UpdateSelf, K> = ({ [P in K & keyof T['__inputType']]: T['__inputType'][P]; } & { [P in keyof T['__inputType']]?: P extends K ? T['__inputType'][P] : T['__inputType'][P] | Expression; })[];
|
|
8385
8335
|
type UpdateManyResult<T extends UpdateSelf> = T['__hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllResult<T, T['result']> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnResult<T, T['result']> : SetQueryResult<T, T['result']> : SetQueryReturnsRowCountMany<T>;
|
|
8386
8336
|
declare const _queryUpdate: <T extends UpdateSelf>(updateSelf: T, arg: UpdateArg<T>) => UpdateResult<T>;
|
|
8387
8337
|
declare const _queryUpdateOrThrow: <T extends UpdateSelf>(q: T, arg: UpdateArg<T>) => UpdateResult<T>;
|
|
@@ -8869,7 +8819,7 @@ type ComputedColumnsFromOptions<Shape, Options> = Options extends {
|
|
|
8869
8819
|
result: {
|
|
8870
8820
|
value: infer Value extends Column.Pick.QueryColumn;
|
|
8871
8821
|
};
|
|
8872
|
-
}) ? Value : never : never } : Shape;
|
|
8822
|
+
}) ? Value : never : never; } : Shape;
|
|
8873
8823
|
interface ComputedOptionsConfig {
|
|
8874
8824
|
[K: string]: QueryOrExpression<unknown> | ReturnsQueryOrExpression<unknown>;
|
|
8875
8825
|
}
|
|
@@ -8884,12 +8834,12 @@ interface RuntimeComputedQueryColumn<OutputType> extends Column.Pick.QueryColumn
|
|
|
8884
8834
|
};
|
|
8885
8835
|
}
|
|
8886
8836
|
interface ComputedMethods<ColumnTypes, Shape extends Column.QueryColumns> extends QueryComputedArg<ColumnTypes, Shape> {
|
|
8887
|
-
computeAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: { [K in keyof Shape & Deps]: Shape[K]['__outputType'] }) => OutputType): {
|
|
8837
|
+
computeAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: { [K in keyof Shape & Deps]: Shape[K]['__outputType']; }) => OutputType): {
|
|
8888
8838
|
result: {
|
|
8889
8839
|
value: RuntimeComputedQueryColumn<OutputType>;
|
|
8890
8840
|
};
|
|
8891
8841
|
};
|
|
8892
|
-
computeBatchAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: { [K in keyof Shape & Deps]: Shape[K]['__outputType'] }[]) => MaybePromise<OutputType[]>): {
|
|
8842
|
+
computeBatchAtRuntime<Deps extends keyof Shape, OutputType>(dependsOn: Deps[], fn: (record: { [K in keyof Shape & Deps]: Shape[K]['__outputType']; }[]) => MaybePromise<OutputType[]>): {
|
|
8893
8843
|
result: {
|
|
8894
8844
|
value: RuntimeComputedQueryColumn<OutputType>;
|
|
8895
8845
|
};
|
|
@@ -8913,7 +8863,7 @@ interface QueryComputedArg<ColumnTypes, Shape extends Column.QueryColumns> exten
|
|
|
8913
8863
|
__selectable: { [K in keyof Shape]: {
|
|
8914
8864
|
as: string;
|
|
8915
8865
|
column: Column.Pick.QueryColumn;
|
|
8916
|
-
} };
|
|
8866
|
+
}; };
|
|
8917
8867
|
}
|
|
8918
8868
|
type WhereItem = {
|
|
8919
8869
|
[K: string]: unknown | {
|
|
@@ -9023,6 +8973,7 @@ interface QueryData extends QueryDataAliases, PickQueryDataParsers, HasHookSelec
|
|
|
9023
8973
|
returningMany?: boolean;
|
|
9024
8974
|
wrapInTransaction?: boolean;
|
|
9025
8975
|
throwOnNotFound?: boolean;
|
|
8976
|
+
cteThrowOnNotFound?: boolean;
|
|
9026
8977
|
ensureCount?: number;
|
|
9027
8978
|
with?: WithItems;
|
|
9028
8979
|
withShapes?: WithConfigs;
|
|
@@ -9135,6 +9086,8 @@ interface QueryData extends QueryDataAliases, PickQueryDataParsers, HasHookSelec
|
|
|
9135
9086
|
/** upsert **/
|
|
9136
9087
|
upsertUpdate?: boolean;
|
|
9137
9088
|
upsertSecond?: boolean;
|
|
9089
|
+
upsertUpdateAsFns?: AsFn[];
|
|
9090
|
+
upsertCreateWith?: WithItems;
|
|
9138
9091
|
upsertCreateAppendQueries?: SubQueryForSql[];
|
|
9139
9092
|
upsertCreateAsFns?: AsFn[];
|
|
9140
9093
|
upsertInsert?(): unknown;
|
|
@@ -9220,13 +9173,13 @@ interface ToSQLQuery extends IsQuery {
|
|
|
9220
9173
|
}
|
|
9221
9174
|
interface FromQuerySelf extends PickQuerySelectable, PickQueryShape, PickQueryReturnType, PickQueryWithData, PickQueryAs, PickQueryHasSelect {}
|
|
9222
9175
|
type FromArg<T extends FromQuerySelf> = IsQuery | Exclude<keyof T['withData'], symbol | number>;
|
|
9223
|
-
type FromResult<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>> = Arg extends string ? T['withData'] extends WithDataItems ? { [K in keyof T]: K extends '__selectable' ? SelectableFromShape<T['withData'][Arg]['shape'], Arg> : K extends 'result' ? T['withData'][Arg]['shape'] : K extends 'then' ? QueryThenByQuery<T, T['withData'][Arg]['shape']> : T[K] } : SetQueryTableAlias<T, Arg> : Arg extends PickQuerySelectableResultInputTypeAs ? { [K in keyof T]: K extends '__defaultSelect' ? keyof Arg['result'] : K extends '__selectable' ? SelectableFromShape<Arg['result'], Arg['__as']> : K extends '__as' ? Arg['__as'] : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends '__inputType' ? Arg['__inputType'] : K extends 'then' ? QueryThenByQuery<T, Arg['result']> : T[K] } : Arg extends (infer A)[] ? { [K in keyof T]: K extends '__selectable' ? UnionToIntersection<A extends string ? T['withData'] extends WithDataItems ? { [K in keyof T['withData'][A]['shape'] & string as `${A}.${K}`]: {
|
|
9176
|
+
type FromResult<T extends FromQuerySelf, Arg extends MaybeArray<FromArg<T>>> = Arg extends string ? T['withData'] extends WithDataItems ? { [K in keyof T]: K extends '__selectable' ? SelectableFromShape<T['withData'][Arg]['shape'], Arg> : K extends 'result' ? T['withData'][Arg]['shape'] : K extends 'then' ? QueryThenByQuery<T, T['withData'][Arg]['shape']> : T[K]; } : SetQueryTableAlias<T, Arg> : Arg extends PickQuerySelectableResultInputTypeAs ? { [K in keyof T]: K extends '__defaultSelect' ? keyof Arg['result'] : K extends '__selectable' ? SelectableFromShape<Arg['result'], Arg['__as']> : K extends '__as' ? Arg['__as'] : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends '__inputType' ? Arg['__inputType'] : K extends 'then' ? QueryThenByQuery<T, Arg['result']> : T[K]; } : Arg extends (infer A)[] ? { [K in keyof T]: K extends '__selectable' ? UnionToIntersection<A extends string ? T['withData'] extends WithDataItems ? { [K in keyof T['withData'][A]['shape'] & string as `${A}.${K}`]: {
|
|
9224
9177
|
as: K;
|
|
9225
9178
|
column: T['withData'][A]['shape'][K];
|
|
9226
|
-
} } : never : A extends PickQueryResultAs ? { [K in keyof A['result'] & string as `${A['__as']}.${K}`]: K extends string ? {
|
|
9179
|
+
}; } : never : A extends PickQueryResultAs ? { [K in keyof A['result'] & string as `${A['__as']}.${K}`]: K extends string ? {
|
|
9227
9180
|
as: K;
|
|
9228
9181
|
column: A['result'][K];
|
|
9229
|
-
} : never } : never> : T[K] } : T;
|
|
9182
|
+
} : never; } : never> : T[K]; } : T;
|
|
9230
9183
|
declare class FromMethods {
|
|
9231
9184
|
/**
|
|
9232
9185
|
* Set the `FROM` value, by default the table name is used.
|
|
@@ -9303,11 +9256,11 @@ interface CteQueryBuilder<T extends PickQueryWithDataColumnTypes> extends Query
|
|
|
9303
9256
|
type CteResult<T extends PickQueryWithDataColumnTypes, Name extends string, Q extends PickQueryResult> = { [K in keyof T]: K extends 'withData' ? { [K in keyof T['withData'] | Name]: K extends Name ? {
|
|
9304
9257
|
table: Name;
|
|
9305
9258
|
shape: Q['result'];
|
|
9306
|
-
} : K extends keyof T['withData'] ? T['withData'][K] : never } : T[K] };
|
|
9259
|
+
} : K extends keyof T['withData'] ? T['withData'][K] : never; } : T[K]; };
|
|
9307
9260
|
type CteSqlResult<T extends PickQueryWithDataColumnTypes, Name extends string, Shape extends Column.QueryColumns> = { [K in keyof T]: K extends 'withData' ? { [K in Name | keyof T['withData']]: K extends Name ? {
|
|
9308
9261
|
table: Name;
|
|
9309
9262
|
shape: Shape;
|
|
9310
|
-
} : K extends keyof T['withData'] ? T['withData'][K] : never } : T[K] };
|
|
9263
|
+
} : K extends keyof T['withData'] ? T['withData'][K] : never; } : T[K]; };
|
|
9311
9264
|
declare const _prependWith: (q: Query, name: string | ((as: string) => void), queryArg: PickQueryResult | ((q: CteQueryBuilder<PickQueryWithDataColumnTypes>) => PickQueryResult)) => Query;
|
|
9312
9265
|
declare class CteQuery {
|
|
9313
9266
|
/**
|
|
@@ -9428,14 +9381,11 @@ declare class CteQuery {
|
|
|
9428
9381
|
* For the first example, consider the employee table, an employee may or may not have a manager.
|
|
9429
9382
|
*
|
|
9430
9383
|
* ```ts
|
|
9431
|
-
*
|
|
9432
|
-
*
|
|
9433
|
-
*
|
|
9434
|
-
*
|
|
9435
|
-
*
|
|
9436
|
-
* managerId: t.integer().nullable(),
|
|
9437
|
-
* }));
|
|
9438
|
-
* }
|
|
9384
|
+
* export const Employee = defineTable('employee', (t) => ({
|
|
9385
|
+
* id: t.identity().primaryKey(),
|
|
9386
|
+
* name: t.string(),
|
|
9387
|
+
* managerId: t.integer().nullable(),
|
|
9388
|
+
* }));
|
|
9439
9389
|
* ```
|
|
9440
9390
|
*
|
|
9441
9391
|
* The task is to load all subordinates of the manager with the id 1.
|
|
@@ -9501,8 +9451,8 @@ declare class CteQuery {
|
|
|
9501
9451
|
* .where({ n: { gt: 10 } });
|
|
9502
9452
|
* ```
|
|
9503
9453
|
*/
|
|
9504
|
-
withRecursive<T extends PickQueryWithDataColumnTypes, Name extends string, Q extends PickQueryResult, Result = CteResult<T, Name, Q>>(this: T, name: Name, base: Q | ((qb: CteQueryBuilder<T>) => Q), recursive: (qb: { [K in keyof Result]: K extends 'result' ? Q['result'] : Result[K] }) => PickQueryResult): Result;
|
|
9505
|
-
withRecursive<T extends PickQueryWithDataColumnTypes, Name extends string, Q extends PickQueryResult, Result = CteResult<T, Name, Q>>(this: T, name: Name, options: CteRecursiveOptions, base: Q | ((qb: CteQueryBuilder<T>) => Q), recursive: (qb: { [K in keyof Result]: K extends 'result' ? Q['result'] : Result[K] }) => PickQueryResult): Result;
|
|
9454
|
+
withRecursive<T extends PickQueryWithDataColumnTypes, Name extends string, Q extends PickQueryResult, Result = CteResult<T, Name, Q>>(this: T, name: Name, base: Q | ((qb: CteQueryBuilder<T>) => Q), recursive: (qb: { [K in keyof Result]: K extends 'result' ? Q['result'] : Result[K]; }) => PickQueryResult): Result;
|
|
9455
|
+
withRecursive<T extends PickQueryWithDataColumnTypes, Name extends string, Q extends PickQueryResult, Result = CteResult<T, Name, Q>>(this: T, name: Name, options: CteRecursiveOptions, base: Q | ((qb: CteQueryBuilder<T>) => Q), recursive: (qb: { [K in keyof Result]: K extends 'result' ? Q['result'] : Result[K]; }) => PickQueryResult): Result;
|
|
9506
9456
|
/**
|
|
9507
9457
|
* Use `withSql` to add a Common Table Expression (CTE) based on a custom SQL.
|
|
9508
9458
|
*
|
|
@@ -9562,7 +9512,7 @@ declare class CteQuery {
|
|
|
9562
9512
|
type UnionArgs<T extends PickQueryResult> = ({
|
|
9563
9513
|
result: { [K in keyof T['result']]: {
|
|
9564
9514
|
__queryType: T['result'][K]['__queryType'];
|
|
9565
|
-
} };
|
|
9515
|
+
}; };
|
|
9566
9516
|
} | ((q: T) => Expression))[];
|
|
9567
9517
|
declare class Union {
|
|
9568
9518
|
/**
|
|
@@ -9754,7 +9704,7 @@ declare class Having {
|
|
|
9754
9704
|
*/
|
|
9755
9705
|
havingSql<T>(this: T, ...args: SQLQueryArgs): T;
|
|
9756
9706
|
}
|
|
9757
|
-
type UpsertCreate<DataKey extends PropertyKey, CD> = { [K in keyof CD as K extends DataKey ? never : K]: CD[K] } & { [K in DataKey]?: K extends keyof CD ? CD[K] : never };
|
|
9707
|
+
type UpsertCreate<DataKey extends PropertyKey, CD> = { [K in keyof CD as K extends DataKey ? never : K]: CD[K]; } & { [K in DataKey]?: K extends keyof CD ? CD[K] : never; };
|
|
9758
9708
|
type UpsertResult<T extends PickQueryHasSelectResultReturnType> = T['__hasSelect'] extends true ? T['returnType'] extends 'value' | 'valueOrThrow' ? SetValueQueryReturnsValueOrThrow<T> : SetQueryReturnsOne<T> : SetQueryReturnsVoid<T>;
|
|
9759
9709
|
interface UpsertThis extends UpdateSelf, CreateSelf {
|
|
9760
9710
|
__hasWhere: true;
|
|
@@ -9921,7 +9871,7 @@ interface QueryPluckSelf extends PickQuerySelectable, PickQueryRelationsWithData
|
|
|
9921
9871
|
type PluckArg<T extends QueryPluckSelf> = SelectableOrExpression<T> | ((q: SelectAsFnArg<T>) => Expression | Query.Pick.SingleValueResult);
|
|
9922
9872
|
type PluckResult<T extends QueryPluckSelf, S extends PluckArg<T>> = S extends ((q: never) => infer R) ? R extends Expression ? SetQueryReturnsPluck<T, R> : R extends Query.Pick.SingleValueResult ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? {
|
|
9923
9873
|
pluck: R['result']['value'];
|
|
9924
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<R['result']['value']['__outputType'][]> : T[K] } : never : S extends SelectableOrExpression<T> ? SetQueryReturnsPluck<T, S> : never;
|
|
9874
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<R['result']['value']['__outputType'][]> : T[K]; } : never : S extends SelectableOrExpression<T> ? SetQueryReturnsPluck<T, S> : never;
|
|
9925
9875
|
declare class QueryPluck {
|
|
9926
9876
|
/**
|
|
9927
9877
|
* `.pluck` returns a single array of a single selected column values:
|
|
@@ -9935,7 +9885,7 @@ declare class QueryPluck {
|
|
|
9935
9885
|
pluck<T extends QueryPluckSelf, S extends PluckArg<T>>(this: T, select: S): PluckResult<T, S>;
|
|
9936
9886
|
}
|
|
9937
9887
|
interface MergeQueryArg extends PickQueryTable, PickQuerySelectable, PickQueryResult, PickQueryReturnType, PickQueryWithData, PickQueryWindows, PickQueryThen, PickQueryHasSelect, PickQueryHasWhere {}
|
|
9938
|
-
type MergeQuery<T extends MergeQueryArg, Q extends MergeQueryArg> = { [K in keyof T]: K extends '__hasWhere' | '__hasSelect' ? T[K] & Q[K] : K extends '__selectable' | 'windows' | 'withData' ? Q[K] & Omit<T[K], keyof Q[K]> : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? Q['returnType'] extends undefined ? T['returnType'] : Q['returnType'] : K extends 'then' ? Q['returnType'] extends undefined ? QueryThenByQuery<T, MergeQueryResult<T, Q>> : Q['returnType'] extends 'all' | 'one' | 'oneOrThrow' | 'rows' ? QueryThenByQuery<Q, MergeQueryResult<T, Q>> : Q['__hasSelect'] extends true ? Q['then'] : T['__hasSelect'] extends true ? T['then'] : Q['then'] : T[K] };
|
|
9888
|
+
type MergeQuery<T extends MergeQueryArg, Q extends MergeQueryArg> = { [K in keyof T]: K extends '__hasWhere' | '__hasSelect' ? T[K] & Q[K] : K extends '__selectable' | 'windows' | 'withData' ? Q[K] & Omit<T[K], keyof Q[K]> : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? Q['returnType'] extends undefined ? T['returnType'] : Q['returnType'] : K extends 'then' ? Q['returnType'] extends undefined ? QueryThenByQuery<T, MergeQueryResult<T, Q>> : Q['returnType'] extends 'all' | 'one' | 'oneOrThrow' | 'rows' ? QueryThenByQuery<Q, MergeQueryResult<T, Q>> : Q['__hasSelect'] extends true ? Q['then'] : T['__hasSelect'] extends true ? T['then'] : Q['then'] : T[K]; };
|
|
9939
9889
|
type MergeQueryResult<T extends PickQueryHasSelectResult, Q extends PickQueryHasSelectResult> = T['__hasSelect'] extends true ? Q['__hasSelect'] extends true ? Omit<T['result'], keyof Q['result']> & Q['result'] : T['result'] : Q['result'];
|
|
9940
9890
|
declare class MergeQueryMethods {
|
|
9941
9891
|
merge<T extends MergeQueryArg, Q extends MergeQueryArg>(this: T, q: Q): MergeQuery<T, Q>;
|
|
@@ -9989,7 +9939,7 @@ declare class QueryMap {
|
|
|
9989
9939
|
then: QueryThen<(infer Data)[]>;
|
|
9990
9940
|
} ? (input: Data, index: number, arr: Data[]) => Result : never : T extends {
|
|
9991
9941
|
then: QueryThen<(infer Data) | undefined>;
|
|
9992
|
-
} ? (input: Data, index: number, value: Data) => Result : never, thisArg?: unknown): Result extends RecordUnknown ? { [K in keyof T]: K extends 'result' ? { [K in keyof Result]: Column.Pick.QueryColumnOfType<Result[K]
|
|
9942
|
+
} ? (input: Data, index: number, value: Data) => Result : never, thisArg?: unknown): Result extends RecordUnknown ? { [K in keyof T]: K extends 'result' ? { [K in keyof Result]: Column.Pick.QueryColumnOfType<Result[K]>; } : K extends 'then' ? QueryThen<T['returnType'] extends QueryReturnTypeAll | 'pluck' ? Result[] : T['returnType'] extends QueryReturnTypeOptional ? Result | undefined : Result> : T[K]; } : { [K in keyof T]: K extends 'returnType' ? T['returnType'] extends QueryReturnTypeAll | 'pluck' ? 'pluck' : T['returnType'] extends 'one' ? 'value' : 'valueOrThrow' : K extends 'result' ? T['returnType'] extends QueryReturnTypeAll | 'pluck' ? {
|
|
9993
9943
|
pluck: Column.Pick.QueryColumnOfType<Result>;
|
|
9994
9944
|
} : T['returnType'] extends QueryReturnTypeOptional ? {
|
|
9995
9945
|
value: Column.Pick.QueryColumnOfType<Result | undefined>;
|
|
@@ -10001,7 +9951,7 @@ declare class QueryMap {
|
|
|
10001
9951
|
} : K extends 'then' ? QueryThen<T['returnType'] extends QueryReturnTypeAll | 'pluck' ? Result[] : T['returnType'] extends QueryReturnTypeOptional ? Result | undefined : T extends {
|
|
10002
9952
|
returnType: 'valueOrThrow';
|
|
10003
9953
|
then: QueryThen<unknown | null>;
|
|
10004
|
-
} ? Result | null : Result> : T[K] };
|
|
9954
|
+
} ? Result | null : Result> : T[K]; };
|
|
10005
9955
|
}
|
|
10006
9956
|
type OrCreateArg<Data> = Data | (() => Data);
|
|
10007
9957
|
declare function _orCreate<T extends PickQueryHasSelectResultReturnType>(query: T, data: unknown | FnUnknownToUnknown, updateData?: unknown, mergeData?: unknown): UpsertResult<T>;
|
|
@@ -10187,7 +10137,7 @@ declare class QueryExistsMethods {
|
|
|
10187
10137
|
*/
|
|
10188
10138
|
notExists<T extends QueryGetSelf>(this: T): SetQueryReturnsColumnOrThrow<T, BooleanQueryColumn>;
|
|
10189
10139
|
}
|
|
10190
|
-
type GroupArgs<T extends PickQueryResult> = ({ [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K }[keyof T['result']] | Expression)[];
|
|
10140
|
+
type GroupArgs<T extends PickQueryResult> = ({ [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' | 'runtimeComputed' ? never : K; }[keyof T['result']] | Expression)[];
|
|
10191
10141
|
interface QueryHelperQuery<T extends PickQuerySelectableShapeAs> extends MergeQueryArg {
|
|
10192
10142
|
returnType: QueryReturnType;
|
|
10193
10143
|
__selectable: Omit<T['__selectable'], `${T['__as']}.${Extract<keyof T['shape'], string>}`>;
|
|
@@ -10216,15 +10166,15 @@ type QueryHelperResult<T extends IsQueryHelper> = T['__result'];
|
|
|
10216
10166
|
interface NarrowTypeSelf extends PickQueryResultReturnType {
|
|
10217
10167
|
returnType: undefined | 'all' | 'one' | 'oneOrThrow' | 'value' | 'valueOrThrow' | 'pluck';
|
|
10218
10168
|
}
|
|
10219
|
-
type NarrowInvalidKeys<T extends PickQueryResult, Narrow> = { [K in keyof Narrow]: K extends keyof T['result'] ? Narrow[K] extends T['result'][K]['__outputType'] ? never : K : K }[keyof Narrow];
|
|
10169
|
+
type NarrowInvalidKeys<T extends PickQueryResult, Narrow> = { [K in keyof Narrow]: K extends keyof T['result'] ? Narrow[K] extends T['result'][K]['__outputType'] ? never : K : K; }[keyof Narrow];
|
|
10220
10170
|
interface NarrowValueTypeResult<T extends PickQueryResultReturnType, Narrow> extends Column.QueryColumns {
|
|
10221
|
-
value: { [K in keyof T['result']['value']]: K extends '__outputType' ? Narrow : T['result']['value'][K] };
|
|
10171
|
+
value: { [K in keyof T['result']['value']]: K extends '__outputType' ? Narrow : T['result']['value'][K]; };
|
|
10222
10172
|
}
|
|
10223
10173
|
interface NarrowPluckTypeResult<T extends PickQueryResultReturnType, Narrow> extends Column.QueryColumns {
|
|
10224
|
-
pluck: { [K in keyof T['result']['pluck']]: K extends '__outputType' ? Narrow extends unknown[] ? Narrow[number] : Narrow : T['result']['pluck'][K] };
|
|
10174
|
+
pluck: { [K in keyof T['result']['pluck']]: K extends '__outputType' ? Narrow extends unknown[] ? Narrow[number] : Narrow : T['result']['pluck'][K]; };
|
|
10225
10175
|
}
|
|
10226
|
-
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.
|
|
10227
|
-
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>;
|
|
10176
|
+
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.QueryColumnToOptional<R['result'][K]>; } : K extends 'then' ? QueryIfResultThen<T, R> : T[K]; };
|
|
10177
|
+
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>;
|
|
10228
10178
|
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 {}
|
|
10229
10179
|
declare class QueryMethods<ColumnTypes> {
|
|
10230
10180
|
/**
|
|
@@ -10665,14 +10615,14 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
10665
10615
|
*/
|
|
10666
10616
|
narrowType<T extends NarrowTypeSelf>(this: T): <Narrow>() => T['returnType'] extends undefined | 'all' | 'one' | 'oneOrThrow' ? [NarrowInvalidKeys<T, Narrow>] extends [never] ? { [K in keyof T]: K extends 'result' ? T['result'] & { [K in keyof Narrow]: {
|
|
10667
10617
|
__outputType: Narrow[K];
|
|
10668
|
-
} } : K extends 'then' ? QueryThenByQuery<T, T['result'] & { [K in keyof Narrow]: {
|
|
10618
|
+
}; } : K extends 'then' ? QueryThenByQuery<T, T['result'] & { [K in keyof Narrow]: {
|
|
10669
10619
|
__outputType: Narrow[K];
|
|
10670
|
-
} }> : T[K] } : `narrowType() error: provided type does not extend the '${NarrowInvalidKeys<T, Narrow> & string}' column type` : (T['returnType'] extends 'pluck' ? Narrow extends unknown[] ? Narrow[number] : Narrow : Narrow) extends (T['returnType'] extends 'pluck' ? T['result']['pluck']['__outputType'] : T['result']['value']['__outputType']) ? { [K in keyof T]: K extends 'result' ? T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow> : K extends 'then' ? QueryThenByQuery<T, T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow>> : T[K] } : 'narrowType() error: provided type does not extend the returning column column type';
|
|
10620
|
+
}; }> : T[K]; } : `narrowType() error: provided type does not extend the '${NarrowInvalidKeys<T, Narrow> & string}' column type` : (T['returnType'] extends 'pluck' ? Narrow extends unknown[] ? Narrow[number] : Narrow : Narrow) extends (T['returnType'] extends 'pluck' ? T['result']['pluck']['__outputType'] : T['result']['value']['__outputType']) ? { [K in keyof T]: K extends 'result' ? T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow> : K extends 'then' ? QueryThenByQuery<T, T['returnType'] extends 'value' | 'valueOrThrow' ? NarrowValueTypeResult<T, Narrow> : NarrowPluckTypeResult<T, Narrow>> : T[K]; } : 'narrowType() error: provided type does not extend the returning column column type';
|
|
10671
10621
|
if<T extends PickQueryResultReturnType, R extends PickQueryResult>(this: T, condition: boolean | null | undefined, fn: (q: T) => R & {
|
|
10672
10622
|
returnType: T['returnType'];
|
|
10673
10623
|
}): QueryIfResult<T, R>;
|
|
10674
10624
|
queryRelated<T extends PickQueryRelations, RelName extends keyof T['relations']>(this: T, relName: RelName, params: T['relations'][RelName]['params']): RelationQueryMaybeSingle<T['relations'][RelName]>;
|
|
10675
|
-
chain<T extends PickQuerySelectableShapeRelationsReturnTypeIsSubQuery, RelName extends keyof T['relations']>(this: T, relName: RelName): T['__subQuery'] extends true | undefined ? [T['returnType'], T['relations'][RelName]['returnsOne']] extends ['one' | 'oneOrThrow', true] ? { [K in keyof RelationQueryMaybeSingle<T['relations'][RelName]>]: K extends '__selectable' ? RelationQueryMaybeSingle<T['relations'][RelName]>['__selectable'] & Omit<T['__selectable'], keyof T['shape']> : RelationQueryMaybeSingle<T['relations'][RelName]>[K] } & IsSubQuery : JoinResultRequireMain<T['relations'][RelName]['query'], Omit<T['__selectable'], keyof T['shape']>> : T['relations'][RelName]['query'];
|
|
10625
|
+
chain<T extends PickQuerySelectableShapeRelationsReturnTypeIsSubQuery, RelName extends keyof T['relations']>(this: T, relName: RelName): T['__subQuery'] extends true | undefined ? [T['returnType'], T['relations'][RelName]['returnsOne']] extends ['one' | 'oneOrThrow', true] ? { [K in keyof RelationQueryMaybeSingle<T['relations'][RelName]>]: K extends '__selectable' ? RelationQueryMaybeSingle<T['relations'][RelName]>['__selectable'] & Omit<T['__selectable'], keyof T['shape']> : RelationQueryMaybeSingle<T['relations'][RelName]>[K]; } & IsSubQuery : JoinResultRequireMain<T['relations'][RelName]['query'], Omit<T['__selectable'], keyof T['shape']>> : T['relations'][RelName]['query'];
|
|
10676
10626
|
}
|
|
10677
10627
|
interface DbExtension {
|
|
10678
10628
|
name: string;
|
|
@@ -10697,10 +10647,10 @@ interface DbDomainArgRecord {
|
|
|
10697
10647
|
type SelectableFromShape<Shape extends Column.QueryColumns, Table extends string | undefined> = { [K in keyof Shape]: {
|
|
10698
10648
|
as: K;
|
|
10699
10649
|
column: Shape[K];
|
|
10700
|
-
} } & { [K in keyof Shape & string as `${Table}.${K}`]: {
|
|
10650
|
+
}; } & { [K in keyof Shape & string as `${Table}.${K}`]: {
|
|
10701
10651
|
as: K;
|
|
10702
10652
|
column: Shape[K];
|
|
10703
|
-
} };
|
|
10653
|
+
}; };
|
|
10704
10654
|
type QueryReturnType = QueryReturnTypeAll | 'one' | 'oneOrThrow' | 'rows' | 'pluck' | 'value' | 'valueOrThrow' | 'void';
|
|
10705
10655
|
type QueryReturnTypeAll = undefined | 'all';
|
|
10706
10656
|
type QueryReturnTypeOptional = 'one' | 'value';
|
|
@@ -10783,52 +10733,52 @@ declare namespace Query {
|
|
|
10783
10733
|
}
|
|
10784
10734
|
}
|
|
10785
10735
|
}
|
|
10786
|
-
type SelectableOfType<T extends PickQuerySelectable, Type> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['__type'] extends Type | null ? K : never }[keyof T['__selectable']];
|
|
10736
|
+
type SelectableOfType<T extends PickQuerySelectable, Type> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['__type'] extends Type | null ? K : never; }[keyof T['__selectable']];
|
|
10787
10737
|
type SelectableOrExpressionOfType<T extends PickQuerySelectable, C extends Column.Pick.Type> = SelectableOfType<T, C['__type']> | Expression<Column.Pick.QueryColumnOfType<C['__type'] | null>>;
|
|
10788
|
-
type SetQueryReturnsAll<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThenShallowSimplifyArr<ColumnsShape.Output<T['result']>> : T[K] } & QueryHasWhere;
|
|
10789
|
-
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;
|
|
10790
|
-
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] };
|
|
10791
|
-
type QueryManyTakeOptional<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnsShape.Output<T['result']>> : T[K] };
|
|
10792
|
-
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] };
|
|
10793
|
-
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] };
|
|
10794
|
-
type QueryManyTake<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K] };
|
|
10795
|
-
type SetQueryReturnsOne<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K] };
|
|
10796
|
-
type SetQueryReturnsOneResult<T extends PickQueryResult, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<Result>> : T[K] };
|
|
10797
|
-
type SetQueryReturnsRows<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnsShape.Output<T['result']>[keyof T['result']][][]> : T[K] };
|
|
10738
|
+
type SetQueryReturnsAll<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThenShallowSimplifyArr<ColumnsShape.Output<T['result']>> : T[K]; } & QueryHasWhere;
|
|
10739
|
+
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;
|
|
10740
|
+
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]; };
|
|
10741
|
+
type QueryManyTakeOptional<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThenShallowSimplifyOptional<ColumnsShape.Output<T['result']>> : T[K]; };
|
|
10742
|
+
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]; };
|
|
10743
|
+
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]; };
|
|
10744
|
+
type QueryManyTake<T extends PickQueryResultReturnType> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K]; };
|
|
10745
|
+
type SetQueryReturnsOne<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<T['result']>> : T[K]; };
|
|
10746
|
+
type SetQueryReturnsOneResult<T extends PickQueryResult, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThenShallowSimplify<ColumnsShape.Output<Result>> : T[K]; };
|
|
10747
|
+
type SetQueryReturnsRows<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnsShape.Output<T['result']>[keyof T['result']][][]> : T[K]; };
|
|
10798
10748
|
type SetQueryReturnsPluck<T extends PickQuerySelectable, S extends keyof T['__selectable'] | Expression> = S extends keyof T['__selectable'] ? { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? {
|
|
10799
10749
|
pluck: T['__selectable'][S]['column'];
|
|
10800
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['__selectable'][S]['column']['__outputType'][]> : T[K] } : { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? {
|
|
10750
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['__selectable'][S]['column']['__outputType'][]> : T[K]; } : { [K in keyof T]: K extends '__hasSelect' ? true : K extends 'result' ? {
|
|
10801
10751
|
pluck: S extends Expression ? S['result']['value'] : never;
|
|
10802
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<(S extends Expression ? S['result']['value']['__outputType'] : never)[]> : T[K] };
|
|
10752
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<(S extends Expression ? S['result']['value']['__outputType'] : never)[]> : T[K]; };
|
|
10803
10753
|
type SetValueQueryReturnsPluckColumn<T extends PickQueryResult> = { [K in keyof T]: K extends 'result' ? {
|
|
10804
10754
|
pluck: T['result']['value'];
|
|
10805
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['__outputType'][]> : T[K] } & QueryHasSelect;
|
|
10755
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['__outputType'][]> : T[K]; } & QueryHasSelect;
|
|
10806
10756
|
type SetQueryReturnsPluckColumnResult<T extends PickQueryResult, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'result' ? {
|
|
10807
10757
|
pluck: T['result']['value'];
|
|
10808
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'result' ? Result : K extends 'then' ? QueryThen<T['result']['value']['__outputType'][]> : T[K] } & QueryHasSelect;
|
|
10758
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'result' ? Result : K extends 'then' ? QueryThen<T['result']['value']['__outputType'][]> : T[K]; } & QueryHasSelect;
|
|
10809
10759
|
type SetQueryReturnsValueOrThrow<T extends PickQuerySelectable, Arg extends keyof T['__selectable']> = SetQueryReturnsColumnOrThrow<T, T['__selectable'][Arg]['column']> & T['__selectable'][Arg]['column']['operators'];
|
|
10810
|
-
type SetValueQueryReturnsValueOrThrow<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['value']['__outputType']> : T[K] };
|
|
10811
|
-
type SetQueryReturnsValueOptional<T extends PickQuerySelectable, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, { [K in keyof T['__selectable'][Arg]['column']]: K extends '__outputType' ? T['__selectable'][Arg]['column'][K] | undefined : T['__selectable'][Arg]['column'][K] }> & Omit<T['__selectable'][Arg]['column']['operators'], 'equals' | 'not'> & Column.
|
|
10760
|
+
type SetValueQueryReturnsValueOrThrow<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['value']['__outputType']> : T[K]; };
|
|
10761
|
+
type SetQueryReturnsValueOptional<T extends PickQuerySelectable, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, { [K in keyof T['__selectable'][Arg]['column']]: K extends '__outputType' ? T['__selectable'][Arg]['column'][K] | undefined : T['__selectable'][Arg]['column'][K]; }> & Omit<T['__selectable'][Arg]['column']['operators'], 'equals' | 'not'> & Column.OperatorsNullable<T['__selectable'][Arg]['column']>;
|
|
10812
10762
|
type SetQueryReturnsColumnOrThrow<T, Column extends Column.Pick.OutputType> = { [K in keyof T]: K extends 'result' ? {
|
|
10813
10763
|
value: Column;
|
|
10814
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['__outputType']> : T[K] } & QueryHasSelect;
|
|
10764
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['__outputType']> : T[K]; } & QueryHasSelect;
|
|
10815
10765
|
type SetQueryReturnsColumnOptional<T, Column extends Column.Pick.OutputType> = { [K in keyof T]: K extends 'result' ? {
|
|
10816
10766
|
value: Column;
|
|
10817
|
-
} : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['__outputType'] | undefined> : T[K] } & QueryHasSelect;
|
|
10767
|
+
} : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['__outputType'] | undefined> : T[K]; } & QueryHasSelect;
|
|
10818
10768
|
type SetQueryReturnsColumn<T extends PickQueryResult> = { [K in keyof T]: K extends 'result' ? {
|
|
10819
10769
|
value: T['result']['pluck'];
|
|
10820
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['__outputType']> : T[K] } & QueryHasSelect;
|
|
10770
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['__outputType']> : T[K]; } & QueryHasSelect;
|
|
10821
10771
|
type SetQueryReturnsColumnResult<T extends PickQueryResult, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'result' ? {
|
|
10822
10772
|
value: T['result']['pluck'];
|
|
10823
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThen<Result['pluck']['__outputType']> : T[K] } & QueryHasSelect;
|
|
10773
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? Result : K extends 'then' ? QueryThen<Result['pluck']['__outputType']> : T[K]; } & QueryHasSelect;
|
|
10824
10774
|
type SetQueryReturnsRowCount<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
10825
10775
|
value: Column.Pick.QueryColumnOfType<number>;
|
|
10826
|
-
} : K extends 'then' ? QueryThen<number> : T[K] };
|
|
10776
|
+
} : K extends 'then' ? QueryThen<number> : T[K]; };
|
|
10827
10777
|
type SetQueryReturnsRowCountMany<T extends PickQueryResult> = { [K in keyof T]: K extends 'returnType' ? 'pluck' : K extends 'result' ? {
|
|
10828
10778
|
pluck: Column.Pick.QueryColumnOfType<number>;
|
|
10829
|
-
} : K extends 'then' ? QueryThen<number> : T[K] };
|
|
10830
|
-
type SetQueryReturnsVoid<T> = { [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K] };
|
|
10831
|
-
type SetQueryResult<T extends PickQueryReturnType, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'result' ? Result : K extends 'then' ? QueryThenByQuery<T, Result> : T[K] };
|
|
10779
|
+
} : K extends 'then' ? QueryThen<number> : T[K]; };
|
|
10780
|
+
type SetQueryReturnsVoid<T> = { [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K]; };
|
|
10781
|
+
type SetQueryResult<T extends PickQueryReturnType, Result extends Column.QueryColumns> = { [K in keyof T]: K extends 'result' ? Result : K extends 'then' ? QueryThenByQuery<T, Result> : T[K]; };
|
|
10832
10782
|
interface ReturnsQueryOrExpression<T> {
|
|
10833
10783
|
(): QueryOrExpression<T>;
|
|
10834
10784
|
}
|
|
@@ -11000,7 +10950,7 @@ interface QueryDataAliases extends PickQueryDataAliases {
|
|
|
11000
10950
|
type SetQueryTableAlias<T extends PickQuerySelectableShapeAs, As extends string> = { [K in keyof T]: K extends '__selectable' ? Omit<T['__selectable'], `${T['__as']}.${keyof T['shape'] & string}`> & { [K in keyof T['shape'] & string as `${As}.${K}`]: {
|
|
11001
10951
|
as: K;
|
|
11002
10952
|
column: T['shape'][K];
|
|
11003
|
-
} } : K extends '__as' ? As : T[K] };
|
|
10953
|
+
}; } : K extends '__as' ? As : T[K]; };
|
|
11004
10954
|
type AsQueryArg = PickQuerySelectableShapeAs;
|
|
11005
10955
|
/** getters **/
|
|
11006
10956
|
declare const getQueryAs: (q: {
|
|
@@ -11026,6 +10976,8 @@ declare abstract class QueryAsMethods {
|
|
|
11026
10976
|
}
|
|
11027
10977
|
declare const _appendQuery: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
11028
10978
|
declare const _appendQueryOnUpsertCreate: (main: Query, append: Query, asFn: (as: string) => void) => Query;
|
|
10979
|
+
declare const _onUpsertUpdate: (q: Query, asFn: (as: string) => void) => Query;
|
|
10980
|
+
declare const _prependWithOnUpsertCreate: (q: Query, name: string | ((as: string) => void), query: Query) => void;
|
|
11029
10981
|
interface RefreshMaterializedViewOptions {
|
|
11030
10982
|
/**
|
|
11031
10983
|
* Refresh the materialized view without blocking concurrent selects.
|
|
@@ -11062,7 +11014,7 @@ declare const escapeString: (value: string) => string;
|
|
|
11062
11014
|
* Sets query kind to 'columnInfo', returns a single value (may return undefined),
|
|
11063
11015
|
* the value is a {@link GetColumnInfo} object or a Record with keys for column names and ColumnInfo objects as values.
|
|
11064
11016
|
**/
|
|
11065
|
-
type SetQueryReturnsColumnInfo<T extends PickQueryShape, Column extends keyof T['shape'] | undefined, Result =
|
|
11017
|
+
type SetQueryReturnsColumnInfo<T extends PickQueryShape, Column extends keyof T['shape'] | undefined, Result = Column extends keyof T['shape'] ? GetColumnInfo : { [K in keyof T['shape']]: GetColumnInfo; }> = Omit<T, 'result' | 'returnType' | 'then'> & {
|
|
11066
11018
|
result: {
|
|
11067
11019
|
value: Column.Pick.QueryColumnOfType<Result>;
|
|
11068
11020
|
};
|
|
@@ -11195,4 +11147,4 @@ declare const testTransaction: {
|
|
|
11195
11147
|
*/
|
|
11196
11148
|
close(arg: Arg$1): Promise<void>;
|
|
11197
11149
|
};
|
|
11198
|
-
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 };
|
|
11150
|
+
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 ColumnRefExpression, 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, type DateColumnInput, 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 OperatorsDate, type OperatorsJson, type OperatorsNumber, 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 SelectSqlColumn, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StaticSQLArgs, 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, _onUpsertUpdate, _orCreate, _prependWith, _prependWithOnUpsertCreate, _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, constraintToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, indexToCode, 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 };
|