home · contact · privacy
Minor DB code refactoring.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 5 Jan 2025 06:03:04 +0000 (07:03 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 5 Jan 2025 06:03:04 +0000 (07:03 +0100)
plomtask/db.py

index d83146b069a8a48fa4be96b9663efcdac2b39c3a..e42bfcc3d498d8ab1f791a6e67b5debb31c0b398 100644 (file)
@@ -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: