Sails Js 中的动态数据库连接 [英] Dynamic database connection in Sails Js

查看:40
本文介绍了Sails Js 中的动态数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从控制器设置数据库连接?.我需要在控制器中指定数据库的类型、用户、密码、端口、数据库名称,并在 connection.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.

推荐答案

您可能可以修改 sails.config.connections 全局并编辑现有连接.当然,这只会持续到应用程序重新启动.

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.

如果您想让它更持久但不修改配置 js 文件,您可以将连接详细信息保存在 localdb(sails-disk?)上并使用config/bootstrap.js

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

这篇关于Sails Js 中的动态数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