Multiple Database connection based on Request #2899
Replies: 2 comments
-
In v5 you can set const connectionSettings = app.get('connections')
const connections = {
company1: knex(connectionSettings.company1),
company2: knex(connectionSettings.company2),
}
app.set('connections', connections) Then use a hook that sets const setCompanyModel = async context => {
const connections = context.app.get('connections')
const { companyName } = context.params.user
const Model = connections[companyName]
context.params = {
...context.params,
Model
}
}
app.service('messages').hooks({
before: {
all: [
authenticate('jwt'),
setCompanyModel
]
}
}) There is nothing particularly fancy needed as long as you understand the Feathers basics of how hooks, services and database adapters work. |
Beta Was this translation helpful? Give feedback.
-
I appreciate your reply and effort to help each query. Apart from this I am trying to read database error but I did not get extractable knexjs error object. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Right Now we have application that runs well on PHP/Mysql server.
We are planning to move whole project to Node/Mysql and for that we have chosen the feather js as it fits very well.
I am exploring the feather for my below requirement.
We are working on accounting system.
Our client will have many companies and each company will have separate database.
User will be login from SSO system(in featherjs) and moved to default company.
and all the data will be modified in that companies database.
User will be also able to switch to companies at anytime without logged out.
Is above requirement can be fulfilled? If it possible can you please give me some idea how can I do it.
I am new to Feather JS
Beta Was this translation helpful? Give feedback.
All reactions