diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-11-21 22:30:47 -0800 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-11-21 23:27:30 -0800 |
| commit | 22714994d2b7cfa238c8b2d54a3639cd6417e9b6 (patch) | |
| tree | dc7036309fbb35376f452f44e33bfbe9c2e18c61 /common.py | |
| parent | a7347217899fb7a3addcee58a9fbee4a0c07ff57 (diff) | |
scaffold implementation for remote sqlite db
Diffstat (limited to 'common.py')
| -rw-r--r-- | common.py | 15 |
1 files changed, 15 insertions, 0 deletions
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) |
