feat: allow connection config to be a function resolver#1164
Open
TheAdamGalloway wants to merge 3 commits intoadonisjs:22.xfrom
Open
feat: allow connection config to be a function resolver#1164TheAdamGalloway wants to merge 3 commits intoadonisjs:22.xfrom
TheAdamGalloway wants to merge 3 commits intoadonisjs:22.xfrom
Conversation
Add support for providing a `ConnectionResolver<T>` (a sync or async function) as the `connection` value in database config types. This mirrors Knex's own `ConnectionConfigProvider` and enables dynamic credentials such as short-lived IAM authentication tokens that must be refreshed on each connection acquisition. Affected config types: MysqlConfig, PostgreConfig, OracleConfig, MssqlConfig. When a resolver function is provided, the `Connection` class stores it and substitutes an empty placeholder for the initial Knex setup. The patched `knex-dynamic-connection` resolver calls the function on each connection acquisition, so credentials are always fresh. Closes adonisjs#1141
Author
|
@thetutlage I appreciate you're very busy right now, but I was wondering if you had any feedback on the way this is implemented? I'm happy to make any changes |
Member
|
@TheAdamGalloway Thanks for the PR. On the surface it does look fine. However, I will have to try it manually to make sure everything works fine. Let's see if I can take out some time today |
thetutlage
reviewed
Apr 7, 2026
|
|
||
| switch (this.clientName) { | ||
| case 'postgres': | ||
| client.acquireRawConnection = function acquireRawConnection(this: any) { |
Member
There was a problem hiding this comment.
Do we really have to do this? Doesn't Knex support async config resolver?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
#1141
❓ Type of change
📚 Description
Add support for providing a
ConnectionResolver<T>(a sync or async function) as theconnectionvalue in database config types. This mirrors Knex's ownConnectionConfigProviderand enables dynamic credentials such as short-lived IAM authentication tokens that must be refreshed on each connection acquisition.Affected config types: MysqlConfig, PostgreConfig, OracleConfig, MssqlConfig.
When a resolver function is provided, the
Connectionclass stores it and substitutes an empty placeholder for the initial Knex setup. The patchedknex-dynamic-connectionresolver calls the function on each connection acquisition, so credentials are always fresh.I have run the test suite and it passed, and I have tested the connection function locally and can confirm it works. I appreciate you may have an opinion @thetutlage on how the new types are set up, so I'm happy to make any changes you see fit.
Closes #1141
📝 Checklist