pg-promise 8.6.4 → 8.7.2
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/README.md +6 -0
- package/lib/connect.js +0 -1
- package/lib/database.js +5 -0
- package/lib/errors/paramQuery.js +11 -18
- package/lib/errors/prepared.js +11 -18
- package/lib/errors/queryFile.js +12 -19
- package/lib/errors/queryResult.js +12 -18
- package/lib/utils/index.js +1 -1
- package/package.json +12 -12
- package/typescript/pg-subset.d.ts +38 -26
package/README.md
CHANGED
|
@@ -376,6 +376,9 @@ db.any('SELECT * FROM products $1:raw', where);
|
|
|
376
376
|
|
|
377
377
|
Special syntax `this:raw` / `this^` is supported, to inject the formatting object as raw JSON string.
|
|
378
378
|
|
|
379
|
+
**WARNING:**<br/>
|
|
380
|
+
This filter is unsafe, and should not be used for values that come from the client side, as it may result in [SQL injection].
|
|
381
|
+
|
|
379
382
|
### Open Values
|
|
380
383
|
|
|
381
384
|
When a variable ends with `:value`, or shorter syntax `#`, it is escaped as usual, except when its type is a string,
|
|
@@ -398,6 +401,9 @@ open-value syntax to add the extra search logic:
|
|
|
398
401
|
SELECT * FROM table WHERE name LIKE '%$1:value%')
|
|
399
402
|
```
|
|
400
403
|
|
|
404
|
+
**WARNING:**<br/>
|
|
405
|
+
This filter is unsafe, and should not be used for values that come from the client side, as it may result in [SQL injection].
|
|
406
|
+
|
|
401
407
|
Method [as.value] implements the formatting.
|
|
402
408
|
|
|
403
409
|
### JSON Filter
|
package/lib/connect.js
CHANGED
|
@@ -107,7 +107,6 @@ function onError(err) {
|
|
|
107
107
|
const ctx = this.$ctx;
|
|
108
108
|
const cn = npm.utils.getSafeConnection(ctx.cn);
|
|
109
109
|
npm.events.error(ctx.options, err, {cn, dc: ctx.dc});
|
|
110
|
-
ctx.disconnect(err);
|
|
111
110
|
if (ctx.cnOptions && typeof ctx.cnOptions.onLost === 'function' && !ctx.notified) {
|
|
112
111
|
try {
|
|
113
112
|
ctx.cnOptions.onLost.call(this, err, {
|
package/lib/database.js
CHANGED
|
@@ -1614,6 +1614,11 @@ function Database(cn, dc, config) {
|
|
|
1614
1614
|
// which cannot be tested automatically; removing from coverage:
|
|
1615
1615
|
// istanbul ignore next
|
|
1616
1616
|
function onError(err) {
|
|
1617
|
+
// this client was never seen by pg-promise, which
|
|
1618
|
+
// can happen if it failed to initialize
|
|
1619
|
+
if (!err.client.$ctx) {
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1617
1622
|
const ctx = err.client.$ctx;
|
|
1618
1623
|
npm.events.error(ctx.options, err, {
|
|
1619
1624
|
cn: npm.utils.getSafeConnection(ctx.cn),
|
package/lib/errors/paramQuery.js
CHANGED
|
@@ -43,27 +43,20 @@ const npm = {
|
|
|
43
43
|
*
|
|
44
44
|
* @see ParameterizedQuery
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
class ParameterizedQueryError extends Error {
|
|
47
|
+
constructor(error, ps) {
|
|
48
|
+
const isQueryFileError = error instanceof npm.QueryFileError;
|
|
49
|
+
const message = isQueryFileError ? 'Failed to initialize \'text\' from a QueryFile.' : error;
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = this.constructor.name;
|
|
52
|
+
if (isQueryFileError) {
|
|
53
|
+
this.error = error;
|
|
54
|
+
}
|
|
55
|
+
this.result = ps;
|
|
56
|
+
Error.captureStackTrace(this, this.constructor);
|
|
55
57
|
}
|
|
56
|
-
this.result = ps;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
ParameterizedQueryError.prototype = Object.create(Error.prototype, {
|
|
60
|
-
constructor: {
|
|
61
|
-
value: ParameterizedQueryError,
|
|
62
|
-
writable: true,
|
|
63
|
-
configurable: true
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
60
|
/**
|
|
68
61
|
* @method errors.ParameterizedQueryError#toString
|
|
69
62
|
* @description
|
package/lib/errors/prepared.js
CHANGED
|
@@ -43,27 +43,20 @@ const npm = {
|
|
|
43
43
|
*
|
|
44
44
|
* @see PreparedStatement
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
class PreparedStatementError extends Error {
|
|
47
|
+
constructor(error, ps) {
|
|
48
|
+
const isQueryFileError = error instanceof npm.QueryFileError;
|
|
49
|
+
const message = isQueryFileError ? 'Failed to initialize \'text\' from a QueryFile.' : error;
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = this.constructor.name;
|
|
52
|
+
if (isQueryFileError) {
|
|
53
|
+
this.error = error;
|
|
54
|
+
}
|
|
55
|
+
this.result = ps;
|
|
56
|
+
Error.captureStackTrace(this, this.constructor);
|
|
55
57
|
}
|
|
56
|
-
this.result = ps;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
PreparedStatementError.prototype = Object.create(Error.prototype, {
|
|
60
|
-
constructor: {
|
|
61
|
-
value: PreparedStatementError,
|
|
62
|
-
writable: true,
|
|
63
|
-
configurable: true
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
60
|
/**
|
|
68
61
|
* @method errors.PreparedStatementError#toString
|
|
69
62
|
* @description
|
package/lib/errors/queryFile.js
CHANGED
|
@@ -46,28 +46,21 @@ const npm = {
|
|
|
46
46
|
* @see QueryFile
|
|
47
47
|
*
|
|
48
48
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
class QueryFileError extends Error {
|
|
50
|
+
constructor(error, qf) {
|
|
51
|
+
const isSqlError = error instanceof npm.minify.SQLParsingError;
|
|
52
|
+
const message = isSqlError ? 'Failed to parse the SQL.' : error.message;
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = this.constructor.name;
|
|
55
|
+
if (isSqlError) {
|
|
56
|
+
this.error = error;
|
|
57
|
+
}
|
|
58
|
+
this.file = qf.file;
|
|
59
|
+
this.options = qf.options;
|
|
60
|
+
Error.captureStackTrace(this, this.constructor);
|
|
58
61
|
}
|
|
59
|
-
this.file = qf.file;
|
|
60
|
-
this.options = qf.options;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
QueryFileError.prototype = Object.create(Error.prototype, {
|
|
64
|
-
constructor: {
|
|
65
|
-
value: QueryFileError,
|
|
66
|
-
writable: true,
|
|
67
|
-
configurable: true
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
64
|
/**
|
|
72
65
|
* @method errors.QueryFileError#toString
|
|
73
66
|
* @description
|
|
@@ -127,25 +127,19 @@ const errorMessages = [
|
|
|
127
127
|
* {@link Database#oneOrNone oneOrNone}, {@link Database#many many}
|
|
128
128
|
*
|
|
129
129
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
QueryResultError.prototype = Object.create(Error.prototype, {
|
|
143
|
-
constructor: {
|
|
144
|
-
value: QueryResultError,
|
|
145
|
-
writable: true,
|
|
146
|
-
configurable: true
|
|
130
|
+
class QueryResultError extends Error {
|
|
131
|
+
constructor(code, result, query, values) {
|
|
132
|
+
const message = errorMessages[code].message;
|
|
133
|
+
super(message);
|
|
134
|
+
this.name = this.constructor.name;
|
|
135
|
+
this.code = code;
|
|
136
|
+
this.result = result;
|
|
137
|
+
this.query = query;
|
|
138
|
+
this.values = values;
|
|
139
|
+
this.received = result.rows.length;
|
|
140
|
+
Error.captureStackTrace(this, this.constructor);
|
|
147
141
|
}
|
|
148
|
-
}
|
|
142
|
+
}
|
|
149
143
|
|
|
150
144
|
/**
|
|
151
145
|
* @method errors.QueryResultError#toString
|
package/lib/utils/index.js
CHANGED
|
@@ -106,7 +106,7 @@ function maskPassword(connectionString) {
|
|
|
106
106
|
///////////////////////////////////////////
|
|
107
107
|
// Returns a space gap for console output;
|
|
108
108
|
function messageGap(level) {
|
|
109
|
-
return
|
|
109
|
+
return ' '.repeat(level * 4);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/////////////////////////////////////////
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-promise",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.7.2",
|
|
4
4
|
"description": "Promises interface for PostgreSQL",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "typescript/pg-promise.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jasmine-node test",
|
|
8
|
+
"test": "jasmine-node --captureExceptions test",
|
|
9
9
|
"test:native": "jasmine-node test --config PG_NATIVE true",
|
|
10
10
|
"doc": "./node_modules/.bin/jsdoc -c ./jsdoc/jsdoc.js ./jsdoc/README.md -t ./jsdoc/templates/custom",
|
|
11
11
|
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
|
|
@@ -41,23 +41,23 @@
|
|
|
41
41
|
"npm": ">=2.15"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"assert-options": "0.1.3",
|
|
44
45
|
"manakin": "0.5.2",
|
|
45
|
-
"pg": "7.
|
|
46
|
-
"pg-minify": "
|
|
47
|
-
"spex": "2.2.0"
|
|
48
|
-
"assert-options": "0.1.3"
|
|
46
|
+
"pg": "7.11.0",
|
|
47
|
+
"pg-minify": "1.2.0",
|
|
48
|
+
"spex": "2.2.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/node": "
|
|
51
|
+
"@types/node": "12.0.0",
|
|
52
52
|
"JSONStream": "1.3.5",
|
|
53
|
-
"bluebird": "3.5.
|
|
53
|
+
"bluebird": "3.5.4",
|
|
54
54
|
"coveralls": "3.0.3",
|
|
55
|
-
"eslint": "5.
|
|
56
|
-
"tslint": "5.
|
|
55
|
+
"eslint": "5.16.0",
|
|
56
|
+
"tslint": "5.16.0",
|
|
57
57
|
"istanbul": "0.4.5",
|
|
58
58
|
"jasmine-node": "1.16.2",
|
|
59
|
-
"jsdoc": "3.
|
|
59
|
+
"jsdoc": "3.6.1",
|
|
60
60
|
"pg-query-stream": "2.0.0",
|
|
61
|
-
"typescript": "3.
|
|
61
|
+
"typescript": "3.4.5"
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Calling it 'pg-subset' to avoid a conflict in case the application also
|
|
14
14
|
// includes the official 'pg' typings.
|
|
15
15
|
//
|
|
16
|
-
// Supported version of pg: 7.
|
|
16
|
+
// Supported version of pg: 7.11.0 and later.
|
|
17
17
|
//
|
|
18
18
|
// pg: https://github.com/brianc/node-postgres
|
|
19
19
|
//////////////////////////////////////////////////////////////////////////////
|
|
@@ -25,6 +25,7 @@ declare namespace pg {
|
|
|
25
25
|
|
|
26
26
|
interface IColumn {
|
|
27
27
|
name: string
|
|
28
|
+
oid: number
|
|
28
29
|
dataTypeID: number
|
|
29
30
|
|
|
30
31
|
// NOTE: properties below are not available within Native Bindings:
|
|
@@ -43,8 +44,15 @@ declare namespace pg {
|
|
|
43
44
|
fields: IColumn[]
|
|
44
45
|
|
|
45
46
|
// properties below are not available within Native Bindings:
|
|
46
|
-
|
|
47
47
|
rowAsArray: boolean
|
|
48
|
+
|
|
49
|
+
_types: {
|
|
50
|
+
_types: any,
|
|
51
|
+
text: any,
|
|
52
|
+
binary: any
|
|
53
|
+
};
|
|
54
|
+
_parsers: Array<Function>;
|
|
55
|
+
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
// SSL configuration;
|
|
@@ -67,11 +75,11 @@ declare namespace pg {
|
|
|
67
75
|
// 2) https://github.com/brianc/node-pg-pool
|
|
68
76
|
type TConnectionParameters = {
|
|
69
77
|
connectionString?: string
|
|
78
|
+
host?: string
|
|
70
79
|
database?: string
|
|
71
80
|
user?: string
|
|
72
81
|
password?: string
|
|
73
82
|
port?: number
|
|
74
|
-
host?: string
|
|
75
83
|
ssl?: boolean | TSSLConfig
|
|
76
84
|
binary?: boolean
|
|
77
85
|
client_encoding?: string
|
|
@@ -79,18 +87,18 @@ declare namespace pg {
|
|
|
79
87
|
application_name?: string
|
|
80
88
|
fallback_application_name?: string
|
|
81
89
|
isDomainSocket?: boolean
|
|
82
|
-
|
|
83
|
-
max?: number // replaces `poolSize`
|
|
90
|
+
max?: number
|
|
84
91
|
min?: number
|
|
85
92
|
idleTimeoutMillis?: number
|
|
86
|
-
reapIntervalMillis?: number
|
|
87
|
-
returnToHead?: boolean
|
|
88
|
-
poolLog?: boolean | (() => void)
|
|
89
93
|
parseInputDatesAsUTC?: boolean
|
|
90
94
|
rows?: number
|
|
91
95
|
statement_timeout?: boolean | number
|
|
92
96
|
query_timeout?: boolean | number
|
|
97
|
+
connect_timeout?: number
|
|
98
|
+
keepAliveInitialDelayMillis?: number
|
|
93
99
|
keepAlive?: boolean
|
|
100
|
+
keepalives?: number
|
|
101
|
+
keepalives_idle?: number
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
// Interface of 'pg-types' module;
|
|
@@ -109,39 +117,34 @@ declare namespace pg {
|
|
|
109
117
|
// database host. defaults to localhost
|
|
110
118
|
host: string
|
|
111
119
|
|
|
112
|
-
//database user's name
|
|
120
|
+
// database user's name
|
|
113
121
|
user: string
|
|
114
122
|
|
|
115
|
-
//name of database to connect
|
|
123
|
+
// name of database to connect
|
|
116
124
|
database: string
|
|
117
125
|
|
|
118
|
-
//database user's password
|
|
126
|
+
// database user's password
|
|
119
127
|
password: string
|
|
120
128
|
|
|
121
|
-
//database port
|
|
129
|
+
// database port
|
|
122
130
|
port: number
|
|
123
131
|
|
|
124
|
-
//number of rows to return at a time from a prepared statement's
|
|
125
|
-
//portal. 0 will return all rows at once
|
|
132
|
+
// number of rows to return at a time from a prepared statement's
|
|
133
|
+
// portal. 0 will return all rows at once
|
|
126
134
|
rows: number
|
|
127
135
|
|
|
128
136
|
// binary result mode
|
|
129
137
|
binary: boolean
|
|
130
138
|
|
|
131
|
-
//Connection pool options - see https://github.com/
|
|
132
|
-
//number of connections to use in connection pool
|
|
133
|
-
//0 will disable connection pooling
|
|
134
|
-
poolSize: number
|
|
139
|
+
// Connection pool options - see https://github.com/brianc/node-pg-pool
|
|
135
140
|
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
141
|
+
// number of connections to use in connection pool
|
|
142
|
+
// 0 will disable connection pooling
|
|
143
|
+
max: 10,
|
|
139
144
|
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//pool log function / boolean
|
|
144
|
-
poolLog: boolean | (() => void)
|
|
145
|
+
// max milliseconds a client can go unused before it is removed
|
|
146
|
+
// from the pool and destroyed
|
|
147
|
+
idleTimeoutMillis: number
|
|
145
148
|
|
|
146
149
|
client_encoding: string
|
|
147
150
|
|
|
@@ -153,9 +156,18 @@ declare namespace pg {
|
|
|
153
156
|
|
|
154
157
|
parseInputDatesAsUTC: boolean
|
|
155
158
|
|
|
159
|
+
// max milliseconds any query using this connection will execute for before timing out in error.
|
|
160
|
+
// false=unlimited
|
|
156
161
|
statement_timeout: boolean | number
|
|
157
162
|
|
|
163
|
+
// max milliseconds to wait for query to complete (client side)
|
|
158
164
|
query_timeout: boolean | number
|
|
165
|
+
|
|
166
|
+
connect_timeout: number
|
|
167
|
+
|
|
168
|
+
keepalives: number
|
|
169
|
+
|
|
170
|
+
keepalives_idle: number
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
class Connection {
|