sedentary-pg 0.0.30 → 0.0.33

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
@@ -22,6 +22,10 @@ const needUsing = [
22
22
  ];
23
23
  const types = { int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", timestamptz: "DATETIME", varchar: "VARCHAR" };
24
24
  const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
25
+ function parseInt8(value) {
26
+ return BigInt(value);
27
+ }
28
+ pg_1.types.setTypeParser(20, parseInt8);
25
29
  class PGDB extends sedentary_1.DB {
26
30
  constructor(connection, log) {
27
31
  super(log);
@@ -112,14 +116,34 @@ class PGDB extends sedentary_1.DB {
112
116
  return ret;
113
117
  };
114
118
  }
119
+ remove(tableName, pk) {
120
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
121
+ const self = this;
122
+ const pkAttrnName = pk.attributeName;
123
+ const pkFldName = pk.fieldName;
124
+ return async function () {
125
+ const client = this.tx ? this.tx.client : await self.pool.connect();
126
+ let removed = false;
127
+ try {
128
+ const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrnName])}`;
129
+ self.log(query);
130
+ removed = (await client.query(query)).rowCount === 1;
131
+ }
132
+ finally {
133
+ if (!this.tx)
134
+ client.release();
135
+ }
136
+ return removed;
137
+ };
138
+ }
115
139
  save(tableName, attributes, pk) {
116
140
  // eslint-disable-next-line @typescript-eslint/no-this-alias
117
141
  const self = this;
118
142
  const pkAttrnName = pk.attributeName;
119
143
  const pkFldName = pk.fieldName;
120
144
  return async function () {
121
- let changed = false;
122
145
  const client = this.tx ? this.tx.client : await self.pool.connect();
146
+ let changed = false;
123
147
  try {
124
148
  const { loaded } = this;
125
149
  if (loaded) {
package/dist/es/pgdb.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DatabaseError, Pool } from "pg";
1
+ import { DatabaseError, Pool, types as PGtypes } from "pg";
2
2
  import format from "pg-format";
3
3
  import { DB, Transaction } from "sedentary";
4
4
  import { adsrc } from "./adsrc";
@@ -16,6 +16,10 @@ const needUsing = [
16
16
  ];
17
17
  const types = { int2: "SMALLINT", int4: "INTEGER", int8: "BIGINT", timestamptz: "DATETIME", varchar: "VARCHAR" };
18
18
  const actions = { cascade: "c", "no action": "a", restrict: "r", "set default": "d", "set null": "n" };
19
+ function parseInt8(value) {
20
+ return BigInt(value);
21
+ }
22
+ PGtypes.setTypeParser(20, parseInt8);
19
23
  export class PGDB extends DB {
20
24
  client;
21
25
  indexes;
@@ -110,14 +114,34 @@ export class PGDB extends DB {
110
114
  return ret;
111
115
  };
112
116
  }
117
+ remove(tableName, pk) {
118
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
119
+ const self = this;
120
+ const pkAttrnName = pk.attributeName;
121
+ const pkFldName = pk.fieldName;
122
+ return async function () {
123
+ const client = this.tx ? this.tx.client : await self.pool.connect();
124
+ let removed = false;
125
+ try {
126
+ const query = `DELETE FROM ${tableName} WHERE ${pkFldName} = ${self.escape(this[pkAttrnName])}`;
127
+ self.log(query);
128
+ removed = (await client.query(query)).rowCount === 1;
129
+ }
130
+ finally {
131
+ if (!this.tx)
132
+ client.release();
133
+ }
134
+ return removed;
135
+ };
136
+ }
113
137
  save(tableName, attributes, pk) {
114
138
  // eslint-disable-next-line @typescript-eslint/no-this-alias
115
139
  const self = this;
116
140
  const pkAttrnName = pk.attributeName;
117
141
  const pkFldName = pk.fieldName;
118
142
  return async function () {
119
- let changed = false;
120
143
  const client = this.tx ? this.tx.client : await self.pool.connect();
144
+ let changed = false;
121
145
  try {
122
146
  const { loaded } = this;
123
147
  if (loaded) {
@@ -1,7 +1,7 @@
1
1
  import { Attribute, EntryBase, ForeignKeyOptions, Natural, Sedentary, SedentaryOptions, Type } from "sedentary";
2
2
  import { PoolConfig } from "pg";
3
3
  import { PGDB, TransactionPG } from "./pgdb";
4
- export { EntryBase, SedentaryOptions, Type } from "sedentary";
4
+ export { Entry, EntryBase, SedentaryOptions, Type } from "sedentary";
5
5
  export { TransactionPG } from "./pgdb";
6
6
  export declare class SedentaryPG extends Sedentary<PGDB, TransactionPG> {
7
7
  constructor(connection: PoolConfig, options?: SedentaryOptions);
@@ -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,20 +9,20 @@
9
9
  "@types/pg": "8.6.5",
10
10
  "pg": "8.7.3",
11
11
  "pg-format": "1.0.4",
12
- "sedentary": "0.0.30"
12
+ "sedentary": "0.0.33"
13
13
  },
14
14
  "description": "The ORM which never needs to migrate - PostgreSQL",
15
15
  "devDependencies": {
16
16
  "@types/mocha": "9.1.0",
17
- "@types/node": "17.0.23",
17
+ "@types/node": "17.0.24",
18
18
  "@types/pg-format": "1.0.2",
19
19
  "@types/yamljs": "0.2.31",
20
- "@typescript-eslint/eslint-plugin": "5.17.0",
21
- "@typescript-eslint/parser": "5.17.0",
22
- "eslint": "8.12.0",
20
+ "@typescript-eslint/eslint-plugin": "5.19.0",
21
+ "@typescript-eslint/parser": "5.19.0",
22
+ "eslint": "8.13.0",
23
23
  "mocha": "9.2.2",
24
24
  "nyc": "15.1.0",
25
- "prettier": "2.6.1",
25
+ "prettier": "2.6.2",
26
26
  "ts-node": "10.7.0",
27
27
  "typescript": "4.6.3",
28
28
  "yamljs": "0.3.0"
@@ -84,5 +84,5 @@
84
84
  }
85
85
  },
86
86
  "types": "./dist/types/index.d.ts",
87
- "version": "0.0.30"
87
+ "version": "0.0.33"
88
88
  }