Refactor: Improve database queries and fix formatting issues in stream utilities
This commit is contained in:
@@ -62,3 +62,5 @@ SELECT * FROM stream_tags;
|
|||||||
-- To see all tables in the database
|
-- To see all tables in the database
|
||||||
SELECT name FROM sqlite_master WHERE type='table';
|
SELECT name FROM sqlite_master WHERE type='table';
|
||||||
|
|
||||||
|
|
||||||
|
SELECT isLive FROM streams WHERE user_id = '5';
|
||||||
@@ -9,7 +9,7 @@ def streamer_live_status(user_id: int) -> bool:
|
|||||||
"""
|
"""
|
||||||
db = Database()
|
db = Database()
|
||||||
db.create_connection()
|
db.create_connection()
|
||||||
is_live = bool(db.fetchone("SELECT 1 FROM streams WHERE user_id = ? AND isLive = 1 ORDER BY stream_id DESC", (user_id,)))
|
is_live = db.fetchone("""SELECT isLive FROM streams WHERE user_id = ?""", (user_id,))
|
||||||
db.close_connection()
|
db.close_connection()
|
||||||
return is_live
|
return is_live
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ def user_stream(user_id: int, stream_id: int) -> dict:
|
|||||||
"""
|
"""
|
||||||
db = Database()
|
db = Database()
|
||||||
db.create_connection()
|
db.create_connection()
|
||||||
stream = db.fetchone("SELECT * FROM streams WHERE user_id = ? AND stream_id = ?", (user_id,stream_id))
|
stream = db.fetchone("SELECT * FROM streams WHERE user_id = ? AND stream_id = ?", (user_id, stream_id))
|
||||||
db.close_connection()
|
db.close_connection()
|
||||||
|
|
||||||
return stream
|
return stream
|
||||||
@@ -9,7 +9,7 @@ load_dotenv()
|
|||||||
|
|
||||||
serializer = URLSafeTimedSerializer(getenv("AUTH_SECRET_KEY"))
|
serializer = URLSafeTimedSerializer(getenv("AUTH_SECRET_KEY"))
|
||||||
|
|
||||||
def get_user_id(username: str) -> Optional[int]:
|
def get_user_id(username: str) -> int:
|
||||||
"""
|
"""
|
||||||
Returns user_id associated with given username
|
Returns user_id associated with given username
|
||||||
"""
|
"""
|
||||||
@@ -21,7 +21,7 @@ def get_user_id(username: str) -> Optional[int]:
|
|||||||
"SELECT user_id FROM users WHERE username = ?",
|
"SELECT user_id FROM users WHERE username = ?",
|
||||||
(username,)
|
(username,)
|
||||||
)
|
)
|
||||||
return data[0] if data else None
|
return data['user_id'] if data else None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user