I'm trying to use node-orm2 as middleware with Express the documentation only shows how you can connect to one database only.
I have tried getting Express to use two different middleware layers, but no luck. For instance,
app.use(orm.express('sqlite://test.db', define: { /* define table1 */ }));
app.use(orm.express('sqlite://test2.db', define: { /* define table2 */ }));
I've routed everything correctly to this get
handler:
app.get("/", function (req, res) {
var t1 = req.db.models.table1.find(...);
var t2 = req.db.models.table2.find(...);
res.send([t1,t2]);
});
Since I app.use
d table1
's database first, the second of the find
invocations will yield
TypeError: Cannot call method 'find' of undefined
... which means that the two define:
blocks haven't been merged, which is what we'd like.
How would I access two databases with node-orm2?