Close or destroy connection #228
-
I'm trying to write a Fastify plugin and it has an 'onClose' hook where you do db cleanup before exiting the app. How do I close or destroy the connection pool created from drizzle? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @GerardKetuma! Drizzle is not doing any connection pool destroy/create actions. You can do all of that in a driver you want to use with Drizzle const pool = new Pool({
connectionString: 'postgres://user:password@host:port/db',
});
const db = drizzle(pool);
const allUsers = await db.select().from(users);
...
await pool.end() // Here you can use node-pg pool, that was created before db https://node-postgres.com/apis/pool#poolend So if driver you are using supports |
Beta Was this translation helpful? Give feedback.
-
Thanks, that makes sense now. |
Beta Was this translation helpful? Give feedback.
Hi @GerardKetuma!
Drizzle is not doing any connection pool destroy/create actions. You can do all of that in a driver you want to use with Drizzle
So for example
node-postgres
driverhttps://node-postgres.com/apis/pool#poolend
So if driver you are using supports
connection end
then you can do the same as withnode-postgres