diff --git a/src/kv/commonKeyValueDB.ts b/src/kv/commonKeyValueDB.ts index c0c157a..ce6d22e 100644 --- a/src/kv/commonKeyValueDB.ts +++ b/src/kv/commonKeyValueDB.ts @@ -50,5 +50,12 @@ export interface CommonKeyValueDB { count: (table: string) => Promise + /** + * + * Increments the value of a key in a table by a given amount. + * Default increment is 1 when `by` is not provided. + * + * Returns the new value. + */ increment: (table: string, id: string, by?: number) => Promise } diff --git a/src/kv/commonKeyValueDao.ts b/src/kv/commonKeyValueDao.ts index 545fb09..8757b2c 100644 --- a/src/kv/commonKeyValueDao.ts +++ b/src/kv/commonKeyValueDao.ts @@ -253,6 +253,12 @@ export class CommonKeyValueDao { ) } + /** + * Increments the `id` field by the amount specified in `by`, + * or by 1 if `by` is not specified. + * + * Returns the new value of the field. + */ async increment(id: string, by = 1): Promise { return await this.cfg.db.increment(this.cfg.table, id, by) }