Implement get methods for retrieving latest stats
This commit is contained in:
parent
3b7405fe9c
commit
f93c93b751
|
@ -34,4 +34,7 @@ class BorgDatabase(object):
|
||||||
def get_repos(self):
|
def get_repos(self):
|
||||||
return self.repo_conn.get_all()
|
return self.repo_conn.get_all()
|
||||||
|
|
||||||
|
def get_repo_stats(self, repo):
|
||||||
|
return self.stats_conn.get_latest_stats(repo)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
|
@ -9,6 +9,8 @@ class StatsConn(DatabaseConnection):
|
||||||
|
|
||||||
super().__init__(db_path, table_name)
|
super().__init__(db_path, table_name)
|
||||||
|
|
||||||
|
# region INIT
|
||||||
|
|
||||||
def _create_table(self):
|
def _create_table(self):
|
||||||
create_statement = f"create table if not exists {self._sql_table}(" \
|
create_statement = f"create table if not exists {self._sql_table}(" \
|
||||||
f"stat_id INTEGER PRIMARY KEY," \
|
f"stat_id INTEGER PRIMARY KEY," \
|
||||||
|
@ -24,6 +26,10 @@ class StatsConn(DatabaseConnection):
|
||||||
f" {self.archive_table} (archive_id));"
|
f" {self.archive_table} (archive_id));"
|
||||||
self.sql_execute(create_statement)
|
self.sql_execute(create_statement)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region INSERT
|
||||||
|
|
||||||
def _exists(self, record):
|
def _exists(self, record):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
@ -41,3 +47,13 @@ class StatsConn(DatabaseConnection):
|
||||||
cursor.execute(statement, args)
|
cursor.execute(statement, args)
|
||||||
self.sql_commit()
|
self.sql_commit()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region QUERY
|
||||||
|
|
||||||
|
def get_latest_stats(self, repo):
|
||||||
|
key = repo.primary_key
|
||||||
|
return self.sql_execute_one(f"SELECT * FROM {self._sql_table} WHERE repo_id=?;", (key,))
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
Loading…
Reference in New Issue
Block a user