6

How I can set a database connection from a controller?. I need to specify in the controller the type of database , user, password, port, database name and set this in connections.js.

1 Answer 1

2

You could probably modify the sails.config.connections global and edit an existing connection. Of course this would only last until the app is restarted.

If you want to make it more permanent but not modify config js files you could then save the connection details on a localdb (sails-disk?) and re-set the connection properties (read from local db) on sails lift using config/bootstrap.js

Sign up to request clarification or add additional context in comments.

1 Comment

Salakar, I have this same issue and tried the solution you proposed, but it doesn't work. It seems it uses the one database name specified in connections.js, and if it's not specified in there, it uses "sails" by default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.