@sqb/postgres 4.0.1-beta.44 → 4.0.1-beta.52

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.
@@ -9,6 +9,10 @@ export declare class PgConnection implements Adapter.Connection {
9
9
  startTransaction(): Promise<void>;
10
10
  commit(): Promise<void>;
11
11
  rollback(): Promise<void>;
12
+ setSavepoint(savepoint: string): Promise<void>;
13
+ releaseSavepoint(savepoint: string): Promise<void>;
14
+ rollbackSavepoint(savepoint: string): Promise<void>;
15
+ getInTransaction(): boolean;
12
16
  test(): Promise<void>;
13
17
  getSchema(): Promise<string>;
14
18
  setSchema(schema: string): Promise<void>;
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.PgConnection = void 0;
7
- const assert_1 = __importDefault(require("assert"));
8
4
  const connect_1 = require("@sqb/connect");
9
5
  const postgresql_client_1 = require("postgresql-client");
10
6
  const datatype_map_1 = require("./datatype-map");
@@ -43,11 +39,13 @@ class PgConnection {
43
39
  return this.rollback();
44
40
  }
45
41
  async startTransaction() {
46
- assert_1.default.ok(this.intlcon, 'Can not start transaction for a closed db session');
42
+ if (!this.intlcon)
43
+ throw new Error('Can not start transaction for a closed db session');
47
44
  await this.intlcon.startTransaction();
48
45
  }
49
46
  async commit() {
50
- assert_1.default.ok(this.intlcon, 'Can not commit transaction for a closed db session');
47
+ if (!this.intlcon)
48
+ throw new Error('Can not commit transaction for a closed db session');
51
49
  await this.intlcon.commit();
52
50
  }
53
51
  async rollback() {
@@ -55,19 +53,40 @@ class PgConnection {
55
53
  return;
56
54
  await this.intlcon.rollback();
57
55
  }
56
+ async setSavepoint(savepoint) {
57
+ if (!this.intlcon)
58
+ throw new Error('Can not set savepoint for a closed db session');
59
+ return this.intlcon.savepoint(savepoint);
60
+ }
61
+ async releaseSavepoint(savepoint) {
62
+ if (!this.intlcon)
63
+ throw new Error('Can not release savepoint for a closed db session');
64
+ return this.intlcon.releaseSavepoint(savepoint);
65
+ }
66
+ async rollbackSavepoint(savepoint) {
67
+ if (!this.intlcon)
68
+ throw new Error('Can not rollback to a savepoint for a closed db session');
69
+ return this.intlcon.rollbackToSavepoint(savepoint);
70
+ }
71
+ getInTransaction() {
72
+ return !!(this.intlcon && this.intlcon.inTransaction);
73
+ }
58
74
  async test() {
59
- assert_1.default.ok(this.intlcon, 'DB session is closed');
75
+ if (!this.intlcon)
76
+ throw new Error('DB session is closed');
60
77
  await this.intlcon.query('select 1');
61
78
  }
62
79
  async getSchema() {
63
- assert_1.default.ok(this.intlcon, 'DB session is closed');
80
+ if (!this.intlcon)
81
+ throw new Error('DB session is closed');
64
82
  const r = await this.intlcon.query('SHOW search_path');
65
83
  if (r && r.rows && r.rows[0])
66
84
  return r.rows[0][0];
67
85
  return '';
68
86
  }
69
87
  async setSchema(schema) {
70
- assert_1.default.ok(this.intlcon, 'Can not set schema of a closed db session');
88
+ if (!this.intlcon)
89
+ throw new Error('Can not set schema of a closed db session');
71
90
  await this.intlcon.execute('SET search_path TO ' + schema);
72
91
  }
73
92
  onGenerateQuery(request) {
@@ -77,7 +96,8 @@ class PgConnection {
77
96
  }
78
97
  }
79
98
  async execute(query) {
80
- assert_1.default.ok(this.intlcon, 'Can not execute query with a closed db session');
99
+ if (!this.intlcon)
100
+ throw new Error('Can not execute query with a closed db session');
81
101
  const params = query.params?.map((v, i) => {
82
102
  const paramOpts = Array.isArray(query.paramOptions) ? query.paramOptions[i] : undefined;
83
103
  if (v != null && paramOpts && paramOpts.dataType) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/postgres",
3
3
  "description": "SQB serialization extension for PostgreSQL database",
4
- "version": "4.0.1-beta.44",
4
+ "version": "4.0.1-beta.52",
5
5
  "author": "Panates Ltd.",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -27,11 +27,11 @@
27
27
  "putil-promisify": "^1.8.5"
28
28
  },
29
29
  "devDependencies": {
30
- "postgresql-client": "^1.16.7"
30
+ "postgresql-client": "^1.21.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "postgresql-client": "^1.16.7",
34
- "@sqb/postgres-dialect": "^4.0.1-beta.44"
33
+ "postgresql-client": "^1.21.0",
34
+ "@sqb/postgres-dialect": "^4.0.1-beta.52"
35
35
  },
36
36
  "main": "dist/index.js",
37
37
  "types": "dist/index.d.ts",