@tstdl/base 0.92.74 → 0.92.76

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.
@@ -78,7 +78,8 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
78
78
  deleteManyByQuery(query: Query<T>, metadataUpdate?: EntityMetadataUpdate): Promise<T[]>;
79
79
  hardDelete(id: string): Promise<void>;
80
80
  tryHardDelete(id: string): Promise<boolean>;
81
- hardDeleteByQuery(query: Query<T>): Promise<boolean>;
81
+ hardDeleteByQuery(query: Query<T>): Promise<void>;
82
+ tryHardDeleteByQuery(query: Query<T>): Promise<boolean>;
82
83
  hardDeleteMany(ids: string[]): Promise<number>;
83
84
  hardDeleteManyByQuery(query: Query<T>): Promise<number>;
84
85
  protected convertQuery(query: Query<T>): SQL;
@@ -359,16 +359,22 @@ let EntityRepository = class EntityRepository {
359
359
  }
360
360
  }
361
361
  async tryHardDelete(id) {
362
- const result = await this.session.delete(this.table).where(eq(this.table.id, id));
363
- console.log({ deleteResult: result });
362
+ const result = await this.session
363
+ .delete(this.table)
364
+ .where(eq(this.table.id, id));
364
365
  return isNotNull(result.rowCount) && (result.rowCount > 0);
365
366
  }
366
367
  async hardDeleteByQuery(query) {
368
+ const result = await this.tryHardDeleteByQuery(query);
369
+ if (!result) {
370
+ throw new NotFoundError(`${this.type.entityName} not found.`);
371
+ }
372
+ }
373
+ async tryHardDeleteByQuery(query) {
367
374
  const idQuery = this.getIdLimitQuery(query);
368
375
  const result = await this.session
369
376
  .delete(this.table)
370
377
  .where(inArray(this.table.id, idQuery));
371
- console.log({ deleteResult: result });
372
378
  return isNotNull(result.rowCount) && (result.rowCount > 0);
373
379
  }
374
380
  async hardDeleteMany(ids) {
@@ -376,8 +382,9 @@ let EntityRepository = class EntityRepository {
376
382
  }
377
383
  async hardDeleteManyByQuery(query) {
378
384
  const sqlQuery = this.convertQuery(query);
379
- const result = await this.session.delete(this.table).where(sqlQuery);
380
- console.log({ deleteResult: result });
385
+ const result = await this.session
386
+ .delete(this.table)
387
+ .where(sqlQuery);
381
388
  return assertNotNullPass(result.rowCount);
382
389
  }
383
390
  convertQuery(query) {
@@ -446,7 +453,7 @@ let EntityRepository = class EntityRepository {
446
453
  if (isUndefined(attributes)) {
447
454
  return undefined;
448
455
  }
449
- return sql `${this.table.attributes} || '${JSON.stringify(attributes)}'::jsonb`;
456
+ return sql `${this.table.attributes} || ${JSON.stringify(attributes)}::jsonb`;
450
457
  }
451
458
  async getTransformContext() {
452
459
  if (isUndefined(this.#transformContext)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.74",
3
+ "version": "0.92.76",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"