@@ -54,7 +54,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
54
54
*
55
55
* @param {PostgreSQL } postgresql PostgreSQL node.js binding
56
56
* @options {Object} settings An object for the data source settings.
57
- * See [node-postgres documentation](https://github.com/brianc/ node-postgres/wiki/Client#parameters ).
57
+ * See [node-postgres documentation](https://node-postgres.com/api/client ).
58
58
* @property {String } url URL to the database, such as 'postgres://test:mypassword@localhost:5432/devdb'.
59
59
* Other parameters can be defined as query string of the url
60
60
* @property {String } hostname The host name or ip address of the PostgreSQL DB server
@@ -63,6 +63,8 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
63
63
* @property {String } password The password
64
64
* @property {String } database The database name
65
65
* @property {Boolean } ssl Whether to try SSL/TLS to connect to server
66
+ * @property {Function | string } [onError] Optional hook to connect to the pg pool 'error' event,
67
+ * or the string 'ignore' to record them with `debug` and otherwise ignore them.
66
68
*
67
69
* @constructor
68
70
*/
@@ -79,6 +81,16 @@ function PostgreSQL(postgresql, settings) {
79
81
this . clientConfig . Promise = Promise ;
80
82
this . pg = new postgresql . Pool ( this . clientConfig ) ;
81
83
84
+ if ( settings . onError ) {
85
+ if ( settings . onError === 'ignore' ) {
86
+ this . pg . on ( 'error' , function ( err ) {
87
+ debug ( err ) ;
88
+ } ) ;
89
+ } else {
90
+ this . pg . on ( 'error' , settings . onError ) ;
91
+ }
92
+ }
93
+
82
94
this . settings = settings ;
83
95
debug ( 'Settings %j' , settings ) ;
84
96
}
0 commit comments