Add get all methods
This commit is contained in:
parent
b9664263d0
commit
9f020c0ee5
|
@ -17,6 +17,8 @@ class BorgDatabase(object):
|
||||||
self.error_conn = ErrorConn(db_path,
|
self.error_conn = ErrorConn(db_path,
|
||||||
table_name=self.error_name)
|
table_name=self.error_name)
|
||||||
|
|
||||||
|
# region INSERT
|
||||||
|
|
||||||
def insert_record(self, repo, archive, stats):
|
def insert_record(self, repo, archive, stats):
|
||||||
repo_id = self.repo_conn.insert(repo)
|
repo_id = self.repo_conn.insert(repo)
|
||||||
archive_id = self.archive_conn.insert(archive, repo_id)
|
archive_id = self.archive_conn.insert(archive, repo_id)
|
||||||
|
@ -24,3 +26,12 @@ class BorgDatabase(object):
|
||||||
|
|
||||||
def insert_error(self, borg_error):
|
def insert_error(self, borg_error):
|
||||||
self.error_conn.insert(borg_error)
|
self.error_conn.insert(borg_error)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region GET
|
||||||
|
|
||||||
|
def get_repos(self):
|
||||||
|
return self.repo_conn.get_all()
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
|
@ -16,6 +16,16 @@ class DatabaseConnection(ABC):
|
||||||
self._create_table()
|
self._create_table()
|
||||||
self.sql_commit()
|
self.sql_commit()
|
||||||
|
|
||||||
|
# region INIT
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _create_table(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region PROPERTIES
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sql_lock(self):
|
def sql_lock(self):
|
||||||
return self.__sql_lock
|
return self.__sql_lock
|
||||||
|
@ -24,6 +34,13 @@ class DatabaseConnection(ABC):
|
||||||
def sql_cursor(self):
|
def sql_cursor(self):
|
||||||
return self.__sql_database.cursor()
|
return self.__sql_database.cursor()
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region GENERIC SQL
|
||||||
|
|
||||||
|
def sql_commit(self):
|
||||||
|
self.__sql_database.commit()
|
||||||
|
|
||||||
def sql_execute(self, statement: str, args: tuple = None):
|
def sql_execute(self, statement: str, args: tuple = None):
|
||||||
with self.__sql_lock:
|
with self.__sql_lock:
|
||||||
cursor = self.sql_cursor
|
cursor = self.sql_cursor
|
||||||
|
@ -63,8 +80,9 @@ class DatabaseConnection(ABC):
|
||||||
|
|
||||||
return cursor.fetchone()
|
return cursor.fetchone()
|
||||||
|
|
||||||
def sql_commit(self):
|
# endregion
|
||||||
self.__sql_database.commit()
|
|
||||||
|
# region MODIFICATION
|
||||||
|
|
||||||
def insert(self, record, repo_id=None, archive_id=None):
|
def insert(self, record, repo_id=None, archive_id=None):
|
||||||
exists, primary_key = self.exists(record)
|
exists, primary_key = self.exists(record)
|
||||||
|
@ -97,9 +115,18 @@ class DatabaseConnection(ABC):
|
||||||
def _exists(self, record) -> (str, tuple):
|
def _exists(self, record) -> (str, tuple):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
# endregion
|
||||||
def _create_table(self):
|
|
||||||
raise NotImplementedError
|
# region QUERIES
|
||||||
|
|
||||||
|
def get_all(self):
|
||||||
|
result = self.sql_execute_one(f"SELECT * FROM {self._sql_table};")
|
||||||
|
if result is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return result[0]
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
with self.__sql_lock:
|
with self.__sql_lock:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user