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.
Like most MVC frameworks, Sails supports multiple databases. That means the syntax to query and manipulate our data is always the same, whether we're using MongoDB, MySQL, or any other supported database.
Since Sails uses sails-disk by default, you can start building your app with zero configuration, using a local temporary file as storage. When you're ready to switch to the real thing (and when everyone knows what that is), just change your app's datastore configuration.
All supported adapters can be configured in roughly the same way: by passing in a Sails/Waterline adapter ( adapter ), as well as a connection URL ( url ). For more information on configuring datastores, see sails.config.datastores.
Sails comes installed with a powerful ORM/ODM called Waterline, a datastore-agnostic tool that dramatically simplifies interaction with one or more databases. It provides an abstraction layer on top of the underlying database, allowing you to easily query and manipulate your data without writing vendor-specific integration code.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With