Spaces:
Runtime error
Runtime error
Download templates/api_templates/database.py.j2 from DesarrolloTT/DataSuitePro: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/templates/api_templates/database.py.j2
- Command line
-
hf download hf://spaces/DesarrolloTT/DataSuitePro/templates/api_templates/database.py.j2
-
curl -L -o database.py.j2 https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/templates/api_templates/database.py.j2
1.06 kB
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| # Configuración de la base de datos | |
| {% if database == "sqlite" %} | |
| SQLALCHEMY_DATABASE_URL = "sqlite:///./{{ project_name.lower() }}.db" | |
| {% elif database == "mysql" %} | |
| SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://username:password@localhost/{{ project_name.lower() }}" | |
| {% elif database == "postgresql" %} | |
| SQLALCHEMY_DATABASE_URL = "postgresql://username:password@localhost/{{ project_name.lower() }}" | |
| {% else %} | |
| SQLALCHEMY_DATABASE_URL = "sqlite:///./{{ project_name.lower() }}.db" | |
| {% endif %} | |
| engine = create_engine( | |
| SQLALCHEMY_DATABASE_URL, | |
| {% if database == "sqlite" %} | |
| connect_args={"check_same_thread": False} | |
| {% else %} | |
| connect_args={} | |
| {% endif %} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| # Dependency para obtener sesión de BD | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() |