pg.native returns null if pg-native is missing (#950)

`require('pg').native` will be `null` and report error once to `stdout` when `pg-native` is missing.
This commit is contained in:
Pavel Lang 2016-06-07 23:02:07 +02:00 committed by Brian C
parent 06743a71e5
commit ad2ffce986
2 changed files with 12 additions and 5 deletions

View File

@ -75,7 +75,16 @@ if(typeof process.env.NODE_PG_FORCE_NATIVE != 'undefined') {
//lazy require native module...the native module may not have installed
module.exports.__defineGetter__("native", function() {
delete module.exports.native;
module.exports.native = new PG(require('./native'));
return module.exports.native;
var native = null;
try {
native = new PG(require('./native'));
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
console.error(err.message);
}
module.exports.native = native;
return native;
});
}

View File

@ -3,6 +3,4 @@
var assert = require('assert');
assert.throws(function() {
require('../../lib').native;
});
assert.equal(require('../../lib').native, null);