From 9be6b0b290f8d101ae61938363c4291f6d657de9 Mon Sep 17 00:00:00 2001 From: hilfe Date: Wed, 24 Jan 2024 15:39:03 +0100 Subject: [PATCH] fix database, add test scripts --- README.md | 2 +- backend/__init__.py | 14 ++++++++++++-- backend/database.py | 4 +++- run.py | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6013f69..b026b2a 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# LF5 Databes Project +# LF5 Database Project diff --git a/backend/__init__.py b/backend/__init__.py index c4f2375..ffd8949 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,7 +1,17 @@ #!/usr/bin/env python3 from .database import db import os +from dotenv import load_dotenv +import time + async def startup(): - await db.signin({"user": os.getenv('DB_USER'), "pass": os.getenv('DB_PW')}) - await db.use("test", "test") \ No newline at end of file + load_dotenv() + await db.connect() + await db.signin({"user": os.environ.get('DB_USER'), "pass": os.environ.get('DB_PW')}) + await db.use("lf5", "lf5") + await db.query('DEFINE TABLE kunde SCHEMAFULL') + await db.query('DEFINE FIELD kundenNr ON TABLE kunde TYPE string') + while(True): + print(await db.query('SELECT * FROM kunde')) + time.sleep(5) \ No newline at end of file diff --git a/backend/database.py b/backend/database.py index 644e625..c6ec188 100644 --- a/backend/database.py +++ b/backend/database.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 import os from surrealdb import Surreal +from dotenv import load_dotenv -db = Surreal(f"{os.getenv('DB_HOST')}:{os.getenv('DB_PORT')}") +load_dotenv() +db = Surreal(f"ws://{os.environ.get('DB_HOST')}:{os.environ.get('DB_PORT')}/rpc") # TODO: "SQL"-Prompts \ No newline at end of file diff --git a/run.py b/run.py index 4428fc4..8eb8c53 100644 --- a/run.py +++ b/run.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 from backend import startup -from dotenv import load_dotenv + import asyncio +import os if __name__ == "__main__": - load_dotenv() # Load User Variables asyncio.run(startup()) \ No newline at end of file