From 40303a20bc39c270c8e50339ada30f9750e2a681 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 29 May 2024 12:15:42 -0500 Subject: [PATCH] Log transaction start and end queries (#95) Route transaction control queries through the SQLKit interface so they get logged properly. --- .../FluentSQLiteDatabase.swift | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift b/Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift index 1c21f42..20e026e 100644 --- a/Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift +++ b/Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift @@ -95,21 +95,23 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase { } return try await self.withConnection { conn in - _ = try await conn.query("BEGIN TRANSACTION") + let db = FluentSQLiteDatabase( + database: conn, + context: self.context, + dataEncoder: self.dataEncoder, + dataDecoder: self.dataDecoder, + queryLogLevel: self.queryLogLevel, + inTransaction: true + ) + + try await db.raw("BEGIN TRANSACTION").run() do { - let result = try await closure(FluentSQLiteDatabase( - database: conn, - context: self.context, - dataEncoder: self.dataEncoder, - dataDecoder: self.dataDecoder, - queryLogLevel: self.queryLogLevel, - inTransaction: true - )) + let result = try await closure(db) - _ = try await conn.query("COMMIT TRANSACTION") + try await db.raw("COMMIT TRANSACTION").run() return result } catch { - _ = try? await conn.query("ROLLBACK TRANSACTION") + try? await db.raw("ROLLBACK TRANSACTION").run() throw error } }