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:
parent
06743a71e5
commit
ad2ffce986
13
lib/index.js
13
lib/index.js
@ -75,7 +75,16 @@ if(typeof process.env.NODE_PG_FORCE_NATIVE != 'undefined') {
|
|||||||
//lazy require native module...the native module may not have installed
|
//lazy require native module...the native module may not have installed
|
||||||
module.exports.__defineGetter__("native", function() {
|
module.exports.__defineGetter__("native", function() {
|
||||||
delete module.exports.native;
|
delete module.exports.native;
|
||||||
module.exports.native = new PG(require('./native'));
|
var native = null;
|
||||||
return module.exports.native;
|
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,4 @@
|
|||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
assert.throws(function() {
|
assert.equal(require('../../lib').native, null);
|
||||||
require('../../lib').native;
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user