From 22714994d2b7cfa238c8b2d54a3639cd6417e9b6 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 21 Nov 2025 22:30:47 -0800 Subject: scaffold implementation for remote sqlite db --- common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 common.py (limited to 'common.py') diff --git a/common.py b/common.py new file mode 100644 index 0000000..e45b5f0 --- /dev/null +++ b/common.py @@ -0,0 +1,15 @@ +from database.local_database import Database as LocalDatabase +from database.remote_database import RemoteDatabase +import os + +def create_database_connection(): + sqlite_db = os.getenv("SQLITE_DB") + if sqlite_db is None or sqlite_db == "": + return LocalDatabase("news.db") + elif sqlite_db.endswith(".db"): + return LocalDatabase(sqlite_db) + else: + auth_token = os.getenv("REMOTE_AUTH_TOKEN") + if not auth_token: + raise RuntimeError("Remote DB was specified but no auth token was provided") + return RemoteDatabase(url=sqlite_db, auth_token=auth_token) -- cgit v1.2.3