postgrejs 2.12.0 → 2.15.1

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +231 -191
  2. package/README.md +112 -96
  3. package/cjs/connection/connection.js +10 -5
  4. package/cjs/connection/cursor.js +2 -4
  5. package/cjs/connection/intl-connection.js +19 -12
  6. package/cjs/connection/pool.js +12 -6
  7. package/cjs/connection/prepared-statement.js +6 -3
  8. package/cjs/data-types/bytea-type.js +2 -4
  9. package/cjs/data-types/numeric-type.js +2 -2
  10. package/cjs/data-types/time-type.js +2 -1
  11. package/cjs/data-types/timestamp-type.js +2 -1
  12. package/cjs/data-types/timestamptz-type.js +2 -1
  13. package/cjs/index.js +26 -39
  14. package/cjs/protocol/frontend.js +8 -5
  15. package/cjs/protocol/pg-socket.js +33 -31
  16. package/cjs/protocol/sasl.js +14 -14
  17. package/cjs/protocol/smart-buffer.js +2 -24
  18. package/cjs/util/array-calculatedim.js +1 -2
  19. package/cjs/util/bigint-methods.js +2 -3
  20. package/cjs/util/config-from-env.js +1 -2
  21. package/cjs/util/connection-config.js +8 -11
  22. package/cjs/util/convert-row-to-object.js +1 -2
  23. package/cjs/util/decode-binaryarray.js +1 -2
  24. package/cjs/util/encode-binaryarray.js +1 -2
  25. package/cjs/util/escape-literal.js +1 -2
  26. package/cjs/util/fast-parseint.js +1 -2
  27. package/cjs/util/get-parsers.js +1 -2
  28. package/cjs/util/parse-array.js +1 -2
  29. package/cjs/util/parse-datetime.js +1 -2
  30. package/cjs/util/parse-row.js +1 -2
  31. package/cjs/util/parse-time.js +2 -2
  32. package/cjs/util/stringify-arrayliteral.js +1 -2
  33. package/cjs/util/stringify-for-sql.js +2 -3
  34. package/cjs/util/wrap-row-description.js +1 -2
  35. package/esm/connection/connection.js +10 -5
  36. package/esm/connection/intl-connection.js +17 -10
  37. package/esm/connection/pool.js +12 -6
  38. package/esm/connection/prepared-statement.js +6 -3
  39. package/esm/data-types/time-type.js +2 -1
  40. package/esm/data-types/timestamp-type.js +2 -1
  41. package/esm/data-types/timestamptz-type.js +2 -1
  42. package/esm/index.js +5 -5
  43. package/esm/protocol/frontend.js +8 -5
  44. package/esm/protocol/pg-socket.js +28 -24
  45. package/esm/protocol/sasl.js +12 -10
  46. package/esm/util/connection-config.js +4 -4
  47. package/package.json +5 -5
  48. package/typings/connection/connection.d.ts +0 -1
  49. package/typings/connection/cursor.d.ts +0 -1
  50. package/typings/connection/prepared-statement.d.ts +0 -1
  51. package/typings/index.d.ts +5 -5
  52. package/typings/interfaces/database-connection-params.d.ts +1 -1
  53. package/typings/protocol/backend.d.ts +0 -1
  54. package/typings/protocol/buffer-reader.d.ts +0 -1
  55. package/typings/protocol/frontend.d.ts +0 -1
  56. package/typings/protocol/pg-socket.d.ts +0 -1
  57. package/typings/protocol/protocol.d.ts +0 -1
  58. package/typings/protocol/smart-buffer.d.ts +0 -1
  59. package/typings/safe-event-emitter.d.ts +0 -1
  60. package/typings/types.d.ts +0 -1
  61. package/typings/util/bigint-methods.d.ts +0 -1
  62. package/typings/util/decode-binaryarray.d.ts +0 -1
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- ## postgresql-client
1
+ <!--suppress HtmlDeprecatedAttribute -->
2
+ <p align="center">¨
3
+ <a href="https://postgrejs.panates.com/" target="blank">
4
+ <img src="https://postgrejs.panates.com/img/postgrejs-header-block.png" width="800" alt="PostgreJS Logo" />
5
+ </a>
6
+ </p>
2
7
 
