简体   繁体   English

Sails Js中的动态数据库连接

[英]Dynamic database connection in Sails Js

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. 我需要在控制器中指定数据库的类型,用户,密码,端口,数据库名称,并在connections.js中进行设置。

You could probably modify the sails.config.connections global and edit an existing connection. 您可能可以全局修改sails.config.connections并编辑现有连接。 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 如果您想使其更永久但不修改config js文件,则可以将连接详细信息保存在localdb(sails-disk?)上,并使用config / bootstrap在Sails Lift上重新设置连接属性(从本地db读取) .js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM