Spaces:
Sleeping
Sleeping
Download database/sqlalchemy_store.py from sbasu2512/stock-scraper: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/spaces/sbasu2512/stock-scraper/resolve/main/database/sqlalchemy_store.py
- Command line
-
hf download hf://spaces/sbasu2512/stock-scraper/database/sqlalchemy_store.py
-
curl -L -o sqlalchemy_store.py https://huggingface.co/spaces/sbasu2512/stock-scraper/resolve/main/database/sqlalchemy_store.py
839 Bytes
| """SQLAlchemy connection helpers for reading SQLite market data.""" | |
| from __future__ import annotations | |
| from contextlib import contextmanager | |
| from sqlalchemy import create_engine, event | |
| def _engine(database_url: str): | |
| engine = create_engine(database_url, connect_args={"timeout": 30}) | |
| def _configure_sqlite(dbapi_connection, _): | |
| cursor = dbapi_connection.cursor() | |
| cursor.execute("PRAGMA foreign_keys = ON") | |
| cursor.execute("PRAGMA journal_mode = WAL") | |
| cursor.execute("PRAGMA busy_timeout = 30000") | |
| cursor.close() | |
| return engine | |
| def read_connection(database_url: str): | |
| engine = _engine(database_url) | |
| try: | |
| with engine.connect() as connection: | |
| yield connection | |
| finally: | |
| engine.dispose() | |