N
Nuxt3mo ago
cosbgn

Best nitro hook to kill a DB connection?

I would like to use hyperdrive which from their docs requires to clean up the client using waitUntil:
const sql = postgres(env.HYPERDRIVE.connectionString);
const result = await sql`select * from pg_tables LIMIT 10`;
// Clean up the client, ensuring we don't kill the worker before that is
// completed.
ctx.waitUntil(sql.end());
const sql = postgres(env.HYPERDRIVE.connectionString);
const result = await sql`select * from pg_tables LIMIT 10`;
// Clean up the client, ensuring we don't kill the worker before that is
// completed.
ctx.waitUntil(sql.end());
I would like to avoid doing this in each route, so I'm thinking a plugin is the right wait, should I use afterResponse? Something like;
nitroApp.hooks.hook("afterResponse", (event, { body }) => {
// SQL is auto-exported from server/utils
event.waitUntil(sql.end());
});
nitroApp.hooks.hook("afterResponse", (event, { body }) => {
// SQL is auto-exported from server/utils
event.waitUntil(sql.end());
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server