Native Bindings override issue
See original GitHub issueThe way Native Bindings currently work, is by overriding the library’s global settings:
module.exports.__defineGetter__("native", function () {
delete module.exports.native;
module.exports.native = new PG(require('./native'));
return module.exports.native;
});
As a result, it creates a conflict when you try using two third-party libraries -
- one that uses
pg
via Native Bindings - one that uses
pg
via JavaScript bindings
Just as one library activates Native Bindings, it becomes global, due to Node.js module sharing principle, so it overrides this setting for libraries that do not support Native Bindings.
How to test it
Install pg-native
, and declare:
var pg1 = require('pg');
var pg2 = require('pg').native;
Just as pg2
is initialized, any call into pg1
for connect
or query
goes into the layer for the Native Bindings, thus breaking any module that supports only JavaScript bindings.
Thoughts
I don’t know yet how difficult it would be to fix this, or even whether it is possible to make Native Bindings work in parallel with JavaScript Bindings within the same process, without running into conflicts. Any thoughts are welcome!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Offf yeah that’s just a nasty bug. I’m putting together a PR for it right now. ❤️
Fixed in version 4.5.3.
My testing confirms that it is working now, at least on the surface - connections are now correct. It would take running the two bindings side-by-side to see if there is any issue remains. Time will tell 😉
@brianc Thank you!