drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

Don't make session private

Open rizen opened this issue 1 year ago • 2 comments

When we do something like:

const poolConnection = mysql.createPool({
        host: dbConfig.hostname,
        port: parseInt(dbConfig.port),
        user: dbConfig.username,
        password: dbConfig.password,
        database: dbConfig.pathname.slice(1),
    });
 const db = drizzle(poolConnection);

To start up our connection pool, don't make us maintain a reference to the pool to shut it down. You already have a reference inside of db that we're holding on to cuz we use it everywhere. Instead make it easy to shut it down by making session public so we can do something like:

db.session.client.pool.end();

rizen avatar Apr 09 '23 22:04 rizen

Or better yet, give a generic method based upon the driver used to just call db.disconnect()

rizen avatar Apr 09 '23 22:04 rizen

It's not as easy as it may look like. Currently, the type of the session property is just a generic MySqlSession, not a driver-specific one, so it doesn't know about which client is used with it. We could instead provide a generic disconnect method, as you wrote, but that would require generalizing the logic across every driver, which might have some specific close/disconnect behavior. For now the easiest way would be just to keep the driver instance along with the Drizzle instance and close the connection using it directly. We might implement something more convenient in the future, but it's not a priority right now because there exists an easy enough alternative.

dankochetov avatar Apr 09 '23 23:04 dankochetov