From 5b9cfd08c4e4cc81c5b43f1f6948a981575d47f2 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Thu, 17 Oct 2024 13:04:15 +0200 Subject: [PATCH] Deinitialize the query result and release the connection as soon as possible. --- src/insert.zig | 3 ++- src/query.zig | 3 ++- src/update.zig | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/insert.zig b/src/insert.zig index 9a320aa..e1c0c4e 100644 --- a/src/insert.zig +++ b/src/insert.zig @@ -299,7 +299,8 @@ pub fn RepositoryInsert(comptime Model: type, comptime TableShape: type, comptim if (self.sql) |_| {} else { try self.buildSql(); } // Execute query and get its result. - const queryResult = try self.execQuery(); + var queryResult = try self.execQuery(); + defer queryResult.deinit(); //TODO deduplicate this in postgresql.zig, we could do it if Mapper type was exposed. //TODO make a generic mapper and do it in repository.zig? diff --git a/src/query.zig b/src/query.zig index c804579..a462810 100644 --- a/src/query.zig +++ b/src/query.zig @@ -216,7 +216,8 @@ pub fn RepositoryQuery(comptime Model: type, comptime TableShape: type, comptime if (self.sql) |_| {} else { try self.buildSql(); } // Execute query and get its result. - const queryResult = try self.execQuery(); + var queryResult = try self.execQuery(); + defer queryResult.deinit(); //TODO deduplicate this in postgresql.zig, we could do it if Mapper type was exposed. //TODO make a generic mapper and do it in repository.zig? diff --git a/src/update.zig b/src/update.zig index 321d3b4..88b38a2 100644 --- a/src/update.zig +++ b/src/update.zig @@ -303,7 +303,8 @@ pub fn RepositoryUpdate(comptime Model: type, comptime TableShape: type, comptim if (self.sql) |_| {} else { try self.buildSql(); } // Execute query and get its result. - const queryResult = try self.execQuery(); + var queryResult = try self.execQuery(); + defer queryResult.deinit(); //TODO deduplicate this in postgresql.zig, we could do it if Mapper type was exposed. //TODO make a generic mapper and do it in repository.zig?