From: Christian Heller Date: Sun, 5 Jan 2025 06:03:04 +0000 (+0100) Subject: Minor DB code refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/day?a=commitdiff_plain;h=92d8450bec9a8bc85d071af27407318876601629;p=plomtask Minor DB code refactoring. --- 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: