-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to access two independent databases #76
Comments
It's not. But probably you want to connect to both databases, define models in both and access them without needing to know where the model was defined, right? |
Possibly. I believe Django has what's called 'database routers' which allow the user to define multiple databases, as well as read/write permissions for each of them. One of the databases in my use case, for instance, is to be accessed read-only, and it'd be nice if node-orm2 could enforce that. |
That's another cool feature that should be available even outside the middleware. I'm going to try to change the express middleware to support several connections. About the read-only option maybe it fits better on model definition. |
#76) There are 2 changes that break backwards compliance: 1. req.db can be: a) null b) db connection c) array of db connections 2. req.models will be filled with the models defined on each connection
This change is not backwards compliant, although I still can try to change to be. Usage: app.use(orm.express("mysql://...", {
define: function (db, models) {
models.Model1 = db.define("model1", { ... });
}
});
app.use(orm.express("pg://...", {
define: function (db, models) {
models.Model2 = db.define("model2", { ... });
}
});
app.get("/", function (req, res) {
// if connections are established:
// req.db should be an Array with both connections (order chan change from definition)
// req.models should have Model1 and Model2
});
|
… and req.models more than once (#76)
I'm using Express to build an application that accesses two Postgres databases. However it's not clear from documentation whether this is possible with the middleware.
The text was updated successfully, but these errors were encountered: