New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way we can configure the connection through an async function? #3340
Comments
This is not a currently supported feature, similar (but somewhat different) feature was requested here: #2732 API proposal and (after proposal is approved) PR for this would be welcome. |
I think this API is good (function can be also non async) and it could be specified in a way that as long as it returns the same configuration object Later on if it is needed we could also allow fetching the whole knex configuration object in async manner. |
@elhigu Thanks for the explanation. I read some of the comments you and other people mention and suggest. for example, to load the config to a file via prescript and then load that file into knex. The problem with that approach is security wise. the entire idea of loading the config via AWS secret manager is to keep the variables in memory. so no direct access via code files. I tried to do async module export and load but the code gets really ugly. what cause the issue to be really painful is I use bookshelf in the project and if there is a relation between two tables and we need to reflect the relation via bookshelf models then it can't be done via async require. I will try to dig in knex code base and I will be really happy If I can implement that feature. I already stuck into this problem since 4 days :( |
Lets leave this opened until someone takes this over :) (I already closed those older issues about this same feature request). |
Hi @elhigu , I try to modify some part of the code and I come up with a solution. The solution allows the connection to be entered as async function
The files I modifed are:
what I did was to check if the type of config is a function (in client.js) then don't do anything, just pass the config to dialects. in dialects, I am checking if the type of config is function, then execute the function (with await and async to the top function) and load the config from the result.
If you agree of the way to implement this, then I can configure the rest of dialects and submit PR |
Could you create WIP PR with changes so far? Would be easier to discuss. |
@kibertoad I will try this weekend to write a POC code to support only one adapter (postgres). |
I am looking for a solution to this as well. Cannot +1 this idea enough. Thanks! |
@mbelles I will try to write a PR this weekend |
@elhigu @kibertoad Can you please give a resolution on what I've done? Also, I am a bit lost where to write the tests for the new connection config. (guide me please) if you are ok with the PG client, then I will write the code to support other clients example:
|
Released in 0.20.1 |
So, we have the db config stored in AWS secret manager. and we use knex with serverless labmda.
so the question is is it possible to load the config as an async function which calls the secret manager rather than setting a simple config object?
The text was updated successfully, but these errors were encountered: