sedentary-pg 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/pgdb.js CHANGED
@@ -112,14 +112,34 @@ class PGDB extends sedentary_1.DB {
112
112
  return ret;
113
113
  };
114
114
  }
115
+ remove(tableName, pk) {
116
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
117
+ const self = this;
118
+ const pkAttrnName = pk.attributeName;
119
+ const pkFldName = pk.fieldName;
120
+ return async function () {
121
+ const client = this.tx ? this.tx.client : await self.pool.connect();
122
+ let removed = false;
123
+ try {
124
+ const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrnName])}`;
125
+ self.log(query);
126
+ removed = (await client.query(query)).rowCount === 1;
127
+ }
128
+ finally {
129
+ if (!this.tx)
130
+ client.release();
131
+ }
132
+ return removed;
133
+ };
134
+ }
115
135
  save(tableName, attributes, pk) {
116
136
  // eslint-disable-next-line @typescript-eslint/no-this-alias
117
137
  const self = this;
118
138
  const pkAttrnName = pk.attributeName;
119
139
  const pkFldName = pk.fieldName;
120
140
  return async function () {
121
- let changed = false;
122
141
  const client = this.tx ? this.tx.client : await self.pool.connect();
142
+ let changed = false;
123
143
  try {
124
144
  const { loaded } = this;
125
145
  if (loaded) {
package/dist/es/pgdb.js CHANGED
@@ -110,14 +110,34 @@ export class PGDB extends DB {
110
110
  return ret;
111
111
  };
112
112
  }
113
+ remove(tableName, pk) {
114
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
115
+ const self = this;
116
+ const pkAttrnName = pk.attributeName;
117
+ const pkFldName = pk.fieldName;
118
+ return async function () {
119
+ const client = this.tx ? this.tx.client : await self.pool.connect();
120
+ let removed = false;
121
+ try {
122
+ const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrnName])}`;
123
+ self.log(query);
124
+ removed = (await client.query(query)).rowCount === 1;
125
+ }
126
+ finally {
127
+ if (!this.tx)
128
+ client.release();
129
+ }
130
+ return removed;
131
+ };
132
+ }
113
133
  save(tableName, attributes, pk) {
114
134
  // eslint-disable-next-line @typescript-eslint/no-this-alias
115
135
  const self = this;
116
136
  const pkAttrnName = pk.attributeName;
117
137
  const pkFldName = pk.fieldName;
118
138
  return async function () {
119
- let changed = false;
120
139
  const client = this.tx ? this.tx.client : await self.pool.connect();
140
+ let changed = false;
121
141
  try {
122
142
  const { loaded } = this;
123
143
  if (loaded) {
@@ -14,6 +14,9 @@ export declare class PGDB extends DB<TransactionPG> {
14
14
  escape(value: Natural): string;
15
15
  fill(attributes: Record<string, string>, row: Record<string, Natural>, entry: Record<string, Natural>): void;
16
16
  load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new (from: "load") => EntryBase, table: Table): (where: string, order?: string[], tx?: Transaction) => Promise<EntryBase[]>;
17
+ remove(tableName: string, pk: Attribute<Natural, unknown>): (this: Record<string, Natural> & {
18
+ tx?: TransactionPG;
19
+ }) => Promise<boolean>;
17
20
  save(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>): (this: Record<string, Natural> & {
18
21
  loaded?: Record<string, unknown>;
19
22
  tx?: TransactionPG;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "@types/pg": "8.6.5",
10
10
  "pg": "8.7.3",
11
11
  "pg-format": "1.0.4",
12
- "sedentary": "0.0.31"
12
+ "sedentary": "0.0.32"
13
13
  },
14
14
  "description": "The ORM which never needs to migrate - PostgreSQL",
15
15
  "devDependencies": {
@@ -84,5 +84,5 @@
84
84
  }
85
85
  },
86
86
  "types": "./dist/types/index.d.ts",
87
- "version": "0.0.31"
87
+ "version": "0.0.32"
88
88
  }