3
8
  [![NPM Version][npm-image]][npm-url]
4
9
  [![NPM Downloads][downloads-image]][downloads-url]
@@ -6,48 +11,59 @@
6
11
  [![Test Coverage][coveralls-image]][coveralls-url]
7
12
 
8
13
 
9
- Enterprise level PostgreSQL client for NodeJs
14
+ PostgreJS is a enterprise-level PostgreSQL client for Node.js.
15
+ It is designed to provide a robust and efficient interface to PostgreSQL databases,
16
+ ensuring high performance and reliability for enterprise applications.
17
+ Written entirely in TypeScript, it leverages modern JavaScript features to deliver a seamless development experience.
10
18
 
11
19
 
12
- ## Library
20
+ ## Library Overview
13
21
 
14
- - Pure JavaScript library completely written in TypeScript
15
- - Works with both CommonJS and ESM module systems
16
- - Well tested
17
- - Strictly typed
18
- - Asynchronous Promise based api
22
+ PostgreJS is a pure JavaScript library, meticulously crafted with TypeScript to offer a strictly typed, well-structured,
23
+ and highly maintainable codebase.
24
+ Key highlights include:
25
+
26
+ - **Language:** Pure modern JavaScript library.
27
+ - **Strictly Typed:** Completely written in TypeScript, offering strong typing and enhanced development experience.
28
+ - **Compatibility:** Works seamlessly with both CommonJS and ESM module systems, ensuring flexibility in various project setups.
29
+ - **Comprehensive Testing:** Rigorously tested to ensure stability and reliability in production environments.
30
+ - **Promise-Based API:** Asynchronous operations are handled with a Promise-based API, promoting clean and efficient asynchronous code.
19
31
 
20
32
  ## Features
21
33
 
22
- - Both single connection and advanced pooling support
23
- - Full binary wire protocol support for all data types
24
- - Named Prepared Statements
25
- - Cursors with fast double-link cache
26
- - High level implementation for notifications (LISTEN/NOTIFY)
27
- - Extensible data-types and type mapping
28
- - Bind parameters with OID mappings
29
- - Multidimensional arrays with fast binary encoding/decoding
30
- - Low memory utilization and boosted performance with Shared Buffers
31
- - Supports Clear text, MD5 and SASL password algorithms
32
- - Can return both array and object rows
33
- - Auto disposal with "using" syntax ([TC30 Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management))
34
+ - **Connection Management:** Supports both single connection and advanced pooling, providing scalability and efficient resource management.
35
+ - **Binary Wire Protocol:** Implements the full binary wire protocol for all PostgreSQL data types, ensuring robust and efficient data handling.
36
+ - **Prepared Statements:** Named prepared statements for optimized query execution.
37
+ - **Cursors:** Features fast double-link cache cursors for efficient data retrieval.
38
+ - **Notifications:** High-level implementation for PostgreSQL notifications (LISTEN/NOTIFY), enabling real-time data updates.
39
+ - **Extensibility:** Extensible data-types and type mapping to accommodate custom requirements.
40
+ - **Parameter Binding:** Bind parameters with OID mappings for precise and efficient query execution.
41
+ - **Array Handling:** Supports multidimensional arrays with fast binary encoding/decoding.
42
+ - **Performance Optimization:** Low memory utilization and boosted performance through the use of shared buffers.
43
+ - **Authorization:** SSupports various password algorithms including Clear text, MD5, and SASL, ensuring secure authentication.
44
+ - **Flexible Data Retrieval:** Can return both array and object rows to suit different data processing needs.
45
+ - **Resource Management:** Auto disposal of resources with the "using" syntax ([TC30 Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)), ensuring efficient resource cleanup.
46
+
47
+ Whether you're building a simple application or a complex enterprise system,
48
+ PostgreJS provides the features and performance you need to succeed.
49
+ Explore the capabilities of the library and elevate your PostgreSQL integration to the next level.
34
50
 
35
51
 
36
52
  ## Installation
37
53
 
