Skip to content

Commit 063d91a

Browse files
committed
refining
1 parent 1909d58 commit 063d91a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/utilities/testDbConnection.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ async function checkCountAfterImport(): Promise<boolean> {
6161
return allValid;
6262
} catch (error) {
6363
console.error(`ERROR: ${error}`);
64-
return false;
6564
}
65+
return false;
6666
}
6767

6868
/**
@@ -81,17 +81,15 @@ async function updateDatabase(): Promise<boolean> {
8181

8282
const userId = user[0]?.id;
8383

84-
await db
84+
// Update the user and return the updated row
85+
const [updatedUser] = await db
8586
.update(schema.usersTable)
8687
.set({ name: updatedName })
87-
.where(sql`id = ${userId}`);
88-
89-
const updatedUser = await db
90-
.select()
91-
.from(schema.usersTable)
92-
.where(sql`id = ${userId}`);
88+
.where(sql`id = ${userId}`)
89+
.returning({ name: schema.usersTable.name });
9390

94-
if (updatedUser[0]?.name !== updatedName) {
91+
// Validate update in one step
92+
if (!updatedUser || updatedUser.name !== updatedName) {
9593
console.error("ERROR: Database update failed!");
9694
return false;
9795
}
@@ -119,7 +117,8 @@ async function runValidation(): Promise<void> {
119117
process.exit(1);
120118
}
121119
console.log("Database Updation : Success");
122-
process.exit(0);
120+
await queryClient.end();
121+
process.exit(0);
123122
} catch (error) {
124123
if (error instanceof Error) {
125124
console.error(`\nERROR: ${error.message}`);

0 commit comments

Comments
 (0)