pqb 0.18.19 → 0.18.21
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 +95 -63
- package/dist/index.js +48 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as orchid_core from 'orchid-core';
|
|
2
|
-
import { QueryResultRow, AdapterBase, QueryInput, Sql, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, StringKey, Expression, ColumnTypeBase, MaybeArray, TemplateLiteralArgs, ColumnsParsers, getValueKey, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, EmptyObject, DbBase, QueryThen, QueryCatch, TransactionState, SQLQueryArgs, NullableColumn, SetOptional, EmptyTuple, MergeObjects, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, Spread, Code, OperatorToSQL, BaseNumberData, NumberTypeMethods, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, stringTypeMethods, DateTypeMethods, DateColumnData, EncodeColumn, ParseColumn, JSONType, JSONUnknown, JSONTypes, ArrayMethodsData, arrayTypeMethods, ForeignKeyTable, TimestampHelpers, ColumnNameOfTable, ValidationContext, ErrorMessage
|
|
2
|
+
import { QueryResultRow, AdapterBase, QueryInput, Sql, QueryBaseCommon, ColumnsShapeBase, QueryInternal, QueryMetaBase, StringKey, Expression, ColumnTypeBase, MaybeArray, TemplateLiteralArgs, ColumnsParsers, getValueKey, ColumnTypesBase, ColumnShapeOutput, DefaultSelectColumns, EmptyObject, DbBase, QueryThen, QueryCatch, TransactionState, SQLQueryArgs, NullableColumn, SetOptional, EmptyTuple, MergeObjects, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, Spread, Code, OperatorToSQL, BaseNumberData, NumberTypeMethods, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, stringTypeMethods, DateTypeMethods, DateColumnData, EncodeColumn, ParseColumn, JSONType, JSONUnknown, JSONTypes, ArrayMethodsData, arrayTypeMethods, ForeignKeyTable, TimestampHelpers, ColumnNameOfTable, ColumnDataBase, ValidationContext, ErrorMessage } from 'orchid-core';
|
|
3
3
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -270,7 +270,7 @@ type CommonQueryData = {
|
|
|
270
270
|
wrapInTransaction?: boolean;
|
|
271
271
|
throwOnNotFound?: boolean;
|
|
272
272
|
with?: WithItem[];
|
|
273
|
-
withShapes?: Record<string,
|
|
273
|
+
withShapes?: Record<string, ColumnsShapeBase>;
|
|
274
274
|
joinTo?: QueryBase;
|
|
275
275
|
joinedShapes?: JoinedShapes;
|
|
276
276
|
joinedParsers?: JoinedParsers;
|
|
@@ -437,9 +437,9 @@ declare class OrchidOrmInternalError extends Error {
|
|
|
437
437
|
}
|
|
438
438
|
type QueryErrorName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
|
|
439
439
|
declare abstract class QueryError<T extends {
|
|
440
|
-
shape:
|
|
440
|
+
shape: ColumnsShapeBase;
|
|
441
441
|
} = {
|
|
442
|
-
shape:
|
|
442
|
+
shape: ColumnsShapeBase;
|
|
443
443
|
}> extends OrchidOrmInternalError {
|
|
444
444
|
message: string;
|
|
445
445
|
name: QueryErrorName;
|
|
@@ -492,8 +492,8 @@ type DbTableOptions = {
|
|
|
492
492
|
language?: string;
|
|
493
493
|
} & QueryLogOptions;
|
|
494
494
|
type QueryDefaultReturnData<Shape extends ColumnsShapeBase> = Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[];
|
|
495
|
-
declare const anyShape: Record<string,
|
|
496
|
-
interface Db<Table extends string | undefined = undefined, Shape extends
|
|
495
|
+
declare const anyShape: Record<string, ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>>;
|
|
496
|
+
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShapeBase = Record<string, never>, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes, ShapeWithComputed extends ColumnsShapeBase = Shape, Data = QueryDefaultReturnData<Shape>> extends DbBase<Adapter, Table, Shape, ColumnTypes, ShapeWithComputed>, QueryMethods<ColumnTypes> {
|
|
497
497
|
new (adapter: Adapter, queryBuilder: Db<Table, Shape, Relations, ColumnTypes>, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
498
498
|
internal: Query['internal'];
|
|
499
499
|
queryBuilder: Db;
|
|
@@ -516,7 +516,7 @@ interface Db<Table extends string | undefined = undefined, Shape extends Columns
|
|
|
516
516
|
}[keyof Shape], true>;
|
|
517
517
|
};
|
|
518
518
|
}
|
|
519
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends
|
|
519
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShapeBase = Record<string, never>, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes, ShapeWithComputed extends ColumnsShapeBase = Shape> implements Query {
|
|
520
520
|
adapter: Adapter;
|
|
521
521
|
queryBuilder: Db;
|
|
522
522
|
table: Table;
|
|
@@ -583,7 +583,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
583
583
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryArraysResult<R>>;
|
|
584
584
|
}
|
|
585
585
|
type DbResult<ColumnTypes> = Db<string, Record<string, never>, EmptyObject, ColumnTypes> & {
|
|
586
|
-
<Table extends string, Shape extends
|
|
586
|
+
<Table extends string, Shape extends ColumnsShapeBase = ColumnsShapeBase>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape, EmptyObject>;
|
|
587
587
|
adapter: Adapter;
|
|
588
588
|
close: Adapter['close'];
|
|
589
589
|
};
|
|
@@ -4371,17 +4371,33 @@ declare class Update {
|
|
|
4371
4371
|
updateOrThrow<T extends Query>(this: T, arg: UpdateArg<T>): UpdateResult<T>;
|
|
4372
4372
|
_updateOrThrow<T extends Query>(this: T, arg: UpdateArg<T>): UpdateResult<T>;
|
|
4373
4373
|
/**
|
|
4374
|
-
* Increments a column
|
|
4374
|
+
* Increments a column by `1`, returns a count of updated records by default.
|
|
4375
4375
|
*
|
|
4376
4376
|
* ```ts
|
|
4377
|
-
*
|
|
4378
|
-
* const result = await db.table
|
|
4379
|
-
* .selectAll()
|
|
4377
|
+
* const updatedCount = await db.table
|
|
4380
4378
|
* .where(...conditions)
|
|
4381
4379
|
* .increment('numericColumn');
|
|
4380
|
+
* ```
|
|
4382
4381
|
*
|
|
4382
|
+
* When using `find` or `get` it will throw `NotFoundError` when no records found.
|
|
4383
|
+
*
|
|
4384
|
+
* ```ts
|
|
4385
|
+
* // throws when not found
|
|
4386
|
+
* const updatedCount = await db.table.find(1).increment('numericColumn');
|
|
4387
|
+
*
|
|
4388
|
+
* // also throws when not found
|
|
4389
|
+
* const updatedCount2 = await db.table
|
|
4390
|
+
* .where(...conditions)
|
|
4391
|
+
* .get('columnName')
|
|
4392
|
+
* .increment('numericColumn');
|
|
4393
|
+
* ```
|
|
4394
|
+
*
|
|
4395
|
+
* Provide an object to increment multiple columns with different values.
|
|
4396
|
+
* Use `select` to specify columns to return.
|
|
4397
|
+
*
|
|
4398
|
+
* ```ts
|
|
4383
4399
|
* // increment someColumn by 5 and otherColumn by 10, return updated records
|
|
4384
|
-
* const
|
|
4400
|
+
* const result = await db.table
|
|
4385
4401
|
* .selectAll()
|
|
4386
4402
|
* .where(...conditions)
|
|
4387
4403
|
* .increment({
|
|
@@ -4395,17 +4411,33 @@ declare class Update {
|
|
|
4395
4411
|
increment<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
4396
4412
|
_increment<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
4397
4413
|
/**
|
|
4398
|
-
* Decrements a column
|
|
4414
|
+
* Decrements a column by `1`, returns a count of updated records by default.
|
|
4399
4415
|
*
|
|
4400
4416
|
* ```ts
|
|
4401
|
-
*
|
|
4402
|
-
*
|
|
4403
|
-
* .
|
|
4417
|
+
* const updatedCount = await db.table
|
|
4418
|
+
* .where(...conditions)
|
|
4419
|
+
* .decrement('numericColumn');
|
|
4420
|
+
* ```
|
|
4421
|
+
*
|
|
4422
|
+
* When using `find` or `get` it will throw `NotFoundError` when no records found.
|
|
4423
|
+
*
|
|
4424
|
+
* ```ts
|
|
4425
|
+
* // throws when not found
|
|
4426
|
+
* const updatedCount = await db.table.find(1).decrement('numericColumn');
|
|
4427
|
+
*
|
|
4428
|
+
* // also throws when not found
|
|
4429
|
+
* const updatedCount2 = await db.table
|
|
4404
4430
|
* .where(...conditions)
|
|
4431
|
+
* .get('columnName')
|
|
4405
4432
|
* .decrement('numericColumn');
|
|
4433
|
+
* ```
|
|
4434
|
+
*
|
|
4435
|
+
* Provide an object to decrement multiple columns with different values.
|
|
4436
|
+
* Use `select` to specify columns to return.
|
|
4406
4437
|
*
|
|
4438
|
+
* ```ts
|
|
4407
4439
|
* // decrement someColumn by 5 and otherColumn by 10, return updated records
|
|
4408
|
-
* const
|
|
4440
|
+
* const result = await db.table
|
|
4409
4441
|
* .selectAll()
|
|
4410
4442
|
* .where(...conditions)
|
|
4411
4443
|
* .decrement({
|
|
@@ -5622,7 +5654,7 @@ type Query = QueryBase & QueryMethods<unknown> & {
|
|
|
5622
5654
|
columnTypes: unknown;
|
|
5623
5655
|
onQueryBuilder: typeof OnQueryBuilder;
|
|
5624
5656
|
table?: string;
|
|
5625
|
-
shape:
|
|
5657
|
+
shape: ColumnsShapeBase;
|
|
5626
5658
|
singlePrimaryKey: string;
|
|
5627
5659
|
primaryKeys: string[];
|
|
5628
5660
|
inputType: Record<string, unknown>;
|
|
@@ -6487,48 +6519,6 @@ declare class ArrayColumn<Item extends ColumnTypeBase> extends ColumnType<Item['
|
|
|
6487
6519
|
};
|
|
6488
6520
|
}
|
|
6489
6521
|
|
|
6490
|
-
type ColumnsShape = Record<string, ColumnType>;
|
|
6491
|
-
declare abstract class ColumnsObject<Shape extends ColumnsShapeBase> extends ColumnType<{
|
|
6492
|
-
[K in keyof Shape]: Shape[K]['type'];
|
|
6493
|
-
}, typeof Operators.any, {
|
|
6494
|
-
[K in keyof Shape]: Shape[K]['inputType'];
|
|
6495
|
-
}, {
|
|
6496
|
-
[K in keyof Shape]: Shape[K]['outputType'];
|
|
6497
|
-
}, {
|
|
6498
|
-
[K in keyof Shape]: Shape[K]['queryType'];
|
|
6499
|
-
}> {
|
|
6500
|
-
shape: Shape;
|
|
6501
|
-
dataType: "object";
|
|
6502
|
-
operators: {
|
|
6503
|
-
equals: Operator<any, BooleanColumn>;
|
|
6504
|
-
not: Operator<any, BooleanColumn>;
|
|
6505
|
-
in: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6506
|
-
notIn: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6507
|
-
};
|
|
6508
|
-
constructor(shape: Shape);
|
|
6509
|
-
}
|
|
6510
|
-
declare abstract class ArrayOfColumnsObjects<Shape extends ColumnsShapeBase> extends ColumnType<{
|
|
6511
|
-
[K in keyof Shape]: Shape[K]['type'];
|
|
6512
|
-
}[], typeof Operators.any, {
|
|
6513
|
-
[K in keyof Shape]: Shape[K]['inputType'];
|
|
6514
|
-
}[], {
|
|
6515
|
-
[K in keyof Shape]: Shape[K]['outputType'];
|
|
6516
|
-
}[], {
|
|
6517
|
-
[K in keyof Shape]: Shape[K]['queryType'];
|
|
6518
|
-
}[]> {
|
|
6519
|
-
shape: Shape;
|
|
6520
|
-
dataType: "array";
|
|
6521
|
-
operators: {
|
|
6522
|
-
equals: Operator<any, BooleanColumn>;
|
|
6523
|
-
not: Operator<any, BooleanColumn>;
|
|
6524
|
-
in: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6525
|
-
notIn: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6526
|
-
};
|
|
6527
|
-
constructor(shape: Shape);
|
|
6528
|
-
}
|
|
6529
|
-
declare abstract class PluckResultColumnType<C extends ColumnTypeBase> extends ColumnTypeBase<C['type'][], typeof Operators.any, C['inputType'][], C['outputType'][], C['queryType'][]> {
|
|
6530
|
-
}
|
|
6531
|
-
|
|
6532
6522
|
declare class CustomTypeColumn extends ColumnType<unknown, typeof Operators.any> {
|
|
6533
6523
|
dataType: string;
|
|
6534
6524
|
operators: {
|
|
@@ -6592,7 +6582,7 @@ declare const getConstraintKind: (it: TableData.Constraint) => 'constraint' | 'f
|
|
|
6592
6582
|
declare const newTableData: () => TableData;
|
|
6593
6583
|
declare const getTableData: () => TableData;
|
|
6594
6584
|
declare const resetTableData: (data?: TableData) => void;
|
|
6595
|
-
declare const getColumnTypes: <ColumnTypes, Shape extends
|
|
6585
|
+
declare const getColumnTypes: <ColumnTypes, Shape extends ColumnsShapeBase>(types: ColumnTypes, fn: (t: ColumnTypes) => Shape, nowSQL: string | undefined, language: string | undefined, data?: TableData) => Shape;
|
|
6596
6586
|
type DefaultColumnTypes = TimestampHelpers & {
|
|
6597
6587
|
name<T extends ColumnTypesBase>(this: T, name: string): T;
|
|
6598
6588
|
sql<T extends ColumnTypesBase>(this: T, sql: TemplateStringsArray, ...values: unknown[]): RawSQLBase<ColumnType, T>;
|
|
@@ -6713,7 +6703,7 @@ type ForeignKeyAction = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET
|
|
|
6713
6703
|
type ForeignKey<Table extends string, Columns extends string[]> = ({
|
|
6714
6704
|
fn(): new () => {
|
|
6715
6705
|
table: Table;
|
|
6716
|
-
columns:
|
|
6706
|
+
columns: ColumnsShapeBase;
|
|
6717
6707
|
};
|
|
6718
6708
|
} | {
|
|
6719
6709
|
table: Table;
|
|
@@ -6956,6 +6946,48 @@ declare abstract class ColumnType<Type = unknown, Ops extends BaseOperators = Ba
|
|
|
6956
6946
|
generated<T extends ColumnType>(this: T, ...args: StaticSQLArgs): T;
|
|
6957
6947
|
}
|
|
6958
6948
|
|
|
6949
|
+
type ColumnsShape = Record<string, ColumnType>;
|
|
6950
|
+
declare abstract class ColumnsObject<Shape extends ColumnsShapeBase> extends ColumnType<{
|
|
6951
|
+
[K in keyof Shape]: Shape[K]['type'];
|
|
6952
|
+
}, typeof Operators.any, {
|
|
6953
|
+
[K in keyof Shape]: Shape[K]['inputType'];
|
|
6954
|
+
}, {
|
|
6955
|
+
[K in keyof Shape]: Shape[K]['outputType'];
|
|
6956
|
+
}, {
|
|
6957
|
+
[K in keyof Shape]: Shape[K]['queryType'];
|
|
6958
|
+
}> {
|
|
6959
|
+
shape: Shape;
|
|
6960
|
+
dataType: "object";
|
|
6961
|
+
operators: {
|
|
6962
|
+
equals: Operator<any, BooleanColumn>;
|
|
6963
|
+
not: Operator<any, BooleanColumn>;
|
|
6964
|
+
in: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6965
|
+
notIn: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6966
|
+
};
|
|
6967
|
+
constructor(shape: Shape);
|
|
6968
|
+
}
|
|
6969
|
+
declare abstract class ArrayOfColumnsObjects<Shape extends ColumnsShapeBase> extends ColumnType<{
|
|
6970
|
+
[K in keyof Shape]: Shape[K]['type'];
|
|
6971
|
+
}[], typeof Operators.any, {
|
|
6972
|
+
[K in keyof Shape]: Shape[K]['inputType'];
|
|
6973
|
+
}[], {
|
|
6974
|
+
[K in keyof Shape]: Shape[K]['outputType'];
|
|
6975
|
+
}[], {
|
|
6976
|
+
[K in keyof Shape]: Shape[K]['queryType'];
|
|
6977
|
+
}[]> {
|
|
6978
|
+
shape: Shape;
|
|
6979
|
+
dataType: "array";
|
|
6980
|
+
operators: {
|
|
6981
|
+
equals: Operator<any, BooleanColumn>;
|
|
6982
|
+
not: Operator<any, BooleanColumn>;
|
|
6983
|
+
in: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6984
|
+
notIn: Operator<any[] | orchid_core.Expression<ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, unknown, unknown, orchid_core.ColumnDataBase>> | Query, BooleanColumn>;
|
|
6985
|
+
};
|
|
6986
|
+
constructor(shape: Shape);
|
|
6987
|
+
}
|
|
6988
|
+
declare abstract class PluckResultColumnType<C extends ColumnTypeBase> extends ColumnTypeBase<C['type'][], typeof Operators.any, C['inputType'][], C['outputType'][], C['queryType'][]> {
|
|
6989
|
+
}
|
|
6990
|
+
|
|
6959
6991
|
declare abstract class VirtualColumn extends ColumnType<unknown, typeof Operators.any> {
|
|
6960
6992
|
dataType: string;
|
|
6961
6993
|
operators: {
|
package/dist/index.js
CHANGED
|
@@ -8283,6 +8283,12 @@ var __spreadValues$3 = (a, b) => {
|
|
|
8283
8283
|
};
|
|
8284
8284
|
const applyCountChange = (self, op, data) => {
|
|
8285
8285
|
self.q.type = "update";
|
|
8286
|
+
if (!self.q.select) {
|
|
8287
|
+
if (self.q.returnType === "oneOrThrow" || self.q.returnType === "valueOrThrow") {
|
|
8288
|
+
self.q.throwOnNotFound = true;
|
|
8289
|
+
}
|
|
8290
|
+
self.q.returnType = "rowCount";
|
|
8291
|
+
}
|
|
8286
8292
|
let map;
|
|
8287
8293
|
if (typeof data === "object") {
|
|
8288
8294
|
map = {};
|
|
@@ -8600,17 +8606,33 @@ class Update {
|
|
|
8600
8606
|
return this._update(arg);
|
|
8601
8607
|
}
|
|
8602
8608
|
/**
|
|
8603
|
-
* Increments a column
|
|
8609
|
+
* Increments a column by `1`, returns a count of updated records by default.
|
|
8604
8610
|
*
|
|
8605
8611
|
* ```ts
|
|
8606
|
-
*
|
|
8607
|
-
* const result = await db.table
|
|
8608
|
-
* .selectAll()
|
|
8612
|
+
* const updatedCount = await db.table
|
|
8609
8613
|
* .where(...conditions)
|
|
8610
8614
|
* .increment('numericColumn');
|
|
8615
|
+
* ```
|
|
8611
8616
|
*
|
|
8617
|
+
* When using `find` or `get` it will throw `NotFoundError` when no records found.
|
|
8618
|
+
*
|
|
8619
|
+
* ```ts
|
|
8620
|
+
* // throws when not found
|
|
8621
|
+
* const updatedCount = await db.table.find(1).increment('numericColumn');
|
|
8622
|
+
*
|
|
8623
|
+
* // also throws when not found
|
|
8624
|
+
* const updatedCount2 = await db.table
|
|
8625
|
+
* .where(...conditions)
|
|
8626
|
+
* .get('columnName')
|
|
8627
|
+
* .increment('numericColumn');
|
|
8628
|
+
* ```
|
|
8629
|
+
*
|
|
8630
|
+
* Provide an object to increment multiple columns with different values.
|
|
8631
|
+
* Use `select` to specify columns to return.
|
|
8632
|
+
*
|
|
8633
|
+
* ```ts
|
|
8612
8634
|
* // increment someColumn by 5 and otherColumn by 10, return updated records
|
|
8613
|
-
* const
|
|
8635
|
+
* const result = await db.table
|
|
8614
8636
|
* .selectAll()
|
|
8615
8637
|
* .where(...conditions)
|
|
8616
8638
|
* .increment({
|
|
@@ -8628,17 +8650,33 @@ class Update {
|
|
|
8628
8650
|
return applyCountChange(this, "+", data);
|
|
8629
8651
|
}
|
|
8630
8652
|
/**
|
|
8631
|
-
* Decrements a column
|
|
8653
|
+
* Decrements a column by `1`, returns a count of updated records by default.
|
|
8632
8654
|
*
|
|
8633
8655
|
* ```ts
|
|
8634
|
-
*
|
|
8635
|
-
* const result = await db.table
|
|
8636
|
-
* .selectAll()
|
|
8656
|
+
* const updatedCount = await db.table
|
|
8637
8657
|
* .where(...conditions)
|
|
8638
8658
|
* .decrement('numericColumn');
|
|
8659
|
+
* ```
|
|
8660
|
+
*
|
|
8661
|
+
* When using `find` or `get` it will throw `NotFoundError` when no records found.
|
|
8662
|
+
*
|
|
8663
|
+
* ```ts
|
|
8664
|
+
* // throws when not found
|
|
8665
|
+
* const updatedCount = await db.table.find(1).decrement('numericColumn');
|
|
8639
8666
|
*
|
|
8667
|
+
* // also throws when not found
|
|
8668
|
+
* const updatedCount2 = await db.table
|
|
8669
|
+
* .where(...conditions)
|
|
8670
|
+
* .get('columnName')
|
|
8671
|
+
* .decrement('numericColumn');
|
|
8672
|
+
* ```
|
|
8673
|
+
*
|
|
8674
|
+
* Provide an object to decrement multiple columns with different values.
|
|
8675
|
+
* Use `select` to specify columns to return.
|
|
8676
|
+
*
|
|
8677
|
+
* ```ts
|
|
8640
8678
|
* // decrement someColumn by 5 and otherColumn by 10, return updated records
|
|
8641
|
-
* const
|
|
8679
|
+
* const result = await db.table
|
|
8642
8680
|
* .selectAll()
|
|
8643
8681
|
* .where(...conditions)
|
|
8644
8682
|
* .decrement({
|