How to close DB connection in provider for commands?

Hello,

I need some values in view from DB, so I registered provider, which on boot load values from DB and create global with result. I can render views in cmds too, because there are generating PDFs, so need to be called in CMDs too.

My problem is that after this every command (e.g. adonis route:list) never end, because DB connection is not closed

So i tried

hooks.after.aceCommand(async () => {
    const Database = use('Database');
    await Database.close();
});

This hook is never called… So my question is how to close connection created with provider. Or is there some another (better) approach to add view global?

THX

Have you figured this out? I am having the same problem. My database connections need to be explicitly closed because they are tunneled thru an ssh connection.

They aren’t getting closed. When I seed the database the connection doesn’t close and finish…

@ajoslin103 I see you updated your package? Did you figure it out? Can you share in here too? :yum:

I only figured out that hooks.after.aceCommand is called only when you close the connection in command… So now in our custom commands I always close DB connection on the end… but e.g. adonis route:list still don’t close

1 Like

I’m not sure how much this will help, but sure.

In my case the connections were not being closed in my custom knex dialect which I had built as a wrapper around mysql-ssh. see: https://github.com/ajoslin103/knex-mysqlssh-dialect

1 Like