Skip to content

Commit

Permalink
changing client
Browse files Browse the repository at this point in the history
  • Loading branch information
robertandremitchell committed Dec 9, 2024
1 parent ec5447a commit e2a941d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions query-connector/src/app/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,24 +849,20 @@ export const deleteQueryById = async (queryId: string) => {
DELETE FROM query WHERE id = $1;
`;

const client = await dbClient.connect();

try {
await client.query("BEGIN");
await dbClient.query("BEGIN");

// Execute deletion queries in the correct order
await client.query(deleteQuerySql1, [queryId]);
await client.query(deleteQuerySql2, [queryId]);
await client.query(deleteQuerySql3, [queryId]);
await dbClient.query(deleteQuerySql1, [queryId]);
await dbClient.query(deleteQuerySql2, [queryId]);
await dbClient.query(deleteQuerySql3, [queryId]);

await client.query("COMMIT");
await dbClient.query("COMMIT");
return { success: true };
} catch (error) {
await client.query("ROLLBACK");
await dbClient.query("ROLLBACK");
console.error(`Failed to delete query with ID ${queryId}:`, error);
return { success: false, error: "Failed to delete the query." };
} finally {
client.release();
}
};

Expand Down

0 comments on commit e2a941d

Please sign in to comment.