sedentary 0.0.31 → 0.0.32

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/cjs/db.js CHANGED
@@ -13,9 +13,14 @@ class EntryBase {
13
13
  }
14
14
  construct() { }
15
15
  postLoad() { }
16
+ postRemove() { }
16
17
  postSave() { }
17
18
  preLoad() { }
19
+ preRemove() { }
18
20
  preSave() { }
21
+ async remove() {
22
+ return false;
23
+ }
19
24
  async save() {
20
25
  return false;
21
26
  }
package/dist/cjs/index.js CHANGED
@@ -449,6 +449,17 @@ class Sedentary {
449
449
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
450
450
  Object.defineProperty(ret, "methods", { value: methods });
451
451
  Object.assign(ret.prototype, methods);
452
+ const remove = this.db.remove(tableName, pk);
453
+ ret.prototype.remove = async function () {
454
+ if (!this.loaded)
455
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
456
+ this.preRemove();
457
+ const ret = await remove.call(this);
458
+ if (ret)
459
+ this.postRemove();
460
+ return ret;
461
+ };
462
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
452
463
  const save = this.db.save(tableName, attr2field, pk);
453
464
  ret.prototype.save = async function () {
454
465
  this.preSave();
package/dist/es/db.js CHANGED
@@ -10,9 +10,14 @@ export class EntryBase {
10
10
  }
11
11
  construct() { }
12
12
  postLoad() { }
13
+ postRemove() { }
13
14
  postSave() { }
14
15
  preLoad() { }
16
+ preRemove() { }
15
17
  preSave() { }
18
+ async remove() {
19
+ return false;
20
+ }
16
21
  async save() {
17
22
  return false;
18
23
  }
package/dist/es/index.js CHANGED
@@ -443,6 +443,17 @@ export class Sedentary {
443
443
  Object.defineProperty(ret, "foreignKeys", { value: foreignKeys });
444
444
  Object.defineProperty(ret, "methods", { value: methods });
445
445
  Object.assign(ret.prototype, methods);
446
+ const remove = this.db.remove(tableName, pk);
447
+ ret.prototype.remove = async function () {
448
+ if (!this.loaded)
449
+ throw new Error(`${modelName}.remove: Can't remove a never saved Entry`);
450
+ this.preRemove();
451
+ const ret = await remove.call(this);
452
+ if (ret)
453
+ this.postRemove();
454
+ return ret;
455
+ };
456
+ Object.defineProperty(ret.prototype.remove, "name", { value: modelName + ".remove" });
446
457
  const save = this.db.save(tableName, attr2field, pk);
447
458
  ret.prototype.save = async function () {
448
459
  this.preSave();
@@ -3,9 +3,12 @@ export declare class EntryBase {
3
3
  constructor(from?: Partial<EntryBase>);
4
4
  construct(): void;
5
5
  postLoad(): void;
6
+ postRemove(): void;
6
7
  postSave(): void;
7
8
  preLoad(): void;
9
+ preRemove(): void;
8
10
  preSave(): void;
11
+ remove(): Promise<boolean>;
9
12
  save(): Promise<boolean>;
10
13
  }
11
14
  export declare type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
@@ -85,6 +88,7 @@ export declare abstract class DB<T extends Transaction> {
85
88
  abstract begin(): Promise<T>;
86
89
  abstract escape(value: Natural): string;
87
90
  abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string[], tx?: Transaction, lock?: boolean) => Promise<EntryBase[]>;
91
+ abstract remove(tableName: string, pk: Attribute<Natural, unknown>): (this: EntryBase & Record<string, Natural>) => Promise<boolean>;
88
92
  abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>): (this: EntryBase & Record<string, Natural>) => Promise<boolean>;
89
93
  abstract dropConstraints(table: Table): Promise<number[]>;
90
94
  abstract dropFields(table: Table): Promise<void>;
package/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  }
80
80
  },
81
81
  "types": "./dist/types/index.d.ts",
82
- "version": "0.0.31"
82
+ "version": "0.0.32"
83
83
  }