Implement repo error retrieval
This commit is contained in:
parent
4aabe467a4
commit
f5a556d06e
|
@ -1,5 +1,5 @@
|
||||||
from .connection import RepoConn, ArchiveConn, ErrorConn, LabelConn, CacheConn
|
from .connection import RepoConn, ArchiveConn, ErrorConn, LabelConn, CacheConn
|
||||||
from .object import Repo, Archive, Label
|
from .object import Repo, Archive, Label, Error
|
||||||
from .object.label import Label
|
from .object.label import Label
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -51,4 +51,12 @@ class BorgDatabase(object):
|
||||||
archive = self.archive_conn.get_latest(repo.primary_key)
|
archive = self.archive_conn.get_latest(repo.primary_key)
|
||||||
return self.cache_conn.get(archive.primary_key)
|
return self.cache_conn.get(archive.primary_key)
|
||||||
|
|
||||||
|
def get_repo_errors(self, repo_id):
|
||||||
|
label = self.label_conn.get_label_id(repo_id)
|
||||||
|
return self.error_conn.get_repo_errors(label)
|
||||||
|
|
||||||
|
def get_recent_repo_errors(self, repo_id, days=7):
|
||||||
|
label = self.label_conn.get_label_id(repo_id)
|
||||||
|
return self.error_conn.get_recent_repo_errors(label, days)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
|
@ -8,6 +8,8 @@ class ErrorConn(DatabaseConnection):
|
||||||
self.label_table = label_table
|
self.label_table = label_table
|
||||||
super().__init__(db_path, Error, table_name)
|
super().__init__(db_path, Error, 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"id INTEGER PRIMARY KEY," \
|
f"id INTEGER PRIMARY KEY," \
|
||||||
|
@ -18,6 +20,10 @@ class ErrorConn(DatabaseConnection):
|
||||||
f" {self.label_table} (id));"
|
f" {self.label_table} (id));"
|
||||||
self.sql_execute(create_statement)
|
self.sql_execute(create_statement)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region INSERT
|
||||||
|
|
||||||
def _exists(self, record, repo_id=None, archive_id=None, label_id=None):
|
def _exists(self, record, repo_id=None, archive_id=None, label_id=None):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
@ -33,3 +39,18 @@ class ErrorConn(DatabaseConnection):
|
||||||
cursor.execute(statement, args)
|
cursor.execute(statement, args)
|
||||||
self.sql_commit()
|
self.sql_commit()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region QUERIES
|
||||||
|
|
||||||
|
def get_repo_errors(self, label_id):
|
||||||
|
result = self.sql_execute_all(f"SELECT * FROM {self._sql_table} WHERE label_id = ?;", (label_id,))
|
||||||
|
return [Error.from_sql(row) for row in result]
|
||||||
|
|
||||||
|
def get_recent_repo_errors(self, label_id, days):
|
||||||
|
result = self.sql_execute_all(f"SELECT * FROM {self._sql_table} WHERE label_id = ?"
|
||||||
|
f" AND date(time) > date('now', '-{days} days');", (label_id,))
|
||||||
|
return [Error.from_sql(row) for row in result]
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
Loading…
Reference in New Issue
Block a user