From 92d8450bec9a8bc85d071af27407318876601629 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 5 Jan 2025 07:03:04 +0100 Subject: [PATCH] Minor DB code refactoring. --- plomtask/db.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plomtask/db.py b/plomtask/db.py index d83146b..e42bfcc 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -158,11 +158,9 @@ class DatabaseConnection: """A single connection to the database.""" def __init__(self, db_file: DatabaseFile) -> None: - self.conn = sql_connect(db_file.path) - - def commit(self) -> None: - """Commit SQL transaction.""" - self.conn.commit() + self._conn = sql_connect(db_file.path) + self.commit = self._conn.commit + self.close = self._conn.close def exec(self, code: str, @@ -174,13 +172,9 @@ class DatabaseConnection: if build_q_marks: q_marks = ('?' if len(inputs) == 1 else '(' + ','.join(['?'] * len(inputs)) + ')') - return self.conn.execute(f'{code} {q_marks}', inputs) - return self.conn.execute(code, inputs) - return self.conn.execute(code) - - def close(self) -> None: - """Close DB connection.""" - self.conn.close() + return self._conn.execute(f'{code} {q_marks}', inputs) + return self._conn.execute(code, inputs) + return self._conn.execute(code) def rewrite_relations(self, table_name: str, key: str, target: int | str, rows: list[list[Any]], key_index: int = 0) -> None: -- 2.30.2