25 lines
715 B
Python
25 lines
715 B
Python
# app/database.py
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
# SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db"
|
|
#SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://root:secret@localhost:3306/test" # Przykład dla MySQL
|
|
SQLALCHEMY_DATABASE_URL = "postgresql+psycopg2://admin:pass@localhost:5432/crypto"
|
|
|
|
engine = create_engine(
|
|
SQLALCHEMY_DATABASE_URL,
|
|
)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
# Test connection
|
|
from sqlalchemy import text
|
|
|
|
with engine.connect() as conn:
|
|
result = conn.execute(text("select 'hello world'"))
|
|
print(result.all())
|
|
|
|
|