38
54
  ```bash
39
- $ npm install postgresql-client --save
55
+ $ npm install postgrejs --save
40
56
  ```
41
57
 
42
58
  ## Documentation
43
- Please read :small_orange_diamond: [DOCUMENTATION](DOCUMENTATION.md) :small_orange_diamond: for detailed usage.
59
+ Please read :small_orange_diamond: [DOCUMENTATION](https://postgrejs.panates.com/) :small_orange_diamond: for detailed usage.
44
60
 
45
61
  ## Example usage
46
62
 
47
63
  ### Establish a single connection, execute a simple query
48
64
 
49
65
  ```ts
50
- import {Connection} from 'postgresql-client';
66
+ import {Connection} from 'postgrejs';
51
67
  // Create connection
52
68
  const connection = new Connection('postgres://localhost');
53
69
  // Connect to database server
@@ -66,7 +82,7 @@ await connection.close();
66
82
 
67
83
  ### Establish a pooled connection, create a cursor
68
84
  ```ts
69
- import {Pool} from 'postgresql-client';
85
+ import {Pool} from 'postgrejs';
70
86
 
71
87
  // Create connection pool
72
88
  const db = new Pool({
@@ -98,7 +114,7 @@ await db.close();
98
114
 
99
115
  ### Using prepared statements
100
116
  ```ts
101
- import {DataTypeOIDs} from 'postgresql-client';
117
+ import {DataTypeOIDs} from 'postgrejs';
102
118
 
103
119
  // .....
104
120
  const statement = await connection.prepare(
@@ -112,89 +128,89 @@ for (let i = 0; i < 100; i++) {
112
128
  await statement.close(); // When you done, close the statement to relase resources
113
129
  ```
114
130
 
115
- #### Check [DOCUMENTATION](DOCUMENTATION.md) for other examples.
131
+ #### Check [DOCUMENTATION](https://postgrejs.panates.com/) for other examples.
116
132
 
117
133
 
118
134
 
119
135
  ## Type mappings
120
136
  The table below lists builtin data type mappings.
121
137
 
122
- | Posgtres type | JS type | Receive | Send |
123
- |---------------|:------------|-------------|--------|
124
- | bool | boolean | text,binary | binary |
125
- | int2 | number | text,binary | binary |
126
- | int4 | number | text,binary | binary |
127
- | int8 | BigInt | text,binary | binary |
128
- | float4 | number | text,binary | binary |
129
- | float8 | number | text,binary | binary |
130
- | char | string | text,binary | binary |
131
- | bpchar | string | text,binary | binary |
132
- | varchar | string | text,binary | binary |
133
- | date | Date | text,binary | binary |
134
- | time | Date | text,binary | binary |
135
- | timestamp | Date | text,binary | binary |
136
- | timestamptz | Date | text,binary | binary |
137
- | oid | number | text,binary | binary |
138
- | bytea | Buffer | text,binary | binary |
139
- | uuid | string | text,binary | binary |
140
- | json | object | text,binary | binary |
141
- | jsonb | object | text,binary | binary |
142
- | xml | string | text,binary | binary |
143
- | point | Point | text,binary | binary |
144
- | circle | Circle | text,binary | binary |
145
- | lseg | Rectangle | text,binary | binary |
146
- | box | Rectangle | text,binary | binary |
147
- | int2Vector | number[] | text,binary | binary |
148
- | _bool | boolean[] | text,binary | binary |
149
- | _int2 | number[] | text,binary | binary |
150
- | _int4 | number[] | text,binary | binary |
151
- | _int8 | BigInt[] | text,binary | binary |
152
- | _float4 | number[] | text,binary | binary |
153
- | _float8 | number[] | text,binary | binary |
154
- | _char | string[] | text,binary | binary |
155
- | _bpchar | string[] | text,binary | binary |
156
- | _varchar | string[] | text,binary | binary |
157
- | _date | Date[] | text,binary | binary |
158
- | _time | Date[] | text,binary | binary |
159
- | _timestamp | Date[] | text,binary | binary |
160
- | _timestamptz | Date[] | text,binary | binary |
161
- | _uuid | string[] | text,binary | binary |
162
- | _oid | number[] | text,binary | binary |
163
- | _bytea | Buffer[] | text,binary | binary |
164
- | _json | object[] | text,binary | binary |
165
- | _jsonb | object[] | text,binary | binary |
166
- | _xml | string[] | text,binary | binary |
167
- | _point | Point[] | text,binary | binary |
168
- | _circle | Circle[] | text,binary | binary |
169
- | _lseg | Rectangle[] | text,binary | binary |
170
- | _box | Rectangle[] | text,binary | binary |
171
- | _int2Vector | number[][] | text,binary | binary |
138
+ | PosgtreSQL type | JS type | Receive | Send |
139
+ |-----------------|:------------|-------------|--------|
140
+ | bool | boolean | text,binary | binary |
141
+ | int2 | number | text,binary | binary |
142
+ | int4 | number | text,binary | binary |
143
+ | int8 | BigInt | text,binary | binary |
144
+ | float4 | number | text,binary | binary |
145
+ | float8 | number | text,binary | binary |
146
+ | char | string | text,binary | binary |
147
+ | bpchar | string | text,binary | binary |
148
+ | varchar | string | text,binary | binary |
149
+ | date | Date | text,binary | binary |
150
+ | time | Date | text,binary | binary |
151
+ | timestamp | Date | text,binary | binary |
152
+ | timestamptz | Date | text,binary | binary |
153
+ | oid | number | text,binary | binary |
154
+ | bytea | Buffer | text,binary | binary |
155
+ | uuid | string | text,binary | binary |
156
+ | json | object | text,binary | binary |
157
+ | jsonb | object | text,binary | binary |
158
+ | xml | string | text,binary | binary |
159
+ | point | Point | text,binary | binary |
160
+ | circle | Circle | text,binary | binary |
161
+ | lseg | Rectangle | text,binary | binary |
162
+ | box | Rectangle | text,binary | binary |
163
+ | int2Vector | number[] | text,binary | binary |
164
+ | _bool | boolean[] | text,binary | binary |
165
+ | _int2 | number[] | text,binary | binary |
166
+ | _int4 | number[] | text,binary | binary |
167
+ | _int8 | BigInt[] | text,binary | binary |
168
+ | _float4 | number[] | text,binary | binary |
169
+ | _float8 | number[] | text,binary | binary |
170
+ | _char | string[] | text,binary | binary |
171
+ | _bpchar | string[] | text,binary | binary |
172
+ | _varchar | string[] | text,binary | binary |
173
+ | _date | Date[] | text,binary | binary |
174
+ | _time | Date[] | text,binary | binary |
175
+ | _timestamp | Date[] | text,binary | binary |
176
+ | _timestamptz | Date[] | text,binary | binary |
177
+ | _uuid | string[] | text,binary | binary |
178
+ | _oid | number[] | text,binary | binary |
179
+ | _bytea | Buffer[] | text,binary | binary |
180
+ | _json | object[] | text,binary | binary |
181
+ | _jsonb | object[] | text,binary | binary |
182
+ | _xml | string[] | text,binary | binary |
183
+ | _point | Point[] | text,binary | binary |
184
+ | _circle | Circle[] | text,binary | binary |
185
+ | _lseg | Rectangle[] | text,binary | binary |
186
+ | _box | Rectangle[] | text,binary | binary |
187
+ | _int2Vector | number[][] | text,binary | binary |
172
188
 
173
189
 
174
190
  ## Support
175
- You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/postgresql-client/issues) page
191
+ You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/postgrejs/issues) page
176
192
  When you open an issue please provide version of NodeJS and PostgreSQL server.
177
193
 
178
194
  ## Node Compatibility
179
- - node >= 14.x
195
+ - node >= 16.x
180
196
 
181
197
 
182
198
  ## License
183
- postgresql-client is available under [MIT](LICENSE) license.
184
-
185
- [npm-image]: https://img.shields.io/npm/v/postgresql-client
186
- [npm-url]: https://npmjs.org/package/postgresql-client
187
- [circleci-image]: https://circleci.com/gh/panates/postgresql-client/tree/master.svg?style=shield
188
- [circleci-url]: https://circleci.com/gh/panates/postgresql-client/tree/master
189
- [coveralls-image]: https://img.shields.io/coveralls/panates/postgresql-client/master.svg
190
- [coveralls-url]: https://coveralls.io/r/panates/postgresql-client
191
- [downloads-image]: https://img.shields.io/npm/dm/postgresql-client.svg
192
- [downloads-url]: https://npmjs.org/package/postgresql-client
193
- [gitter-image]: https://badges.gitter.im/panates/postgresql-client.svg
194
- [gitter-url]: https://gitter.im/panates/postgresql-client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
195
- [dependencies-image]: https://david-dm.org/panates/postgresql-client/status.svg
196
- [dependencies-url]:https://david-dm.org/panates/postgresql-client
197
- [devdependencies-image]: https://david-dm.org/panates/postgresql-client/dev-status.svg
198
- [devdependencies-url]:https://david-dm.org/panates/postgresql-client?type=dev
199
- [quality-image]: http://npm.packagequality.com/shield/postgresql-client.png
200
- [quality-url]: http://packagequality.com/#?package=postgresql-client
199
+ postgrejs is available under [MIT](LICENSE) license.
200
+
201
+ [npm-image]: https://img.shields.io/npm/v/postgrejs
202
+ [npm-url]: https://npmjs.org/package/postgrejs
203
+ [circleci-image]: https://circleci.com/gh/panates/postgrejs/tree/master.svg?style=shield
204
+ [circleci-url]: https://circleci.com/gh/panates/postgrejs/tree/master
205
+ [coveralls-image]: https://img.shields.io/coveralls/panates/postgrejs/master.svg
206
+ [coveralls-url]: https://coveralls.io/r/panates/postgrejs
207
+ [downloads-image]: https://img.shields.io/npm/dm/postgrejs.svg
208
+ [downloads-url]: https://npmjs.org/package/postgrejs
209
+ [gitter-image]: https://badges.gitter.im/panates/postgrejs.svg
210
+ [gitter-url]: https://gitter.im/panates/postgrejs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
211
+ [dependencies-image]: https://david-dm.org/panates/postgrejs/status.svg
212
+ [dependencies-url]:https://david-dm.org/panates/postgrejs
213
+ [devdependencies-image]: https://david-dm.org/panates/postgrejs/dev-status.svg
214
+ [devdependencies-url]:https://david-dm.org/panates/postgrejs?type=dev
215
+ [quality-image]: http://npm.packagequality.com/shield/postgrejs.png
216
+ [quality-url]: http://packagequality.com/#?package=postgrejs
@@ -86,34 +86,37 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
86
86
  if (this.state === constants_js_1.ConnectionState.CLOSED || this._closing)
87
87
  return;
88
88
  /* istanbul ignore next */
89
- if (this.listenerCount('debug'))
89
+ if (this.listenerCount('debug')) {
90
90
  this.emit('debug', {
91
91
  location: 'Connection.close',
92
92
  connection: this,
93
93
  message: `[${this.processID}] closing`,
94
94
  });
95
+ }
95
96
  this._closing = true;
96
97
  if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) {
97
98
  const startTime = Date.now();
98
99
  return this._captureErrorStack(new Promise((resolve, reject) => {
99
100
  /* istanbul ignore next */
100
- if (this.listenerCount('debug'))
101
+ if (this.listenerCount('debug')) {
101
102
  this.emit('debug', {
102
103
  location: 'Connection.close',
103
104
  connection: this,
104
105
  message: `[${this.processID}] waiting active queries`,
105
106
  });
107
+ }
106
108
  const timer = setInterval(() => {
107
109
  if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) {
108
110
  clearInterval(timer);
109
111
  if (this._intlCon.refCount > 0) {
110
112
  /* istanbul ignore next */
111
- if (this.listenerCount('debug'))
113
+ if (this.listenerCount('debug')) {
112
114
  this.emit('debug', {
113
115
  location: 'Connection.close',
114
116
  connection: this,
115
117
  message: `[${this.processID}] terminate`,
116
118
  });
119
+ }
117
120
  this.emit('terminate');
118
121
  }
119
122
  this._close().then(resolve).catch(reject);
@@ -137,13 +140,14 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
137
140
  async query(sql, options) {
138
141
  this._intlCon.assertConnected();
139
142
  /* istanbul ignore next */
140
- if (this.listenerCount('debug'))
143
+ if (this.listenerCount('debug')) {
141
144
  this.emit('debug', {
142
145
  location: 'Connection.query',
143
146
  connection: this,
144
147
  message: `[${this.processID}] query | ${sql}`,
145
148
  sql,
146
149
  });
150
+ }
147
151
  const typeMap = options?.typeMap || data_type_map_js_1.GlobalTypeMap;
148
152
  const paramTypes = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.oid : typeMap.determine(prm));
149
153
  const statement = await this.prepare(sql, { paramTypes, typeMap }).catch((e) => {
@@ -164,13 +168,14 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
164
168
  */
165
169
  async prepare(sql, options) {
166
170
  /* istanbul ignore next */
167
- if (this.listenerCount('debug'))
171
+ if (this.listenerCount('debug')) {
168
172
  this.emit('debug', {
169
173
  location: 'Connection.prepare',
170
174
  connection: this,
171
175
  message: `[${this.processID}] prepare | ${sql}`,
172
176
  sql,
173
177
  });
178
+ }
174
179
  return await this._captureErrorStack(prepared_statement_js_1.PreparedStatement.prepare(this, sql, options));
175
180
  }
176
181
  /**
@@ -1,10 +1,8 @@
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.Cursor = void 0;
7
- const doublylinked_1 = __importDefault(require("doublylinked"));
4
+ const tslib_1 = require("tslib");
5
+ const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
8
6
  const power_tasks_1 = require("power-tasks");
9
7
  const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
10
8
  const convert_row_to_object_js_1 = require("../util/convert-row-to-object.js");
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntlConnection = exports.IntlConnection = void 0;
3
+ exports.IntlConnection = void 0;
4
+ exports.getIntlConnection = getIntlConnection;
4
5
  const power_tasks_1 = require("power-tasks");
5
6
  const putil_varhelpers_1 = require("putil-varhelpers");
6
7
  const constants_js_1 = require("../constants.js");
@@ -112,8 +113,9 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
112
113
  const result = await this._execute(sql, options, cb);
113
114
  if (commitLast)
114
115
  await this._execute('COMMIT');
115
- else if (this.inTransaction && rollbackOnError)
116
+ else if (this.inTransaction && rollbackOnError) {
116
117
  await this._execute('RELEASE ' + this._onErrorSavePoint + ';');
118
+ }
117
119
  return result;
118
120
  }
119
121
  catch (e) {
@@ -194,20 +196,23 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
194
196
  current.rows = [];
195
197
  break;
196
198
  case protocol_js_1.Protocol.BackendMessageCode.DataRow:
197
- let row = msg.columns.map((x) => x.toString('utf8'));
198
- (0, parse_row_js_1.parseRow)(parsers, row, opts);
199
- if (opts.objectRows && current.fields)
200
- row = (0, convert_row_to_object_js_1.convertRowToObject)(current.fields, row);
201
- if (cb)
202
- cb('row', row);
203
- current.rows = current.rows || [];
204
- current.rows.push(row);
199
+ {
200
+ let row = msg.columns.map((x) => x.toString('utf8'));
201
+ (0, parse_row_js_1.parseRow)(parsers, row, opts);
202
+ if (opts.objectRows && current.fields)
203
+ row = (0, convert_row_to_object_js_1.convertRowToObject)(current.fields, row);
204
+ if (cb)
205
+ cb('row', row);
206
+ current.rows = current.rows || [];
207
+ current.rows.push(row);
208
+ }
205
209
  break;
206
210
  case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
207
211
  // Ignore BEGIN command that we added to sql
208
212
  current.command = msg.command;
209
- if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE')
213
+ if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') {
210
214
  current.rowsAffected = msg.rowCount;
215
+ }
211
216
  current.executeTime = Date.now() - currentStart;
212
217
  if (current.rows)
213
218
  current.rowType = opts.objectRows && current.fields ? 'object' : 'array';
@@ -223,6 +228,9 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
223
228
  // Ignore COMMIT command that we added to sql
224
229
  result.totalCommands = result.results.length;
225
230
  done(undefined, result);
231
+ break;
232
+ default:
233
+ break;
226
234
  }
227
235
  });
228
236
  }
@@ -240,4 +248,3 @@ exports.IntlConnection = IntlConnection;
240
248
  function getIntlConnection(connection) {
241
249
  return connection._intlCon;
242
250
  }
243
- exports.getIntlConnection = getIntlConnection;
@@ -28,42 +28,46 @@ class Pool extends safe_event_emitter_js_1.SafeEventEmitter {
28
28
  const poolFactory = {
29
29
  create: async () => {
30
30
  /* istanbul ignore next */
31
- if (this.listenerCount('debug'))
31
+ if (this.listenerCount('debug')) {
32
32
  this.emit('debug', {
33
33
  location: 'Pool.factory.create',
34
34
  pool: this,
35
35
  message: `new connection creating`,
36
36
  });
37
+ }
37
38
  const intlCon = new intl_connection_js_1.IntlConnection(cfg);
38
39
  await intlCon.connect();
39
40
  intlCon.on('close', () => this._pool.destroy(intlCon));
40
41
  /* istanbul ignore next */
41
- if (this.listenerCount('debug'))
42
+ if (this.listenerCount('debug')) {
42
43
  this.emit('debug', {
43
44
  location: 'Pool.factory.create',
44
45
  pool: this,
45
46
  message: `[${intlCon.processID}] connection created`,
46
47
  });
48
+ }
47
49
  return intlCon;
48
50
  },
49
51
  destroy: intlCon => {
50
52
  /* istanbul ignore next */
51
- if (this.listenerCount('debug'))
53
+ if (this.listenerCount('debug')) {
52
54
  this.emit('debug', {
53
55
  location: 'Pool.factory.destroy',
54
56
  pool: this,
55
57
  message: `[${intlCon.processID}] connection destroy`,
56
58
  });
59
+ }
57
60
  return intlCon.close();
58
61
  },
59
62
  reset: async (intlCon) => {
60
63
  /* istanbul ignore next */
61
- if (this.listenerCount('debug'))
64
+ if (this.listenerCount('debug')) {
62
65
  this.emit('debug', {
63
66
  location: 'Pool.factory.reset',
64
67
  pool: this,
65
68
  message: `[${intlCon.processID}] connection reset`,
66
69
  });
70
+ }
67
71
  try {
68
72
  if (intlCon.state === constants_js_1.ConnectionState.READY) {
69
73
  await intlCon.execute('ROLLBACK;UNLISTEN *');
@@ -77,12 +81,13 @@ class Pool extends safe_event_emitter_js_1.SafeEventEmitter {
77
81
  },
78
82
  validate: async (intlCon) => {
79
83
  /* istanbul ignore next */
80
- if (this.listenerCount('debug'))
84
+ if (this.listenerCount('debug')) {
81
85
  this.emit('debug', {
82
86
  location: 'Pool.factory.validate',
83
87
  pool: this,
84
88
  message: `[${intlCon.processID}] connection validate`,
85
89
  });
90
+ }
86
91
  if (intlCon.state !== constants_js_1.ConnectionState.READY)
87
92
  throw new Error('Connection is not active');
88
93
  await intlCon.execute('select 1;');
@@ -119,12 +124,13 @@ class Pool extends safe_event_emitter_js_1.SafeEventEmitter {
119
124
  async acquire() {
120
125
  const intlCon = await this._pool.acquire();
121
126
  /* istanbul ignore next */
122
- if (this.listenerCount('debug'))
127
+ if (this.listenerCount('debug')) {
123
128
  this.emit('debug', {
124
129
  location: 'Pool.acquire',
125
130
  pool: this,
126
131
  message: `[${intlCon.processID}] acquired`,
127
132
  });
133
+ }
128
134
  const connection = new connection_js_1.Connection(this, intlCon);
129
135
  /* istanbul ignore next */
130
136
  if (this.listenerCount('debug'))
@@ -103,13 +103,15 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
103
103
  const result = await intlCon.statementQueue.enqueue(() => this._execute(options)).toPromise();
104
104
  if (commitLast)
105
105
  await intlCon.execute('COMMIT');
106
- else if (intlCon.inTransaction && rollbackOnError)
106
+ else if (intlCon.inTransaction && rollbackOnError) {
107
107
  await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';');
108
+ }
108
109
  return result;
109
110
  }
110
111
  catch (e) {
111
- if (intlCon.inTransaction && rollbackOnError)
112
+ if (intlCon.inTransaction && rollbackOnError) {
112
113
  await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';');
114
+ }
113
115
  throw e;
114
116
  }
115
117
  }
@@ -169,8 +171,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
169
171
  }
170
172
  }
171
173
  }
172
- if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE')
174
+ if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') {
173
175
  result.rowsAffected = executeResult.rowCount;
176
+ }
174
177
  result.executeTime = Date.now() - startTime;
175
178
  return result;
176
179
  }
@@ -1,10 +1,8 @@
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.ArrayByteaType = exports.ByteaType = void 0;
7
- const postgres_bytea_1 = __importDefault(require("postgres-bytea"));
4
+ const tslib_1 = require("tslib");
5
+ const postgres_bytea_1 = tslib_1.__importDefault(require("postgres-bytea"));
8
6
  const constants_js_1 = require("../constants.js");
9
7
  exports.ByteaType = {
10
8
  name: 'bytea',
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberBytesToString = exports.ArrayNumericType = exports.NumericType = void 0;
3
+ exports.ArrayNumericType = exports.NumericType = void 0;
4
+ exports.numberBytesToString = numberBytesToString;
4
5
  const constants_js_1 = require("../constants.js");
5
6
  const NUMERIC_NEG = 0x4000;
6
7
  const NUMERIC_NAN = 0xc000;
@@ -93,7 +94,6 @@ function numberBytesToString(digits, scale, weight, sign) {
93
94
  const extra = (i - scale) % DEC_DIGITS;
94
95
  return out.substr(0, out.length - extra);
95
96
  }
96
- exports.numberBytesToString = numberBytesToString;
97
97
  /* https://github.com/pgjdbc/pgjdbc/blob/3eca3a76aa4a04cb28cb960ed674cb67db30b5e3/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java */
98
98
  /**
99
99
  * Convert a number from binary representation to text representation.
@@ -13,8 +13,9 @@ exports.TimeType = {
13
13
  const hi = v.readInt32BE();
14
14
  const lo = v.readUInt32BE(4);
15
15
  let d = new Date((lo + hi * timeMul) / 1000);
16
- if (fetchAsString || !options.utcDates)
16
+ if (fetchAsString || !options.utcDates) {
17
17
  d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
18
+ }
18
19
  return fetchAsString ? dateToTimeString(d) : d;
19
20
  },
20
21
  encodeBinary(buf, v, options) {
@@ -19,8 +19,9 @@ exports.TimestampType = {
19
19
  return fetchAsString ? '-infinity' : -Infinity;
20
20
  // Shift from 2000 to 1970
21
21
  let d = new Date((lo + hi * timeMul) / 1000 + timeShift);
22
- if (fetchAsString || !options.utcDates)
22
+ if (fetchAsString || !options.utcDates) {
23
23
  d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
24
+ }
24
25
  return fetchAsString ? dateToTimestampString(d) : d;
25
26
  },
26
27
  encodeBinary(buf, v, options) {
@@ -19,8 +19,9 @@ exports.TimestamptzType = {
19
19
  return fetchAsString ? '-infinity' : -Infinity;
20
20
  // Shift from 2000 to 1970
21
21
  let d = new Date((lo + hi * timeMul) / 1000 + timeShift);
22
- if (fetchAsString || !options.utcDates)
22
+ if (fetchAsString || !options.utcDates) {
23
23
  d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
24
+ }
24
25
  return fetchAsString ? dateToTimestamptzString(d) : d;
25
26
  },
26
27
  encodeBinary(buf, v, options) {