postgrejs 2.12.0 → 2.15.0
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/CHANGELOG.md +215 -191
- package/README.md +25 -25
- package/cjs/connection/connection.js +10 -5
- package/cjs/connection/cursor.js +2 -4
- package/cjs/connection/intl-connection.js +19 -12
- package/cjs/connection/pool.js +12 -6
- package/cjs/connection/prepared-statement.js +6 -3
- package/cjs/data-types/bytea-type.js +2 -4
- package/cjs/data-types/numeric-type.js +2 -2
- package/cjs/data-types/time-type.js +2 -1
- package/cjs/data-types/timestamp-type.js +2 -1
- package/cjs/data-types/timestamptz-type.js +2 -1
- package/cjs/index.js +26 -39
- package/cjs/protocol/frontend.js +8 -5
- package/cjs/protocol/pg-socket.js +33 -31
- package/cjs/protocol/sasl.js +14 -14
- package/cjs/protocol/smart-buffer.js +2 -24
- package/cjs/util/array-calculatedim.js +1 -2
- package/cjs/util/bigint-methods.js +2 -3
- package/cjs/util/config-from-env.js +1 -2
- package/cjs/util/connection-config.js +8 -11
- package/cjs/util/convert-row-to-object.js +1 -2
- package/cjs/util/decode-binaryarray.js +1 -2
- package/cjs/util/encode-binaryarray.js +1 -2
- package/cjs/util/escape-literal.js +1 -2
- package/cjs/util/fast-parseint.js +1 -2
- package/cjs/util/get-parsers.js +1 -2
- package/cjs/util/parse-array.js +1 -2
- package/cjs/util/parse-datetime.js +1 -2
- package/cjs/util/parse-row.js +1 -2
- package/cjs/util/parse-time.js +2 -2
- package/cjs/util/stringify-arrayliteral.js +1 -2
- package/cjs/util/stringify-for-sql.js +2 -3
- package/cjs/util/wrap-row-description.js +1 -2
- package/esm/connection/connection.js +10 -5
- package/esm/connection/intl-connection.js +17 -10
- package/esm/connection/pool.js +12 -6
- package/esm/connection/prepared-statement.js +6 -3
- package/esm/data-types/time-type.js +2 -1
- package/esm/data-types/timestamp-type.js +2 -1
- package/esm/data-types/timestamptz-type.js +2 -1
- package/esm/index.js +5 -5
- package/esm/protocol/frontend.js +8 -5
- package/esm/protocol/pg-socket.js +28 -24
- package/esm/protocol/sasl.js +12 -10
- package/esm/util/connection-config.js +4 -4
- package/package.json +5 -5
- package/typings/connection/connection.d.ts +0 -1
- package/typings/connection/cursor.d.ts +0 -1
- package/typings/connection/prepared-statement.d.ts +0 -1
- package/typings/index.d.ts +5 -5
- package/typings/interfaces/database-connection-params.d.ts +1 -1
- package/typings/protocol/backend.d.ts +0 -1
- package/typings/protocol/buffer-reader.d.ts +0 -1
- package/typings/protocol/frontend.d.ts +0 -1
- package/typings/protocol/pg-socket.d.ts +0 -1
- package/typings/protocol/protocol.d.ts +0 -1
- package/typings/protocol/smart-buffer.d.ts +0 -1
- package/typings/safe-event-emitter.d.ts +0 -1
- package/typings/types.d.ts +0 -1
- package/typings/util/bigint-methods.d.ts +0 -1
- package/typings/util/decode-binaryarray.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
##
|
|
1
|
+
## postgrejs
|
|
2
2
|
|
|
3
3
|
[![NPM Version][npm-image]][npm-url]
|
|
4
4
|
[![NPM Downloads][downloads-image]][downloads-url]
|
|
@@ -36,7 +36,7 @@ Enterprise level PostgreSQL client for NodeJs
|
|
|
36
36
|
## Installation
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
$ npm install
|
|
39
|
+
$ npm install postgrejs --save
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## Documentation
|
|
@@ -47,7 +47,7 @@ Please read :small_orange_diamond: [DOCUMENTATION](DOCUMENTATION.md) :small_oran
|
|
|
47
47
|
### Establish a single connection, execute a simple query
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
import {Connection} from '
|
|
50
|
+
import {Connection} from 'postgrejs';
|
|
51
51
|
// Create connection
|
|
52
52
|
const connection = new Connection('postgres://localhost');
|
|
53
53
|
// Connect to database server
|
|
@@ -66,7 +66,7 @@ await connection.close();
|
|
|
66
66
|
|
|
67
67
|
### Establish a pooled connection, create a cursor
|
|
68
68
|
```ts
|
|
69
|
-
import {Pool} from '
|
|
69
|
+
import {Pool} from 'postgrejs';
|
|
70
70
|
|
|
71
71
|
// Create connection pool
|
|
72
72
|
const db = new Pool({
|
|
@@ -98,7 +98,7 @@ await db.close();
|
|
|
98
98
|
|
|
99
99
|
### Using prepared statements
|
|
100
100
|
```ts
|
|
101
|
-
import {DataTypeOIDs} from '
|
|
101
|
+
import {DataTypeOIDs} from 'postgrejs';
|
|
102
102
|
|
|
103
103
|
// .....
|
|
104
104
|
const statement = await connection.prepare(
|
|
@@ -172,29 +172,29 @@ The table below lists builtin data type mappings.
|
|
|
172
172
|
|
|
173
173
|
|
|
174
174
|
## Support
|
|
175
|
-
You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/
|
|
175
|
+
You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/postgrejs/issues) page
|
|
176
176
|
When you open an issue please provide version of NodeJS and PostgreSQL server.
|
|
177
177
|
|
|
178
178
|
## Node Compatibility
|
|
179
|
-
- node >=
|
|
179
|
+
- node >= 16.x
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
## License
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
[npm-image]: https://img.shields.io/npm/v/
|
|
186
|
-
[npm-url]: https://npmjs.org/package/
|
|
187
|
-
[circleci-image]: https://circleci.com/gh/panates/
|
|
188
|
-
[circleci-url]: https://circleci.com/gh/panates/
|
|
189
|
-
[coveralls-image]: https://img.shields.io/coveralls/panates/
|
|
190
|
-
[coveralls-url]: https://coveralls.io/r/panates/
|
|
191
|
-
[downloads-image]: https://img.shields.io/npm/dm/
|
|
192
|
-
[downloads-url]: https://npmjs.org/package/
|
|
193
|
-
[gitter-image]: https://badges.gitter.im/panates/
|
|
194
|
-
[gitter-url]: https://gitter.im/panates/
|
|
195
|
-
[dependencies-image]: https://david-dm.org/panates/
|
|
196
|
-
[dependencies-url]:https://david-dm.org/panates/
|
|
197
|
-
[devdependencies-image]: https://david-dm.org/panates/
|
|
198
|
-
[devdependencies-url]:https://david-dm.org/panates/
|
|
199
|
-
[quality-image]: http://npm.packagequality.com/shield/
|
|
200
|
-
[quality-url]: http://packagequality.com/#?package=
|
|
183
|
+
postgrejs is available under [MIT](LICENSE) license.
|
|
184
|
+
|
|
185
|
+
[npm-image]: https://img.shields.io/npm/v/postgrejs
|
|
186
|
+
[npm-url]: https://npmjs.org/package/postgrejs
|
|
187
|
+
[circleci-image]: https://circleci.com/gh/panates/postgrejs/tree/master.svg?style=shield
|
|
188
|
+
[circleci-url]: https://circleci.com/gh/panates/postgrejs/tree/master
|
|
189
|
+
[coveralls-image]: https://img.shields.io/coveralls/panates/postgrejs/master.svg
|
|
190
|
+
[coveralls-url]: https://coveralls.io/r/panates/postgrejs
|
|
191
|
+
[downloads-image]: https://img.shields.io/npm/dm/postgrejs.svg
|
|
192
|
+
[downloads-url]: https://npmjs.org/package/postgrejs
|
|
193
|
+
[gitter-image]: https://badges.gitter.im/panates/postgrejs.svg
|
|
194
|
+
[gitter-url]: https://gitter.im/panates/postgrejs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
195
|
+
[dependencies-image]: https://david-dm.org/panates/postgrejs/status.svg
|
|
196
|
+
[dependencies-url]:https://david-dm.org/panates/postgrejs
|
|
197
|
+
[devdependencies-image]: https://david-dm.org/panates/postgrejs/dev-status.svg
|
|
198
|
+
[devdependencies-url]:https://david-dm.org/panates/postgrejs?type=dev
|
|
199
|
+
[quality-image]: http://npm.packagequality.com/shield/postgrejs.png
|
|
200
|
+
[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
|
/**
|
package/cjs/connection/cursor.js
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
cb
|
|
203
|
-
|
|
204
|
-
|
|
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;
|
package/cjs/connection/pool.js
CHANGED
|
@@ -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
|
|
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.
|
|
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) {
|
package/cjs/index.js
CHANGED
|
@@ -1,41 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./connection/
|
|
21
|
-
__exportStar(require("./connection/
|
|
22
|
-
__exportStar(require("./connection/
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./interfaces/command-result.js"), exports);
|
|
26
|
-
__exportStar(require("./interfaces/data-mapping-options.js"), exports);
|
|
27
|
-
__exportStar(require("./interfaces/data-type.js"), exports);
|
|
28
|
-
__exportStar(require("./interfaces/database-connection-params.js"), exports);
|
|
29
|
-
__exportStar(require("./interfaces/field-info.js"), exports);
|
|
30
|
-
__exportStar(require("./interfaces/query-options.js"), exports);
|
|
31
|
-
__exportStar(require("./interfaces/query-result.js"), exports);
|
|
32
|
-
__exportStar(require("./interfaces/script-execute-options.js"), exports);
|
|
33
|
-
__exportStar(require("./interfaces/script-result.js"), exports);
|
|
34
|
-
__exportStar(require("./interfaces/statement-prepare-options.js"), exports);
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./util/
|
|
39
|
-
__exportStar(require("./util/
|
|
40
|
-
__exportStar(require("./
|
|
41
|
-
__exportStar(require("./
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./connection/bind-param.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./connection/connection.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./connection/cursor.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./connection/pool.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./connection/prepared-statement.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./data-type-map.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./interfaces/command-result.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./interfaces/data-mapping-options.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./interfaces/data-type.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./interfaces/database-connection-params.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./interfaces/field-info.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./interfaces/query-options.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./interfaces/query-result.js"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./interfaces/script-execute-options.js"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./interfaces/script-result.js"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./interfaces/statement-prepare-options.js"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./protocol/database-error.js"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./protocol/smart-buffer.js"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./util/connection-config.js"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./util/escape-literal.js"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./util/parse-datetime.js"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./util/stringify-arrayliteral.js"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./util/stringify-for-sql.js"), exports);
|
package/cjs/protocol/frontend.js
CHANGED
|
@@ -161,8 +161,9 @@ class Frontend {
|
|
|
161
161
|
return setLengthAndFlush(io, 1);
|
|
162
162
|
}
|
|
163
163
|
getDescribeMessage(args) {
|
|
164
|
-
if (args.name && args.name.length > 63)
|
|
165
|
-
throw new Error(args.type === 'P' ? 'Portal' : 'Statement
|
|
164
|
+
if (args.name && args.name.length > 63) {
|
|
165
|
+
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63');
|
|
166
|
+
}
|
|
166
167
|
const io = this._io
|
|
167
168
|
.start()
|
|
168
169
|
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Describe)
|
|
@@ -172,8 +173,9 @@ class Frontend {
|
|
|
172
173
|
return setLengthAndFlush(io, 1);
|
|
173
174
|
}
|
|
174
175
|
getExecuteMessage(args) {
|
|
175
|
-
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295))
|
|
176
|
+
if (args.fetchCount && (args.fetchCount < 0 || args.fetchCount > 4294967295)) {
|
|
176
177
|
throw new Error('fetchCount can be between 0 and 4294967295');
|
|
178
|
+
}
|
|
177
179
|
const io = this._io
|
|
178
180
|
.start()
|
|
179
181
|
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Execute)
|
|
@@ -183,8 +185,9 @@ class Frontend {
|
|
|
183
185
|
return setLengthAndFlush(io, 1);
|
|
184
186
|
}
|
|
185
187
|
getCloseMessage(args) {
|
|
186
|
-
if (args.name && args.name.length > 63)
|
|
187
|
-
throw new Error(args.type === 'P' ? 'Portal' : 'Statement
|
|
188
|
+
if (args.name && args.name.length > 63) {
|
|
189
|
+
throw new Error(args.type === 'P' ? 'Portal' : 'Statement name length must be lower than 63');
|
|
190
|
+
}
|
|
188
191
|
const io = this._io
|
|
189
192
|
.start()
|
|
190
193
|
.writeInt8(protocol_js_1.Protocol.FrontendMessageCode.Close)
|
|
@@ -1,13 +1,11 @@
|
|
|
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.PgSocket = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
6
|
+
const net_1 = tslib_1.__importDefault(require("net"));
|
|
7
|
+
const putil_promisify_1 = tslib_1.__importDefault(require("putil-promisify"));
|
|
8
|
+
const tls_1 = tslib_1.__importDefault(require("tls"));
|
|
11
9
|
const constants_js_1 = require("../constants.js");
|
|
12
10
|
const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
|
|
13
11
|
const backend_js_1 = require("./backend.js");
|
|
@@ -59,30 +57,31 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
59
57
|
socket.setTimeout(0);
|
|
60
58
|
if (this.options.keepAlive || this.options.keepAlive == null)
|
|
61
59
|
socket.setKeepAlive(true);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
60
|
+
socket.write(this._frontend.getSSLRequestMessage());
|
|
61
|
+
socket.once('data', x => {
|
|
62
|
+
this._removeListeners();
|
|
63
|
+
if (x.toString() === 'S') {
|
|
64
|
+
const tslOptions = { ...options.ssl, socket };
|
|
65
|
+
if (options.host && net_1.default.isIP(options.host) === 0)
|
|
66
|
+
tslOptions.servername = options.host;
|
|
67
|
+
const tlsSocket = (this._socket = tls_1.default.connect(tslOptions));
|
|
68
|
+
tlsSocket.once('error', errorHandler);
|
|
69
|
+
tlsSocket.once('secureConnect', () => {
|
|
70
|
+
this._removeListeners();
|
|
71
|
+
this._handleConnect();
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (x.toString() === 'N') {
|
|
76
|
+
if (options.requireSSL) {
|
|
79
77
|
return errorHandler(new Error('Server does not support SSL connections'));
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
}
|
|
79
|
+
this._removeListeners();
|
|
80
|
+
this._handleConnect();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
return errorHandler(new Error('There was an error establishing an SSL connection'));
|
|
84
|
+
});
|
|
86
85
|
};
|
|
87
86
|
socket.setNoDelay(true);
|
|
88
87
|
socket.setTimeout(options.connectTimeoutMs || 30000, () => errorHandler(new Error('Connection timed out')));
|
|
@@ -289,8 +288,9 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
289
288
|
});
|
|
290
289
|
break;
|
|
291
290
|
case protocol_js_1.Protocol.AuthenticationMessageKind.SASL: {
|
|
292
|
-
if (!msg.mechanisms.includes('SCRAM-SHA-256'))
|
|
291
|
+
if (!msg.mechanisms.includes('SCRAM-SHA-256')) {
|
|
293
292
|
throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported');
|
|
293
|
+
}
|
|
294
294
|
const saslSession = (this._saslSession = sasl_js_1.SASL.createSession(this.options.user || '', 'SCRAM-SHA-256'));
|
|
295
295
|
this._send(this._frontend.getSASLMessage(saslSession));
|
|
296
296
|
break;
|
|
@@ -314,6 +314,8 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
314
314
|
this._saslSession = undefined;
|
|
315
315
|
break;
|
|
316
316
|
}
|
|
317
|
+
default:
|
|
318
|
+
break;
|
|
317
319
|
}
|
|
318
320
|
}
|
|
319
321
|
_handleParameterStatus(msg) {
|