pqb 0.30.6 → 0.30.7
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 +22 -30
- package/dist/index.js +19 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -615,7 +615,7 @@ type JoinFirstArg<T extends PickQueryRelationsWithData> = PickQueryTableMetaResu
|
|
|
615
615
|
* Arguments of `join` methods (not `joinLateral`).
|
|
616
616
|
* See {@link join}
|
|
617
617
|
*/
|
|
618
|
-
type JoinArgs<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = [JoinCallback<T, Arg>] | (Arg extends PickQueryTableMetaResult ? JoinQueryArgs<T, Arg> : Arg extends keyof T['relations'] ? EmptyTuple : Arg extends keyof T['withData'] ? JoinWithArgs<T, Arg> : never);
|
|
618
|
+
type JoinArgs<T extends PickQueryMetaShapeRelationsWithData, Arg extends JoinFirstArg<T>> = [on?: JoinCallback<T, Arg>] | (Arg extends PickQueryTableMetaResult ? JoinQueryArgs<T, Arg> : Arg extends keyof T['relations'] ? EmptyTuple : Arg extends keyof T['withData'] ? JoinWithArgs<T, Arg> : never);
|
|
619
619
|
/**
|
|
620
620
|
* Column names of the joined table that can be used to join.
|
|
621
621
|
* Derived from 'result', not from 'shape',
|
|
@@ -1382,7 +1382,7 @@ declare const _queryJoinOnJsonPathEquals: <T extends PickQueryMeta>(q: T, args:
|
|
|
1382
1382
|
*/
|
|
1383
1383
|
type JoinQueryBuilder<T extends PickQueryMetaShape = PickQueryMetaShape, J extends PickQueryTableMetaResult = PickQueryTableMetaResult> = {
|
|
1384
1384
|
[K in keyof J]: K extends 'meta' ? {
|
|
1385
|
-
[K in keyof J['meta']]: K extends 'selectable' ? J['
|
|
1385
|
+
[K in keyof J['meta']]: K extends 'selectable' ? SelectableFromShape<J['result'], AliasOrTable<J>> & Omit<T['meta']['selectable'], keyof T['shape']> : J['meta'][K];
|
|
1386
1386
|
} : J[K];
|
|
1387
1387
|
} & OnMethods;
|
|
1388
1388
|
declare class OnMethods {
|
|
@@ -3798,19 +3798,16 @@ interface CreateSelf extends QueryBase {
|
|
|
3798
3798
|
}
|
|
3799
3799
|
type CreateData<T extends CreateSelf, BelongsToData = CreateBelongsToData<T>> = RelationsBase extends T['relations'] ? CreateDataWithDefaults<T, keyof T['meta']['defaults']> : CreateRelationsData<T, BelongsToData>;
|
|
3800
3800
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = {
|
|
3801
|
-
[K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T
|
|
3801
|
+
[K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K>;
|
|
3802
3802
|
} & {
|
|
3803
|
-
[K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T
|
|
3803
|
+
[K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T, K> : never;
|
|
3804
3804
|
};
|
|
3805
3805
|
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = {
|
|
3806
|
-
[K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T
|
|
3806
|
+
[K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K>;
|
|
3807
3807
|
} & {
|
|
3808
|
-
[K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T
|
|
3809
|
-
};
|
|
3810
|
-
type CreateColumn<InputType, Key extends keyof InputType> = Expression | InputType[Key] | {
|
|
3811
|
-
__isQuery: true;
|
|
3812
|
-
then: QueryThen<InputType[Key]>;
|
|
3808
|
+
[K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K>;
|
|
3813
3809
|
};
|
|
3810
|
+
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | QueryOrExpression<T['inputType'][K]> | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
3814
3811
|
type CreateRelationsData<T extends CreateSelf, BelongsToData> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['relationConfig']['omitForeignKeyInCreate']> & BelongsToData & T['relations'][keyof T['relations']]['relationConfig']['optionalDataForCreate'];
|
|
3815
3812
|
type CreateBelongsToData<T extends CreateSelf> = CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['relationConfig']['dataForCreate']>;
|
|
3816
3813
|
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: keyof Union['columns'] extends keyof T['meta']['defaults'] ? Omit<Union['columns'], keyof T['meta']['defaults']> & {
|
|
@@ -3918,7 +3915,7 @@ declare class Create {
|
|
|
3918
3915
|
*
|
|
3919
3916
|
* await db.table.create({
|
|
3920
3917
|
* // raw SQL
|
|
3921
|
-
* column1: sql`'John' || ' ' || 'Doe'`,
|
|
3918
|
+
* column1: (q) => q.sql`'John' || ' ' || 'Doe'`,
|
|
3922
3919
|
*
|
|
3923
3920
|
* // query that returns a single value
|
|
3924
3921
|
* // returning multiple values will result in Postgres error
|
|
@@ -5237,26 +5234,24 @@ declare class Union {
|
|
|
5237
5234
|
}
|
|
5238
5235
|
|
|
5239
5236
|
type UpdateSelf = {
|
|
5240
|
-
[K in '
|
|
5237
|
+
[K in 'inputType' | 'relations' | UpdateColumnArgKeys]: Query[K];
|
|
5241
5238
|
};
|
|
5242
5239
|
type UpdateData<T extends UpdateSelf> = {
|
|
5243
5240
|
[K in keyof T['inputType']]?: UpdateColumn<T, K>;
|
|
5244
5241
|
} & {
|
|
5245
5242
|
[K in keyof T['relations']]?: UpdateRelationData<T, T['relations'][K]['relationConfig']>;
|
|
5246
5243
|
};
|
|
5247
|
-
type UpdateColumnArgKeys = keyof JsonModifiers | 'meta' | 'shape' | 'result' | 'returnType';
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
}
|
|
5252
|
-
interface ResultRelationQueryBase extends RelationQueryBase {
|
|
5253
|
-
meta: ResultRelationQueryBaseMeta;
|
|
5244
|
+
type UpdateColumnArgKeys = keyof JsonModifiers | keyof ExpressionMethods | 'sql' | 'meta' | 'shape' | 'result' | 'returnType' | 'columnTypes';
|
|
5245
|
+
interface UpdateQueryOrExpression<T> extends QueryOrExpression<T> {
|
|
5246
|
+
meta: {
|
|
5247
|
+
kind: 'select';
|
|
5248
|
+
};
|
|
5254
5249
|
}
|
|
5255
|
-
type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] |
|
|
5250
|
+
type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] | QueryOrExpression<T['inputType'][Key]> | {
|
|
5256
5251
|
[K in keyof Query]: K extends 'then' ? QueryThen<T['inputType'][Key]> : Query[K];
|
|
5257
5252
|
} | ((q: {
|
|
5258
5253
|
[K in keyof T['relations'] | UpdateColumnArgKeys]: K extends keyof T['relations'] ? T['relations'][K] : K extends UpdateColumnArgKeys ? T[K] : never;
|
|
5259
|
-
}) =>
|
|
5254
|
+
}) => JsonItem | UpdateQueryOrExpression<T['inputType'][Key]>);
|
|
5260
5255
|
type UpdateRelationData<T extends UpdateSelf, Rel extends RelationConfigBase> = QueryReturnsAll<T['returnType']> extends true ? Rel['dataForUpdate'] : Rel['one'] extends true ? Rel['dataForUpdate'] | Rel['dataForUpdateOne'] : Rel['dataForUpdate'] & Rel['dataForUpdateOne'];
|
|
5261
5256
|
type UpdateArg<T extends UpdateSelf> = T['meta']['hasWhere'] extends true ? UpdateData<T> : never;
|
|
5262
5257
|
type UpdateRawArgs<T extends UpdateSelf> = T['meta']['hasWhere'] extends true ? SQLQueryArgs : never;
|
|
@@ -5330,7 +5325,7 @@ declare class Update {
|
|
|
5330
5325
|
* column1: 123,
|
|
5331
5326
|
*
|
|
5332
5327
|
* // use raw SQL to update the column
|
|
5333
|
-
* column2: sql`2 + 2`,
|
|
5328
|
+
* column2: (q) => q.sql`2 + 2`,
|
|
5334
5329
|
*
|
|
5335
5330
|
* // use query that returns a single value
|
|
5336
5331
|
* // returning multiple values will result in Postgres error
|
|
@@ -5439,7 +5434,7 @@ declare class Update {
|
|
|
5439
5434
|
*/
|
|
5440
5435
|
update<T extends UpdateSelf>(this: T, arg: UpdateArg<T>): UpdateResult<T>;
|
|
5441
5436
|
/**
|
|
5442
|
-
* `
|
|
5437
|
+
* `updateSql` is for updating records with raw expression.
|
|
5443
5438
|
*
|
|
5444
5439
|
* The behavior is the same as a regular `update` method has:
|
|
5445
5440
|
* `find` or `where` must precede calling this method,
|
|
@@ -5450,14 +5445,14 @@ declare class Update {
|
|
|
5450
5445
|
* const value = 'new name';
|
|
5451
5446
|
*
|
|
5452
5447
|
* // update with SQL template string
|
|
5453
|
-
* const updatedCount = await db.table.find(1).
|
|
5448
|
+
* const updatedCount = await db.table.find(1).updateSql`name = ${value}`;
|
|
5454
5449
|
*
|
|
5455
5450
|
* // or update with `sql` function:
|
|
5456
|
-
* await db.table.find(1).
|
|
5451
|
+
* await db.table.find(1).updateSql(sql`name = ${value}`);
|
|
5457
5452
|
* ```
|
|
5458
5453
|
* @param args - raw SQL via a template string or by using a `sql` method
|
|
5459
5454
|
*/
|
|
5460
|
-
|
|
5455
|
+
updateSql<T extends UpdateSelf>(this: T, ...args: UpdateRawArgs<T>): UpdateResult<T>;
|
|
5461
5456
|
/**
|
|
5462
5457
|
* To make sure that at least one row was updated use `updateOrThrow`:
|
|
5463
5458
|
*
|
|
@@ -6690,10 +6685,7 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6690
6685
|
* pets: (q) => q.pets.join().none(),
|
|
6691
6686
|
* });
|
|
6692
6687
|
*
|
|
6693
|
-
* await db.user.join(
|
|
6694
|
-
* (q) => q.pets.none(),
|
|
6695
|
-
* (q) => q,
|
|
6696
|
-
* );
|
|
6688
|
+
* await db.user.join((q) => q.pets.none());
|
|
6697
6689
|
*
|
|
6698
6690
|
* await db.user.join('pets', (q) => q.none());
|
|
6699
6691
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -2379,25 +2379,14 @@ const subJoinToSql = (ctx, jq, innerAs, outerAs, cloned) => {
|
|
|
2379
2379
|
}).text}) ${outerAs || innerAs}`;
|
|
2380
2380
|
};
|
|
2381
2381
|
const processArgs = (args, ctx, query, joinAs, joinShape, quotedAs) => {
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
);
|
|
2391
|
-
} else {
|
|
2392
|
-
return getConditionsFor3Or4LengthItem(
|
|
2393
|
-
ctx,
|
|
2394
|
-
query,
|
|
2395
|
-
joinAs,
|
|
2396
|
-
quotedAs,
|
|
2397
|
-
args,
|
|
2398
|
-
joinShape
|
|
2399
|
-
);
|
|
2400
|
-
}
|
|
2382
|
+
return args.length === 1 ? getObjectOrRawConditions(ctx, query, args[0], quotedAs, joinAs, joinShape) : getConditionsFor3Or4LengthItem(
|
|
2383
|
+
ctx,
|
|
2384
|
+
query,
|
|
2385
|
+
joinAs,
|
|
2386
|
+
quotedAs,
|
|
2387
|
+
args,
|
|
2388
|
+
joinShape
|
|
2389
|
+
);
|
|
2401
2390
|
};
|
|
2402
2391
|
const getConditionsFor3Or4LengthItem = (ctx, query, target, quotedAs, args, joinShape) => {
|
|
2403
2392
|
const [leftColumn, opOrRightColumn, maybeRightColumn] = args;
|
|
@@ -2550,7 +2539,9 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
|
|
|
2550
2539
|
);
|
|
2551
2540
|
return { w: first, r, s: joinSubQuery || getIsJoinSubQuery(r) };
|
|
2552
2541
|
}
|
|
2553
|
-
}
|
|
2542
|
+
}
|
|
2543
|
+
const args0 = args.length ? args[0] : orchidCore.returnArg;
|
|
2544
|
+
if (typeof args0 === "function") {
|
|
2554
2545
|
const q = first;
|
|
2555
2546
|
if (q.joinQueryAfterCallback) {
|
|
2556
2547
|
let base = q.baseQuery;
|
|
@@ -2568,7 +2559,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
|
|
|
2568
2559
|
const joinedShapes = __spreadProps$4(__spreadValues$c({}, joinTo.q.joinedShapes), {
|
|
2569
2560
|
[joinTo.q.as || joinTo.table]: joinTo.shape
|
|
2570
2561
|
});
|
|
2571
|
-
const r =
|
|
2562
|
+
const r = args0(
|
|
2572
2563
|
makeJoinQueryBuilder(
|
|
2573
2564
|
q,
|
|
2574
2565
|
q.q.joinedShapes ? __spreadValues$c(__spreadValues$c({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
|
|
@@ -6366,7 +6357,7 @@ class Create {
|
|
|
6366
6357
|
*
|
|
6367
6358
|
* await db.table.create({
|
|
6368
6359
|
* // raw SQL
|
|
6369
|
-
* column1: sql`'John' || ' ' || 'Doe'`,
|
|
6360
|
+
* column1: (q) => q.sql`'John' || ' ' || 'Doe'`,
|
|
6370
6361
|
*
|
|
6371
6362
|
* // query that returns a single value
|
|
6372
6363
|
* // returning multiple values will result in Postgres error
|
|
@@ -9442,7 +9433,7 @@ class Update {
|
|
|
9442
9433
|
* column1: 123,
|
|
9443
9434
|
*
|
|
9444
9435
|
* // use raw SQL to update the column
|
|
9445
|
-
* column2: sql`2 + 2`,
|
|
9436
|
+
* column2: (q) => q.sql`2 + 2`,
|
|
9446
9437
|
*
|
|
9447
9438
|
* // use query that returns a single value
|
|
9448
9439
|
* // returning multiple values will result in Postgres error
|
|
@@ -9556,7 +9547,7 @@ class Update {
|
|
|
9556
9547
|
);
|
|
9557
9548
|
}
|
|
9558
9549
|
/**
|
|
9559
|
-
* `
|
|
9550
|
+
* `updateSql` is for updating records with raw expression.
|
|
9560
9551
|
*
|
|
9561
9552
|
* The behavior is the same as a regular `update` method has:
|
|
9562
9553
|
* `find` or `where` must precede calling this method,
|
|
@@ -9567,14 +9558,14 @@ class Update {
|
|
|
9567
9558
|
* const value = 'new name';
|
|
9568
9559
|
*
|
|
9569
9560
|
* // update with SQL template string
|
|
9570
|
-
* const updatedCount = await db.table.find(1).
|
|
9561
|
+
* const updatedCount = await db.table.find(1).updateSql`name = ${value}`;
|
|
9571
9562
|
*
|
|
9572
9563
|
* // or update with `sql` function:
|
|
9573
|
-
* await db.table.find(1).
|
|
9564
|
+
* await db.table.find(1).updateSql(sql`name = ${value}`);
|
|
9574
9565
|
* ```
|
|
9575
9566
|
* @param args - raw SQL via a template string or by using a `sql` method
|
|
9576
9567
|
*/
|
|
9577
|
-
|
|
9568
|
+
updateSql(...args) {
|
|
9578
9569
|
return _queryUpdateRaw(
|
|
9579
9570
|
this.clone(),
|
|
9580
9571
|
sqlQueryArgsToExpression(args)
|
|
@@ -11149,10 +11140,7 @@ class QueryMethods {
|
|
|
11149
11140
|
* pets: (q) => q.pets.join().none(),
|
|
11150
11141
|
* });
|
|
11151
11142
|
*
|
|
11152
|
-
* await db.user.join(
|
|
11153
|
-
* (q) => q.pets.none(),
|
|
11154
|
-
* (q) => q,
|
|
11155
|
-
* );
|
|
11143
|
+
* await db.user.join((q) => q.pets.none());
|
|
11156
11144
|
*
|
|
11157
11145
|
* await db.user.join('pets', (q) => q.none());
|
|
11158
11146
|
* ```
|