"""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,
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: