Correct _insert signature for consistency

This commit is contained in:
George Lacey 2021-05-04 05:48:18 +01:00
parent 40ecdf04ef
commit 75521f61ee
4 changed files with 10 additions and 6 deletions

View File

@ -19,7 +19,9 @@ class ArchiveConn(DatabaseConnection):
def _exists(self, record):
return f"SELECT archive_id FROM {self._sql_table} WHERE fingerprint=?;", (record.fingerprint,)
def _insert(self, record, repo_id) -> int:
def _insert(self, record, repo_id=None, archive_id=None) -> int:
if repo_id is None:
raise Exception("Repo id not supplied")
with self.sql_lock:
cursor = self.sql_cursor
statement = f"INSERT INTO {self._sql_table}"\

View File

@ -66,19 +66,19 @@ class DatabaseConnection(ABC):
def sql_commit(self):
self.__sql_database.commit()
def insert(self, record, *args, **kwargs):
def insert(self, record, repo_id=None, archive_id=None):
exists, primary_key = self.exists(record)
if exists:
self._update(record, primary_key)
return primary_key
else:
return self._insert(record, *args, **kwargs)
return self._insert(record, repo_id, archive_id)
def _update(self, record, primary_key):
pass
@abstractmethod
def _insert(self, record, *args, **kwargs) -> int:
def _insert(self, record, repo_id=None, archive_id=None) -> int:
raise NotImplementedError
def exists(self, record) -> (bool, int):

View File

@ -5,7 +5,7 @@ class RepoConn(DatabaseConnection):
def __init__(self, db_path, table_name: str = 'repo'):
super(RepoConn, self).__init__(db_path, table_name)
def _insert(self, record) -> int:
def _insert(self, record, repo_id=None, archive_id=None) -> int:
with self.sql_lock:
cursor = self.sql_cursor
statement = f"INSERT INTO {self._sql_table}"\

View File

@ -21,7 +21,9 @@ class StatsConn(DatabaseConnection):
def _exists(self, record):
return None, None
def _insert(self, record, repo_id, archive_id) -> int:
def _insert(self, record, repo_id=None, archive_id=None) -> int:
if repo_id is None or archive_id is None:
raise Exception("Repo and archive ids not supplied")
with self.sql_lock:
cursor = self.sql_cursor
statement = f"INSERT INTO {self._sql_table}"\