kysely-hydrate 0.6.0 → 0.7.2
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/README.md +111 -13
- package/dist/index.d.mts +109 -9
- package/dist/index.mjs +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,6 +136,7 @@ type Result = Array<{
|
|
|
136
136
|
- [Output transformations with `.map()`](#output-transformations-with-map)
|
|
137
137
|
- [Composable mappings with `.with()`](#composable-mappings-with-with)
|
|
138
138
|
- [Hydrated writes](#hydrated-writes)
|
|
139
|
+
- [Type helpers](#type-helpers)
|
|
139
140
|
- [Hydrators](#hydrators)
|
|
140
141
|
- [Creating hydrators with `createHydrator()`](#creating-hydrators-with-createhydrator)
|
|
141
142
|
- [Manual hydration with `hydrate()`](#manual-hydration-with-hydrate)
|
|
@@ -388,11 +389,12 @@ const result = await querySet(db)
|
|
|
388
389
|
|
|
389
390
|
###### Generated SQL strategy:
|
|
390
391
|
|
|
391
|
-
1 **Inner Query**: Selects the parent rows, applying the `LIMIT 10` here. This
|
|
392
|
-
inner query will include "cardinality-one" joins (`*One()`), so you can use them
|
|
393
|
-
in filtering. "Cardinality-many" filtering joins (`innerJoinMany` or
|
|
394
|
-
`crossJoinMany`) will be converted to a WHERE EXISTS to filter without causing
|
|
395
|
-
row explosion.
|
|
392
|
+
1. **Inner Query**: Selects the parent rows, applying the `LIMIT 10` here. This
|
|
393
|
+
inner query will include "cardinality-one" joins (`*One()`), so you can use them
|
|
394
|
+
in filtering. "Cardinality-many" filtering joins (`innerJoinMany` or
|
|
395
|
+
`crossJoinMany`) will be converted to a `WHERE EXISTS` to filter without causing
|
|
396
|
+
row explosion.
|
|
397
|
+
2. **Outer Query**: Joins the "many" relations to the limited set of parents.
|
|
396
398
|
|
|
397
399
|
For example, a query for "users who have posted" looks something like this:
|
|
398
400
|
|
|
@@ -544,7 +546,7 @@ Kysely Hydrate how to match the attached rows back to their parents:
|
|
|
544
546
|
- `matchChild`: the key (or keys) on the attached rows
|
|
545
547
|
- `toParent` (optional): the key (or keys) on the parent rows
|
|
546
548
|
|
|
547
|
-
If you omit `toParent`, it defaults to the parent collection
|
|
549
|
+
If you omit `toParent`, it defaults to the parent collection's `keyBy` (which
|
|
548
550
|
itself defaults to `"id"` when available).
|
|
549
551
|
|
|
550
552
|
```ts
|
|
@@ -596,7 +598,7 @@ type Result = Array<{
|
|
|
596
598
|
```
|
|
597
599
|
|
|
598
600
|
Because the `fetchFn` can be any async function, `.attachMany()` is also useful
|
|
599
|
-
for things that _aren
|
|
601
|
+
for things that _aren't_ database rows: HTTP calls, caches, etc.
|
|
600
602
|
|
|
601
603
|
```ts
|
|
602
604
|
// Example: Attach feature flags from a cached HTTP endpoint
|
|
@@ -1090,9 +1092,105 @@ type Result = {
|
|
|
1090
1092
|
};
|
|
1091
1093
|
```
|
|
1092
1094
|
|
|
1095
|
+
### Type Helpers
|
|
1096
|
+
|
|
1097
|
+
Kysely Hydrate provides type helpers that mirror
|
|
1098
|
+
[Kysely's type manipulation methods](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html).
|
|
1099
|
+
These methods don't change the SQL or have any runtime effect—they only affect TypeScript types.
|
|
1100
|
+
|
|
1101
|
+
#### `$castTo<T>()`
|
|
1102
|
+
|
|
1103
|
+
Changes the output type of the query. Use this when you know the actual output type better than
|
|
1104
|
+
TypeScript can infer. This is unsafe! You can change the type to anything.
|
|
1105
|
+
|
|
1106
|
+
```ts
|
|
1107
|
+
const users = await querySet(db)
|
|
1108
|
+
.selectAs("user", db.selectFrom("users").select(["id", "name"]))
|
|
1109
|
+
.$castTo<{ id: number; name: string; extra: boolean }>()
|
|
1110
|
+
.execute();
|
|
1111
|
+
// ⬇
|
|
1112
|
+
type Result = Array<{
|
|
1113
|
+
id: number;
|
|
1114
|
+
name: string;
|
|
1115
|
+
extra: boolean; // You better be sure this is there!
|
|
1116
|
+
}>;
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
See [Kysely's version](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#castto).
|
|
1120
|
+
|
|
1121
|
+
#### `$narrowType<T>()`
|
|
1122
|
+
|
|
1123
|
+
Narrows parts of the output type. Useful after `WHERE` clauses that guarantee a
|
|
1124
|
+
nullable column is not null.
|
|
1125
|
+
|
|
1126
|
+
```ts
|
|
1127
|
+
const users = await querySet(db)
|
|
1128
|
+
.selectAs("user", db.selectFrom("users").select(["id", "avatar_url"]))
|
|
1129
|
+
.where("avatar_url", "is not", null)
|
|
1130
|
+
.$narrowType<{ avatar_url: string }>(); // Remove null from the type
|
|
1131
|
+
.execute()
|
|
1132
|
+
// ⬇
|
|
1133
|
+
type Result = Array<{
|
|
1134
|
+
id: string;
|
|
1135
|
+
avatar_url: string; // No `| null`!
|
|
1136
|
+
}>
|
|
1137
|
+
```
|
|
1138
|
+
|
|
1139
|
+
You can also use Kysely's `NotNull` type:
|
|
1140
|
+
|
|
1141
|
+
```ts
|
|
1142
|
+
import type { NotNull } from "kysely";
|
|
1143
|
+
|
|
1144
|
+
const users = await querySet(db)
|
|
1145
|
+
.selectAs("user", db.selectFrom("users").select(["id", "avatar_url"]))
|
|
1146
|
+
.where("avatar_url", "is not", null)
|
|
1147
|
+
.$narrowType<{ avatar_url: NotNull }>();
|
|
1148
|
+
.execute()
|
|
1149
|
+
// ⬇
|
|
1150
|
+
type Result = Array<{
|
|
1151
|
+
id: string;
|
|
1152
|
+
avatar_url: string; // No `| null`!
|
|
1153
|
+
}>
|
|
1154
|
+
```
|
|
1155
|
+
|
|
1156
|
+
See [Kysely's version](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#narrowtype).
|
|
1157
|
+
|
|
1158
|
+
#### `$assertType<T>()`
|
|
1159
|
+
|
|
1160
|
+
Asserts that the query's output type equals a given type. Unlike `$castTo`, this
|
|
1161
|
+
validates structural equality—if the types don't match, you get a compile error. Useful as a strategy for annotating your query sets with their expected return type, and also useful if you run into a dreaded "excessively deep" type instantiation error.
|
|
1162
|
+
|
|
1163
|
+
```ts
|
|
1164
|
+
type UserDto = { id: number; name: string };
|
|
1165
|
+
|
|
1166
|
+
const users = await querySet(db)
|
|
1167
|
+
.selectAs("user", db.selectFrom("users").select(["id", "name"]))
|
|
1168
|
+
.$assertType<UserDto>(); // Compile error if output doesn't match UserDto
|
|
1169
|
+
.execute();
|
|
1170
|
+
// ⬇
|
|
1171
|
+
type Result = Array<UserDto>
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
See [Kysely's version](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#asserttype).
|
|
1175
|
+
|
|
1176
|
+
#### `InferOutput<T>`
|
|
1177
|
+
|
|
1178
|
+
A type-level helper to extract the output type of a query set.
|
|
1179
|
+
|
|
1180
|
+
```ts
|
|
1181
|
+
import type { InferOutput } from "kysely-hydrate";
|
|
1182
|
+
|
|
1183
|
+
const usersQuery = querySet(db)
|
|
1184
|
+
.selectAs("user", db.selectFrom("users").select(["id", "name"]))
|
|
1185
|
+
.extras({ upperName: (u) => u.name.toUpperCase() });
|
|
1186
|
+
|
|
1187
|
+
type User = InferOutput<typeof usersQuery>;
|
|
1188
|
+
// type User = { id: number; name: string; upperName: string }
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1093
1191
|
## Hydrators
|
|
1094
1192
|
|
|
1095
|
-
The `querySet()` API described above is the happy path when you
|
|
1193
|
+
The `querySet()` API described above is the happy path when you're building a
|
|
1096
1194
|
query in Kysely and want nested results.
|
|
1097
1195
|
|
|
1098
1196
|
Hydrators are the lower-level API: they let you take _already-fetched_ rows
|
|
@@ -1105,7 +1203,7 @@ Use hydrators when:
|
|
|
1105
1203
|
- You want to define reusable hydration logic independent of any particular query.
|
|
1106
1204
|
|
|
1107
1205
|
> [!NOTE]
|
|
1108
|
-
> Hydrators don
|
|
1206
|
+
> Hydrators don't "know" what you selected. Unlike `querySet()`, you need to
|
|
1109
1207
|
> specify what you want in the output using `.fields()` (and/or `.extras()`).
|
|
1110
1208
|
|
|
1111
1209
|
### Creating hydrators with `createHydrator()`
|
|
@@ -1276,7 +1374,7 @@ mapped.extend(...); // Error: Property 'extend' does not exist
|
|
|
1276
1374
|
### Attached collections with `.attach*()`
|
|
1277
1375
|
|
|
1278
1376
|
These work the same as in the `querySet()` API (see the `.attach*()` section above).
|
|
1279
|
-
They
|
|
1377
|
+
They're useful when your "rows" come from somewhere other than SQL, but you still
|
|
1280
1378
|
want to batch-fetch and attach related data.
|
|
1281
1379
|
|
|
1282
1380
|
### Prefixed collections with `.has*()`
|
|
@@ -1329,11 +1427,11 @@ know the difference, and so does not suffer from this problem.
|
|
|
1329
1427
|
|
|
1330
1428
|
Merges two hydrators. The second hydrator's configuration takes precedence.
|
|
1331
1429
|
|
|
1332
|
-
This is a good way to build small, reusable hydrators (for a
|
|
1333
|
-
|
|
1430
|
+
This is a good way to build small, reusable hydrators (for a "user preview", a
|
|
1431
|
+
"user display name", etc.) and compose them.
|
|
1334
1432
|
|
|
1335
1433
|
> [!NOTE]
|
|
1336
|
-
> Hydrators must have the same `keyBy`. If they don
|
|
1434
|
+
> Hydrators must have the same `keyBy`. If they don't, `.extend()` throws.
|
|
1337
1435
|
|
|
1338
1436
|
```ts
|
|
1339
1437
|
type UserRow = { id: number; username: string; email: string };
|
package/dist/index.d.mts
CHANGED
|
@@ -22,7 +22,24 @@ type SelectAndStripPrefix<P extends string, T> = { [K in keyof T as K extends `$
|
|
|
22
22
|
type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
|
|
23
23
|
type Identity<T> = T;
|
|
24
24
|
type Flatten<T> = Identity<{ [k in keyof T]: T[k] }>;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Type-level error message. Cloned from Kysely since it's not exported.
|
|
27
|
+
*/
|
|
28
|
+
interface TypeErrorMessage<E extends string> {
|
|
29
|
+
readonly __typeError__: E;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Narrows a type by intersecting with another type, with validation.
|
|
33
|
+
* Cloned from Kysely's NarrowPartial since it's not exported.
|
|
34
|
+
*
|
|
35
|
+
* Unlike a simple intersection, this:
|
|
36
|
+
* - Validates that narrowing types are subsets of original types
|
|
37
|
+
* - Supports `k.NotNull` to exclude null from nullable fields
|
|
38
|
+
* - Produces readable error messages for invalid narrowing
|
|
39
|
+
*/
|
|
40
|
+
type NarrowPartial<O$1, T> = DrainOuterGeneric<T extends object ? { [K in keyof O$1 & string]: K extends keyof T ? T[K] extends k.NotNull ? Exclude<O$1[K], null> : T[K] extends O$1[K] ? T[K] : TypeErrorMessage<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : O$1[K] } : never>;
|
|
41
|
+
type Extend<A, B> = Flatten<RawExtend<A, B>>;
|
|
42
|
+
type RawExtend<A, B> = keyof A & keyof B extends never ? A & B : { [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never };
|
|
26
43
|
type ExtendWith<T, K$1 extends PropertyKey, V> = Flatten<K$1 & keyof T extends never ? T & { [_ in K$1]: V } : Omit<T, K$1> & { [_ in K$1]: V }>;
|
|
27
44
|
/**
|
|
28
45
|
* Ensures that U is a strict subset of T - all keys in U must exist in T
|
|
@@ -566,13 +583,18 @@ interface TQuerySet {
|
|
|
566
583
|
* The final shape of the hydrated output row.
|
|
567
584
|
*/
|
|
568
585
|
HydratedOutput: any;
|
|
586
|
+
/**
|
|
587
|
+
* Keys that have been omitted from the output. Tracked separately so they
|
|
588
|
+
* can be preserved through base query changes (e.g., .insert(), .update()).
|
|
589
|
+
*/
|
|
590
|
+
OmittedKeys: PropertyKey;
|
|
569
591
|
}
|
|
570
592
|
interface TSelectQuerySet extends TQuerySet {
|
|
571
593
|
BaseQuery: TSelectQuery;
|
|
572
594
|
}
|
|
573
595
|
type QuerySetFor<T extends TQuerySet> = T["IsMapped"] extends true ? MappedQuerySet<T> : QuerySet<T>;
|
|
574
596
|
type TInput<T extends TQuerySet> = T["JoinedQuery"]["O"];
|
|
575
|
-
type TOutput<T extends TQuerySet> =
|
|
597
|
+
type TOutput<T extends TQuerySet> = T["HydratedOutput"];
|
|
576
598
|
interface TMapped<in out T extends TQuerySet, in out Output> {
|
|
577
599
|
DB: T["DB"];
|
|
578
600
|
IsMapped: true;
|
|
@@ -582,6 +604,7 @@ interface TMapped<in out T extends TQuerySet, in out Output> {
|
|
|
582
604
|
JoinedQuery: T["JoinedQuery"];
|
|
583
605
|
OrderableColumns: T["OrderableColumns"];
|
|
584
606
|
HydratedOutput: Output;
|
|
607
|
+
OmittedKeys: T["OmittedKeys"];
|
|
585
608
|
}
|
|
586
609
|
interface TJoinedQueryWithBaseQuery<in out BaseAlias extends string, in out JoinedQuery extends TQuery, in out BaseQuery extends TQuery> {
|
|
587
610
|
Type: "Select";
|
|
@@ -598,7 +621,8 @@ interface TWithBaseQuery<in out T extends TQuerySet, in out BaseQuery extends TQ
|
|
|
598
621
|
Collections: T["Collections"];
|
|
599
622
|
JoinedQuery: TJoinedQueryWithBaseQuery<T["BaseAlias"], T["JoinedQuery"], BaseQuery>;
|
|
600
623
|
OrderableColumns: T["OrderableColumns"] | (keyof BaseQuery["O"] & string);
|
|
601
|
-
HydratedOutput:
|
|
624
|
+
HydratedOutput: Flatten<Omit<RawExtend<BaseQuery["O"], T["HydratedOutput"]>, T["OmittedKeys"]>>;
|
|
625
|
+
OmittedKeys: T["OmittedKeys"];
|
|
602
626
|
}
|
|
603
627
|
interface TWithOutput<in out T extends TQuerySet, in out Output> {
|
|
604
628
|
DB: T["DB"];
|
|
@@ -609,6 +633,7 @@ interface TWithOutput<in out T extends TQuerySet, in out Output> {
|
|
|
609
633
|
JoinedQuery: T["JoinedQuery"];
|
|
610
634
|
OrderableColumns: T["OrderableColumns"];
|
|
611
635
|
HydratedOutput: Output;
|
|
636
|
+
OmittedKeys: T["OmittedKeys"];
|
|
612
637
|
}
|
|
613
638
|
interface TWithExtendedOutput<in out T extends TQuerySet, in out Output> {
|
|
614
639
|
DB: T["DB"];
|
|
@@ -619,7 +644,20 @@ interface TWithExtendedOutput<in out T extends TQuerySet, in out Output> {
|
|
|
619
644
|
JoinedQuery: T["JoinedQuery"];
|
|
620
645
|
OrderableColumns: T["OrderableColumns"];
|
|
621
646
|
HydratedOutput: Extend<T["HydratedOutput"], Output>;
|
|
647
|
+
OmittedKeys: T["OmittedKeys"];
|
|
648
|
+
}
|
|
649
|
+
interface TWithOmit<in out T extends TQuerySet, in out K$1 extends PropertyKey> {
|
|
650
|
+
DB: T["DB"];
|
|
651
|
+
IsMapped: T["IsMapped"];
|
|
652
|
+
BaseAlias: T["BaseAlias"];
|
|
653
|
+
BaseQuery: T["BaseQuery"];
|
|
654
|
+
Collections: T["Collections"];
|
|
655
|
+
JoinedQuery: T["JoinedQuery"];
|
|
656
|
+
OrderableColumns: T["OrderableColumns"];
|
|
657
|
+
HydratedOutput: Flatten<Omit<T["HydratedOutput"], K$1>>;
|
|
658
|
+
OmittedKeys: T["OmittedKeys"] | K$1;
|
|
622
659
|
}
|
|
660
|
+
type NarrowOutput<T extends TQuerySet, Narrow> = NarrowPartial<T["HydratedOutput"], Narrow>;
|
|
623
661
|
interface InitialJoinedQuery<in out DB$1, in out BaseAlias extends string, in out BaseO> {
|
|
624
662
|
Type: "Select";
|
|
625
663
|
DB: DB$1 & { [K in BaseAlias]: BaseO };
|
|
@@ -649,6 +687,32 @@ type OpaqueExistsQueryBuilder = OpaqueSelectQueryBuilder<{
|
|
|
649
687
|
* A limit or offset value, passable to `.limit()` and `.offset()`.
|
|
650
688
|
*/
|
|
651
689
|
type LimitOrOffset = number | bigint | null;
|
|
690
|
+
/**
|
|
691
|
+
* Infer the output type of a query set. This is the type of one hydrated row. It's the same as
|
|
692
|
+
* the type returned by `.executeTakeFirstOrThrow()`.
|
|
693
|
+
*
|
|
694
|
+
* **Example:**
|
|
695
|
+
* ```ts
|
|
696
|
+
* const usersQuerySet = querySet(db)
|
|
697
|
+
* .selectAs("user", db.selectFrom("users").select(["id", "username"]))
|
|
698
|
+
*
|
|
699
|
+
* type User = InferOutput<typeof usersQuerySet>;
|
|
700
|
+
* // ⬇
|
|
701
|
+
* type User = { id: number; username: string };
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
type InferOutput<Q extends {
|
|
705
|
+
_generics: TQuerySet | undefined;
|
|
706
|
+
}> = Q extends {
|
|
707
|
+
_generics: {
|
|
708
|
+
HydratedOutput: infer O;
|
|
709
|
+
} | undefined;
|
|
710
|
+
} ? O : never;
|
|
711
|
+
/**
|
|
712
|
+
* Given a TQuerySet, return a QuerySet or MappedQuerySet depending on whether the query set has
|
|
713
|
+
* been mapped (indicated by T["IsMapped"]).
|
|
714
|
+
*/
|
|
715
|
+
type MaybeMappedQuerySet<T extends TQuerySet> = T["IsMapped"] extends true ? MappedQuerySet<T> : QuerySet<T>;
|
|
652
716
|
/**
|
|
653
717
|
* A query set that has been mapped with a transformation function.
|
|
654
718
|
*
|
|
@@ -1176,6 +1240,39 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
|
|
|
1176
1240
|
* Calls a callback with the query set and returns the result. Like {@link k.SelectQueryBuilder.$call}.
|
|
1177
1241
|
*/
|
|
1178
1242
|
$call<R>(callback: (qs: this) => R): R;
|
|
1243
|
+
/**
|
|
1244
|
+
* Changes the output type of the query.
|
|
1245
|
+
*
|
|
1246
|
+
* This method call doesn't change the SQL in any way. This method simply
|
|
1247
|
+
* returns a copy of this query set with a new output type.
|
|
1248
|
+
*/
|
|
1249
|
+
$castTo<NewOutput>(): MaybeMappedQuerySet<TWithOutput<T, NewOutput>>;
|
|
1250
|
+
/**
|
|
1251
|
+
* Narrows (parts of) the output type of the query.
|
|
1252
|
+
*
|
|
1253
|
+
* This method call doesn't change the SQL in any way. This method simply
|
|
1254
|
+
* returns a copy of this query set with a narrowed output type.
|
|
1255
|
+
*
|
|
1256
|
+
* See {@link k.SelectQueryBuilder.$narrowType} for more information.
|
|
1257
|
+
*/
|
|
1258
|
+
$narrowType<Narrow>(): MaybeMappedQuerySet<TWithOutput<T, NarrowOutput<T, Narrow>>>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
1261
|
+
*
|
|
1262
|
+
* This method can be used to simplify excessively complex types to make
|
|
1263
|
+
* TypeScript happy and faster.
|
|
1264
|
+
*
|
|
1265
|
+
* It's also useful as a type guard to ensure a query set matches an expected
|
|
1266
|
+
* shape, similar to annotating a function's return type. For example,
|
|
1267
|
+
* `.$assertType<UserDto>()` will produce a type error if the query's output
|
|
1268
|
+
* doesn't match `UserDto`.
|
|
1269
|
+
*
|
|
1270
|
+
* Using this method doesn't reduce type safety at all. You have to pass in
|
|
1271
|
+
* a type that is structurally equal to the current type.
|
|
1272
|
+
*
|
|
1273
|
+
* See {@link k.SelectQueryBuilder.$assertType} for more information.
|
|
1274
|
+
*/
|
|
1275
|
+
$assertType<NewOutput extends TOutput<T>>(): TOutput<T> extends NewOutput ? MaybeMappedQuerySet<TWithOutput<T, NewOutput>> : TypeErrorMessage<"$assertType() call failed: The type passed in is not equal to the output type of the query.">;
|
|
1179
1276
|
/**
|
|
1180
1277
|
* Switches the base query to an `INSERT` statement.
|
|
1181
1278
|
*
|
|
@@ -1209,15 +1306,15 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
|
|
|
1209
1306
|
* @param iqb - An insert query builder or factory function.
|
|
1210
1307
|
* @returns A new QuerySet with the insert query as the base.
|
|
1211
1308
|
*/
|
|
1212
|
-
insert<IQB extends k.InsertQueryBuilder<any, any, T["BaseQuery"]["O"]>>(iqb: InsertQueryBuilderOrFactory<T["DB"], IQB>):
|
|
1309
|
+
insert<IQB extends k.InsertQueryBuilder<any, any, T["BaseQuery"]["O"]>>(iqb: InsertQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTInsertQuery<IQB>>>;
|
|
1213
1310
|
/**
|
|
1214
1311
|
* Like {@link insert}, but switches to an `UPDATE` statement.
|
|
1215
1312
|
*/
|
|
1216
|
-
update<IQB extends k.UpdateQueryBuilder<any, any, any, T["BaseQuery"]["O"]>>(
|
|
1313
|
+
update<IQB extends k.UpdateQueryBuilder<any, any, any, T["BaseQuery"]["O"]>>(uqb: UpdateQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTUpdateQuery<IQB>>>;
|
|
1217
1314
|
/**
|
|
1218
1315
|
* Like {@link insert}, but switches to a `DELETE` statement.
|
|
1219
1316
|
*/
|
|
1220
|
-
delete<IQB extends k.DeleteQueryBuilder<any, any, T["BaseQuery"]["O"]>>(
|
|
1317
|
+
delete<IQB extends k.DeleteQueryBuilder<any, any, T["BaseQuery"]["O"]>>(dqb: DeleteQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTDeleteQuery<IQB>>>;
|
|
1221
1318
|
}
|
|
1222
1319
|
/**
|
|
1223
1320
|
* A query set that supports nested joins and automatic hydration.
|
|
@@ -1305,7 +1402,7 @@ interface QuerySet<in out T extends TQuerySet> extends MappedQuerySet<T> {
|
|
|
1305
1402
|
* @param keys - Field names to omit from the output.
|
|
1306
1403
|
* @returns A new HydratedQueryBuilder with the fields omitted.
|
|
1307
1404
|
*/
|
|
1308
|
-
omit<K$1 extends keyof TInput<T>>(keys: readonly K$1[]): QuerySet<
|
|
1405
|
+
omit<K$1 extends keyof TInput<T>>(keys: readonly K$1[]): QuerySet<TWithOmit<T, K$1>>;
|
|
1309
1406
|
/**
|
|
1310
1407
|
* Extends this query builder's hydration configuration with another Hydrator.
|
|
1311
1408
|
* The other Hydrator's configuration takes precedence in case of conflicts.
|
|
@@ -2206,6 +2303,7 @@ interface TQuerySetWithAttach<in out T extends TQuerySet, in out Key extends str
|
|
|
2206
2303
|
}>;
|
|
2207
2304
|
OrderableColumns: T["OrderableColumns"];
|
|
2208
2305
|
HydratedOutput: ExtendWith<T["HydratedOutput"], Key, AttachedOutputMap<FetchFnReturn>[Type]>;
|
|
2306
|
+
OmittedKeys: T["OmittedKeys"];
|
|
2209
2307
|
}
|
|
2210
2308
|
interface QuerySetWithAttach<in out T extends TQuerySet, in out Key extends string, in out Type extends TAttachType, in out FetchFnReturn extends SomeFetchFnReturn> extends QuerySet<TQuerySetWithAttach<T, Key, Type, FetchFnReturn>> {}
|
|
2211
2309
|
type NestedQuerySetOrFactory<T extends TQuerySet, Alias extends string, TNested extends TSelectQuerySet> = MappedQuerySet<TNested> | JoinBuilderCallback<T, Alias, TNested>;
|
|
@@ -2251,6 +2349,7 @@ type TQuerySetWithJoin<T extends TQuerySet, Key extends string, Type extends TJo
|
|
|
2251
2349
|
JoinedQuery: JoinedQueryMap<T, Key, TNested>[Type];
|
|
2252
2350
|
OrderableColumns: TOrderableColumnsWithJoin<T, Key, Type, TNested>;
|
|
2253
2351
|
HydratedOutput: ExtendWith<T["HydratedOutput"], Key, JoinHydratedRowMap<TNested>[Type]>;
|
|
2352
|
+
OmittedKeys: T["OmittedKeys"];
|
|
2254
2353
|
}>;
|
|
2255
2354
|
interface QuerySetWithJoin<in out T extends TQuerySet, in out Key extends string, in out Type extends TJoinType, in out TNested extends TSelectQuerySet> extends QuerySet<TQuerySetWithJoin<T, Key, Type, TNested>> {}
|
|
2256
2355
|
interface InitialQuerySet<in out DB$1, in out BaseAlias extends string, in out BaseQuery extends TQuery> extends QuerySet<{
|
|
@@ -2261,7 +2360,8 @@ interface InitialQuerySet<in out DB$1, in out BaseAlias extends string, in out B
|
|
|
2261
2360
|
Collections: {};
|
|
2262
2361
|
JoinedQuery: InitialJoinedQuery<BaseQuery["DB"], BaseAlias, BaseQuery["O"]>;
|
|
2263
2362
|
OrderableColumns: keyof BaseQuery["O"] & string;
|
|
2264
|
-
HydratedOutput: BaseQuery["O"]
|
|
2363
|
+
HydratedOutput: Flatten<BaseQuery["O"]>;
|
|
2364
|
+
OmittedKeys: never;
|
|
2265
2365
|
}> {}
|
|
2266
2366
|
interface SelectCreator<DB$1> {
|
|
2267
2367
|
selectFrom: k.QueryCreator<DB$1>["selectFrom"];
|
|
@@ -2495,4 +2595,4 @@ declare class InvalidJoinedQuerySetError extends KyselyHydrateError {
|
|
|
2495
2595
|
constructor(baseAlias: string);
|
|
2496
2596
|
}
|
|
2497
2597
|
//#endregion
|
|
2498
|
-
export { AmbiguousColumnReferenceError, CardinalityViolationError, ExpectedOneItemError, type Hydrator, InvalidJoinedQuerySetError, KeyByMismatchError, KyselyHydrateError, UnexpectedCaseError, UnexpectedComplexAliasError, UnexpectedSelectAllError, UnexpectedSelectionTypeError, UnsupportedAliasNodeTypeError, UnsupportedNodeTypeError, UnsupportedTableAliasNodeTypeError, WildcardSelectionError, createHydrator, hydrate, isFullHydrator, querySet };
|
|
2598
|
+
export { AmbiguousColumnReferenceError, CardinalityViolationError, ExpectedOneItemError, type Hydrator, type InferOutput, InvalidJoinedQuerySetError, KeyByMismatchError, KyselyHydrateError, UnexpectedCaseError, UnexpectedComplexAliasError, UnexpectedSelectAllError, UnexpectedSelectionTypeError, UnsupportedAliasNodeTypeError, UnsupportedNodeTypeError, UnsupportedTableAliasNodeTypeError, WildcardSelectionError, createHydrator, hydrate, isFullHydrator, querySet };
|
package/dist/index.mjs
CHANGED
|
@@ -1017,6 +1017,15 @@ var QuerySetImpl = class QuerySetImpl {
|
|
|
1017
1017
|
$call(callback) {
|
|
1018
1018
|
return callback(this);
|
|
1019
1019
|
}
|
|
1020
|
+
$castTo() {
|
|
1021
|
+
return this;
|
|
1022
|
+
}
|
|
1023
|
+
$narrowType() {
|
|
1024
|
+
return this;
|
|
1025
|
+
}
|
|
1026
|
+
$assertType() {
|
|
1027
|
+
return this;
|
|
1028
|
+
}
|
|
1020
1029
|
#asWrite(query) {
|
|
1021
1030
|
return this.#clone({ baseQuery: typeof query === "function" ? query(this.#props.db) : query });
|
|
1022
1031
|
}
|