Repository navigation
TypeError when initialize multiple connections to the same db with pool option #469
Copy link
Copy link
Closed
Milestone
Description
Hi,
I'm having the following code which throws error
var _ = require('underscore');
var orm = require('orm');
var db = {
host: '127.0.0.1',
user: '****',
password: '****',
database: 'my_db',
charset: 'utf8',
protocol: 'postgres',
query: {
pool: true
}
};
orm.connect(db, function(err, db) {
var User = db.define('users', {}, {cache: false});
User.count({}, function(err, results) { console.log(results);});
});
orm.connect(db, function(err, db) {
var User = db.define('users', {}, {cache: false});
User.count({}, function(err, results) { console.log(results);});
});
/var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/Drivers/DML/postgres.js:93
this.db.query(query, function (err, result) {
^
TypeError: Object [object Object] has no method 'query'
at Driver.switchableFunctions.client.execSimpleQuery (/var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/Drivers/DML/postgres.js:93:12)
at Driver.count (/var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/Drivers/DML/postgres.js:202:7)
at Function.Model.model.count (/var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/Model.js:467:15)
at orm.connect.db.define.cache (/var/proj/pb-dev3/synchronizer_new/example.coffee:15:8)
at /var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/ORM.js:127:13
at /var/proj/pb-dev3/synchronizer_new/node_modules/orm/lib/Drivers/DML/postgres.js:57:5
at /var/proj/pb-dev3/synchronizer_new/node_modules/pg/lib/pool.js:55:9
at /var/proj/pb-dev3/synchronizer_new/node_modules/pg/node_modules/generic-pool/lib/generic-pool.js:278:11
at /var/proj/pb-dev3/synchronizer_new/node_modules/pg/lib/pool.js:36:18
at [object Object].<anonymous> (/var/proj/pb-dev3/synchronizer_new/node_modules/pg/lib/client.js:134:7)
at [object Object].g (events.js:175:14)
at [object Object].EventEmitter.emit (events.js:117:20)
at [object Object].<anonymous> (/var/proj/pb-dev3/synchronizer_new/node_modules/pg/lib/connection.js:97:12)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:736:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
This error only appears when setting pool: true option, without it works perfectly fine. I'm trying to build a multi tenacy solution and the problem occurs when initializing first connection for database (i.e. multiple requests which were started at the same time).
What can be an issue in here ? I would like to use pool option for my database connections.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
dxg commentedon Mar 13, 2014
Hi,
The problem is that ORM modifies your connection settings - it deletes
pool: trueduring the firstorm.connectcall.You can work around this by using something like lodash
_.cloneDeep()on the connection settings before passing them in. In the meantime, I'll try get this fixed before the next release.kbackowski commentedon Mar 13, 2014
It works! :) Thanks for the solution.