@naturalcycles/db-lib 9.1.0 → 9.1.1

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.
@@ -193,10 +193,10 @@ export declare class CommonDaoTransaction {
193
193
  * Perform a graceful rollback without throwing/re-throwing any error.
194
194
  */
195
195
  rollback(): Promise<void>;
196
- getById<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(dao: CommonDao<BM, DBM, any>, id: string, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
196
+ getById<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
197
197
  getByIds<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
198
198
  save<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(dao: CommonDao<BM, DBM, any>, bm: Unsaved<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
199
199
  saveBatch<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(dao: CommonDao<BM, DBM, any>, bms: Unsaved<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
200
- deleteById(dao: CommonDao<any>, id: string, opt?: CommonDaoOptions): Promise<number>;
200
+ deleteById(dao: CommonDao<any>, id?: string | null, opt?: CommonDaoOptions): Promise<number>;
201
201
  deleteByIds(dao: CommonDao<any>, ids: string[], opt?: CommonDaoOptions): Promise<number>;
202
202
  }
@@ -1080,6 +1080,8 @@ class CommonDaoTransaction {
1080
1080
  }
1081
1081
  }
1082
1082
  async getById(dao, id, opt) {
1083
+ if (!id)
1084
+ return null;
1083
1085
  return (await this.getByIds(dao, [id], opt))[0] || null;
1084
1086
  }
1085
1087
  async getByIds(dao, ids, opt) {
@@ -1105,6 +1107,8 @@ class CommonDaoTransaction {
1105
1107
  return await dao.saveBatch(bms, { ...opt, tx: this.tx });
1106
1108
  }
1107
1109
  async deleteById(dao, id, opt) {
1110
+ if (!id)
1111
+ return 0;
1108
1112
  return await this.deleteByIds(dao, [id], opt);
1109
1113
  }
1110
1114
  async deleteByIds(dao, ids, opt) {
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "engines": {
41
41
  "node": ">=18.12"
42
42
  },
43
- "version": "9.1.0",
43
+ "version": "9.1.1",
44
44
  "description": "Lowest Common Denominator API to supported Databases",
45
45
  "keywords": [
46
46
  "db",
@@ -1432,9 +1432,10 @@ export class CommonDaoTransaction {
1432
1432
 
1433
1433
  async getById<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId>(
1434
1434
  dao: CommonDao<BM, DBM, any>,
1435
- id: string,
1435
+ id?: string | null,
1436
1436
  opt?: CommonDaoOptions,
1437
1437
  ): Promise<Saved<BM> | null> {
1438
+ if (!id) return null
1438
1439
  return (await this.getByIds(dao, [id], opt))[0] || null
1439
1440
  }
1440
1441
 
@@ -1476,7 +1477,12 @@ export class CommonDaoTransaction {
1476
1477
  return await dao.saveBatch(bms, { ...opt, tx: this.tx })
1477
1478
  }
1478
1479
 
1479
- async deleteById(dao: CommonDao<any>, id: string, opt?: CommonDaoOptions): Promise<number> {
1480
+ async deleteById(
1481
+ dao: CommonDao<any>,
1482
+ id?: string | null,
1483
+ opt?: CommonDaoOptions,
1484
+ ): Promise<number> {
1485
+ if (!id) return 0
1480
1486
  return await this.deleteByIds(dao, [id], opt)
1481
1487
  }
1482
1488