From 57d7d257438224297e69e8383d7eb547fb2ab4b7 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Mon, 22 Jan 2024 06:50:31 -0500 Subject: [PATCH] set sqlite file path relative to config path if possible --- relay/config.py | 3 +++ relay/database/__init__.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/relay/config.py b/relay/config.py index 5aadcec..937372f 100644 --- a/relay/config.py +++ b/relay/config.py @@ -57,6 +57,9 @@ class Config: @property def sqlite_path(self) -> Path: + if not os.path.isabs(self.sq_path): + return self.path.parent.joinpath(self.sq_path).resolve() + return Path(self.sq_path).expanduser().resolve() diff --git a/relay/database/__init__.py b/relay/database/__init__.py index d69b214..925c5e0 100644 --- a/relay/database/__init__.py +++ b/relay/database/__init__.py @@ -18,7 +18,7 @@ if typing.TYPE_CHECKING: def get_database(config: Config, migrate: Optional[bool] = True) -> tinysql.Database: if config.db_type == "sqlite": - db = tinysql.Database.sqlite(config.sq_path, connection_class = Connection) + db = tinysql.Database.sqlite(config.sqlite_path, connection_class = Connection) elif config.db_type == "postgres": db = tinysql.Database.postgres(