From 35e6bb8e1344be26ff9a5f701de6d71b4973c9df Mon Sep 17 00:00:00 2001 From: Imam Fahrur Rofi Date: Sat, 23 Mar 2024 23:32:48 +0700 Subject: [PATCH] Add timeout to end postgres.js connection --- src/postgres/postgres.ts | 2 +- src/setup/init-postgres.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/postgres/postgres.ts b/src/postgres/postgres.ts index 9c487a8..159e92e 100644 --- a/src/postgres/postgres.ts +++ b/src/postgres/postgres.ts @@ -12,4 +12,4 @@ const sql = postgres(Object.assign({ transform: postgres.camel }, options)); export const postgresGetUser = async (id: number) => await sql`SELECT * FROM users WHERE id = ${id}`.then((rows) => rows[0]); -export const postgresClose = async () => await sql.end(); +export const postgresClose = async () => await sql.end({ timeout: 1 }); diff --git a/src/setup/init-postgres.ts b/src/setup/init-postgres.ts index f2d64a5..26d6519 100644 --- a/src/setup/init-postgres.ts +++ b/src/setup/init-postgres.ts @@ -36,4 +36,4 @@ await sql`select count(id) as total from ${sql('users')}`.then((res) => console.log(`[PostgreSQL] total users: ${res[0].total}`) ); -await sql.end(); +await sql.end({ timeout: 1 });