pqb 0.40.9 → 0.40.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +27 -12
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1885,6 +1885,13 @@ interface QueryMetaHasWhere {
|
|
|
1885
1885
|
hasWhere: true;
|
|
1886
1886
|
};
|
|
1887
1887
|
}
|
|
1888
|
+
interface QueryFnReturningSelect {
|
|
1889
|
+
(q: never): {
|
|
1890
|
+
meta: {
|
|
1891
|
+
hasSelect: true;
|
|
1892
|
+
};
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1888
1895
|
/**
|
|
1889
1896
|
* Mutative {@link Where.prototype.where}
|
|
1890
1897
|
*/
|
|
@@ -2485,6 +2492,10 @@ declare class Where {
|
|
|
2485
2492
|
* // find by a relation name if it's defined
|
|
2486
2493
|
* db.user.whereExists('account');
|
|
2487
2494
|
*
|
|
2495
|
+
* // find users who have an account with positive balance
|
|
2496
|
+
* // `accounts` is a relation name
|
|
2497
|
+
* db.user.whereExists((q) => q.accounts.where({ balance: { gt: 0 } }));
|
|
2498
|
+
*
|
|
2488
2499
|
* // find using a table and a join conditions
|
|
2489
2500
|
* db.user.whereExists(db.account, 'account.id', 'user.id');
|
|
2490
2501
|
*
|
|
@@ -2492,7 +2503,11 @@ declare class Where {
|
|
|
2492
2503
|
* db.user.whereExists(db.account, (q) => q.on('account.id', '=', 'user.id'));
|
|
2493
2504
|
* ```
|
|
2494
2505
|
*/
|
|
2495
|
-
whereExists<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>>(this: T, arg: Arg, ...args:
|
|
2506
|
+
whereExists<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>, Args extends JoinArgs<T, Arg>>(this: T, arg: Arg, ...args: Args): Arg extends QueryFnReturningSelect ? {
|
|
2507
|
+
error: 'Cannot select in whereExists';
|
|
2508
|
+
} : Args[0] extends QueryFnReturningSelect ? {
|
|
2509
|
+
error: 'Cannot select in whereExists';
|
|
2510
|
+
} : WhereResult<T>;
|
|
2496
2511
|
/**
|
|
2497
2512
|
* Acts as `whereExists`, but prepends the condition with `OR`:
|
|
2498
2513
|
*
|
|
@@ -3349,6 +3364,16 @@ type DbTableOptionScopes<Table extends string | undefined, Shape extends QueryCo
|
|
|
3349
3364
|
type QueryDefaultReturnData<Shape extends QueryColumnsInit> = {
|
|
3350
3365
|
[K in DefaultSelectColumns<Shape>]: Shape[K]['outputType'];
|
|
3351
3366
|
}[];
|
|
3367
|
+
interface TableMeta<Table extends string | undefined, Shape extends QueryColumnsInit, ShapeWithComputed extends QueryColumnsInit, Scopes extends RecordUnknown | undefined> extends QueryMetaBase<{
|
|
3368
|
+
[K in keyof Scopes]: true;
|
|
3369
|
+
}> {
|
|
3370
|
+
kind: 'select';
|
|
3371
|
+
defaults: {
|
|
3372
|
+
[K in keyof Shape as unknown extends Shape[K]['data']['default'] ? never : K]: true;
|
|
3373
|
+
};
|
|
3374
|
+
selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
3375
|
+
defaultSelect: DefaultSelectColumns<Shape>;
|
|
3376
|
+
}
|
|
3352
3377
|
declare const anyShape: QueryColumnsInit;
|
|
3353
3378
|
interface Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject> extends DbBase<Adapter, Table, Shape, ColumnTypes, ShapeWithComputed>, QueryMethods<ColumnTypes>, QueryBase {
|
|
3354
3379
|
result: Pick<Shape, DefaultSelectColumns<Shape>>;
|
|
@@ -3359,17 +3384,7 @@ interface Db<Table extends string | undefined = undefined, Shape extends QueryCo
|
|
|
3359
3384
|
relations: EmptyObject;
|
|
3360
3385
|
withData: EmptyObject;
|
|
3361
3386
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
|
|
3362
|
-
meta:
|
|
3363
|
-
kind: 'select';
|
|
3364
|
-
defaults: {
|
|
3365
|
-
[K in keyof Shape as unknown extends Shape[K]['data']['default'] ? never : K]: true;
|
|
3366
|
-
};
|
|
3367
|
-
scopes: {
|
|
3368
|
-
[K in keyof Scopes]: true;
|
|
3369
|
-
};
|
|
3370
|
-
selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
3371
|
-
defaultSelect: DefaultSelectColumns<Shape>;
|
|
3372
|
-
};
|
|
3387
|
+
meta: TableMeta<Table, Shape, ShapeWithComputed, Scopes>;
|
|
3373
3388
|
internal: QueryInternal<{
|
|
3374
3389
|
[K in keyof PrimaryKeys]: (keyof PrimaryKeys extends K ? never : keyof PrimaryKeys) extends never ? PrimaryKeys[K] : never;
|
|
3375
3390
|
}[keyof PrimaryKeys], PrimaryKeys | UniqueColumns, {
|
package/dist/index.js
CHANGED
|
@@ -2578,6 +2578,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
|
2578
2578
|
s: joinSubQuery
|
|
2579
2579
|
};
|
|
2580
2580
|
};
|
|
2581
|
+
const preprocessJoinArg = (q, arg) => {
|
|
2582
|
+
if (typeof arg !== "function")
|
|
2583
|
+
return arg;
|
|
2584
|
+
arg = arg(q.relations);
|
|
2585
|
+
arg.joinQueryAfterCallback = arg.joinQuery;
|
|
2586
|
+
return arg;
|
|
2587
|
+
};
|
|
2581
2588
|
const makeJoinQueryBuilder = (joinedQuery, joinedShapes, joinTo) => {
|
|
2582
2589
|
const q = joinedQuery.baseQuery.clone();
|
|
2583
2590
|
q.baseQuery = q;
|
|
@@ -2640,10 +2647,7 @@ const _join = (query, require2, type, first, args) => {
|
|
|
2640
2647
|
let batchParsers;
|
|
2641
2648
|
let computeds;
|
|
2642
2649
|
let joinSubQuery = false;
|
|
2643
|
-
|
|
2644
|
-
first = first(query.relations);
|
|
2645
|
-
first.joinQueryAfterCallback = first.joinQuery;
|
|
2646
|
-
}
|
|
2650
|
+
first = preprocessJoinArg(query, first);
|
|
2647
2651
|
if (typeof first === "object") {
|
|
2648
2652
|
if (require2 && isQueryNone(first)) {
|
|
2649
2653
|
return _queryNone(query);
|
|
@@ -9814,7 +9818,13 @@ const _queryWhereIn = (q, and, arg, values, not) => {
|
|
|
9814
9818
|
return q;
|
|
9815
9819
|
};
|
|
9816
9820
|
const existsArgs = (self, q, args) => {
|
|
9817
|
-
const joinArgs = processJoinArgs(
|
|
9821
|
+
const joinArgs = processJoinArgs(
|
|
9822
|
+
self,
|
|
9823
|
+
preprocessJoinArg(self, q),
|
|
9824
|
+
args,
|
|
9825
|
+
false,
|
|
9826
|
+
true
|
|
9827
|
+
);
|
|
9818
9828
|
return [
|
|
9819
9829
|
{
|
|
9820
9830
|
EXISTS: joinArgs
|
|
@@ -10457,6 +10467,10 @@ class Where {
|
|
|
10457
10467
|
* // find by a relation name if it's defined
|
|
10458
10468
|
* db.user.whereExists('account');
|
|
10459
10469
|
*
|
|
10470
|
+
* // find users who have an account with positive balance
|
|
10471
|
+
* // `accounts` is a relation name
|
|
10472
|
+
* db.user.whereExists((q) => q.accounts.where({ balance: { gt: 0 } }));
|
|
10473
|
+
*
|
|
10460
10474
|
* // find using a table and a join conditions
|
|
10461
10475
|
* db.user.whereExists(db.account, 'account.id', 'user.id');
|
|
10462
10476
|
*
|