Skip to content
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

Ability to pass/re-use knex client #3167

Closed
parisholley opened this issue May 30, 2022 · 1 comment
Closed

Ability to pass/re-use knex client #3167

parisholley opened this issue May 30, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@parisholley
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I am switching my project over to Remix and an issue with local development is that it constantly destroys module state between requests. When using Mikro, this is problematic as the connection pool keeps getting recreated and eventually the server gets exhausted. While the Mikro instance could be a singleton and re-used this means any changes to anything related to the database would require a full server restart vs hot reload.

Describe the solution you'd like
Here is how I am currently hacking it:

        if(!process['knex']){
            process['knex'] = (0, knex_1.knex)(this.getKnexOptions(type))
                .on('query', data => {
                if (!data.__knexQueryUid) {
                    this.logQuery(data.sql.toLowerCase().replace(/;$/, ''));
                }
            });
        }

        return process['knex'];

The concern obviously is how to expose this without leaking the usage of knex to end-user. From what I can tell, the connection classes are coupled with metadata (which can change between hot reloads). Knex itself doesn't really have a way to support passing in existing pg connections/pools.

@parisholley parisholley added the enhancement New feature or request label May 30, 2022
@B4nan
Copy link
Member

B4nan commented May 31, 2022

What I can offer is to allow driverOptions to be also a knex instance, which would be then preferred. PR welcome :]

You might still need some type casting I guess, but for such a use case, I really don't see anything wrong with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants