Last active
February 11, 2026 02:15
-
-
Save mcsee/066db12ea24de4afed7f11452b5b03fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Optional | |
| import sqlite3 | |
| class DatabaseManager: | |
| def __init__(self, db_path: str): | |
| self.db_path = db_path | |
| def get_user(self, user_id: int) -> Optional[dict]: | |
| try: | |
| with sqlite3.connect(self.db_path) as conn: | |
| conn.row_factory = sqlite3.Row | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,)) | |
| row = cursor.fetchone() | |
| return dict(row) if row else None | |
| except sqlite3.Error as e: | |
| print(f"Database error: {e}") | |
| return None | |
| db = DatabaseManager("app.db") | |
| user = db.get_user(123) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment