sails.js-我想在帆扬起后动态添加数据库连接 [英] sails.js - I want to add DB connection dynamically after sails lift

查看:83
本文介绍了sails.js-我想在帆扬起后动态添加数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扬帆起航期间,我还没有DB的所有连接信息.

During sails lift I don't yet have all the connection information for my DB.

有没有办法使配置值取决于Promise或在风帆提升完成后动态创建连接?

Is there a way to either have config values dependent on promises or dynamically create a connection after sails lift has completed?

很明显,如果尚不可用,我显然必须添加一个策略或钩子来处理对需要该模型的路由的请求,但是,在这一点上,我什至看不到如何扬帆,直到我已经知道连接信息(必须在配置中).

I would obviously have to add a policy or hook to handle requests to routes needing the model if it wasn't available yet, but at this point I don't see how to even let the sails lift until I already know the connection info (it must be in the configs).

我希望我缺少一种动态创建连接并为其建立连线模型的方法.

I'm hoping I'm missing a way to dynamically create connections and wire models to them.

推荐答案

是; sails.js中的两件事允许您执行此操作.当前存在一种,而即将到来.

Yes; two things in sails.js allow you to do this. One currently exists, and one is upcoming.

  1. https://github.com/sgress454/sails-hook-autoreload.此模块监视磁盘上的配置文件更改,并在文件更改时重新加载您的ORM模型.

  1. https://github.com/sgress454/sails-hook-autoreload. This module watches for config file changes on disk and will re-load your ORM models when a file changes.

我正在研究此确切功能,我的计划是在下周末发布我的作品.我同意这将非常有用.

I am working on this exact feature right now, and my plan is to publish my work at the end of next week. I agree that it will be very useful.

API将允许您动态地在数据库中定义新的模型和连接 . sails.js生命周期回调处理ORM和适配器的更新等.它基于事件,将允许您手动触发事件以更新ORM/连接,如下所示:

The API will allow you to define new Models and Connections in the database on the fly. sails.js lifecycle callbacks handle updating the ORM and adapters and so forth. It is event-based and will allow you to manually fire events to update the ORM/Connections, like so:

  • sails.emit('hook:dynamic-orm:reload')

这是您需要的吗?

这篇关于sails.js-我想在帆扬起后动态添加数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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