mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Merge pull request #381 from hoegaarden/master
force usage of pg.native via environment variable
This commit is contained in:
commit
a943500358
20
lib/index.js
20
lib/index.js
@ -52,12 +52,16 @@ PG.prototype.cancel = function(config, client, query) {
|
||||
cancellingClient.cancel(client, query);
|
||||
};
|
||||
|
||||
module.exports = new PG(Client);
|
||||
|
||||
//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(__dirname + '/native'));
|
||||
return module.exports.native;
|
||||
});
|
||||
var forceNative = Object.prototype.hasOwnProperty.call(process.env, 'NODE_PG_FORCE_NATIVE');
|
||||
if (forceNative) {
|
||||
module.exports = new PG(require(__dirname + '/native'));
|
||||
} else {
|
||||
module.exports = new PG(Client);
|
||||
|
||||
//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(__dirname + '/native'));
|
||||
return module.exports.native;
|
||||
});
|
||||
}
|
||||
|
||||
38
test/integration/client/force-native-with-envvar-tests.js
Normal file
38
test/integration/client/force-native-with-envvar-tests.js
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* helper needs to be loaded for the asserts but it alos proloads
|
||||
* client which we don't want here
|
||||
*
|
||||
*/
|
||||
var helper = require(__dirname+"/test-helper")
|
||||
, path = require('path')
|
||||
;
|
||||
|
||||
var paths = {
|
||||
'pg' : path.join(__dirname, '..', '..', '..', 'lib', 'index.js') ,
|
||||
'query_js' : path.join(__dirname, '..', '..', '..', 'lib', 'query.js') ,
|
||||
'query_native' : path.join(__dirname, '..', '..', '..', 'lib', 'native', 'query.js') ,
|
||||
};
|
||||
|
||||
/**
|
||||
* delete the modules we are concerned about from the
|
||||
* module cache, so they get loaded cleanly and the env
|
||||
* var can kick in ...
|
||||
*/
|
||||
function emptyCache(){
|
||||
Object.keys(require.cache).forEach(function(key){
|
||||
delete require.cache[key];
|
||||
});
|
||||
};
|
||||
|
||||
emptyCache();
|
||||
process.env.NODE_PG_FORCE_NATIVE = '1';
|
||||
|
||||
var pg = require( paths.pg );
|
||||
var query_native = require( paths.query_native );
|
||||
var query_js = require( paths.query_js );
|
||||
|
||||
assert.deepEqual(pg.Client.Query, query_native);
|
||||
assert.notDeepEqual(pg.Client.Query, query_js);
|
||||
|
||||
emptyCache();
|
||||
delete process.env.NODE_PG_FORCE_NATIVE
|
||||
Loading…
x
Reference in New Issue
Block a user