20 lines
No EOL
646 B
Python
20 lines
No EOL
646 B
Python
from typing import List, Optional
|
|
from dotenv import load_dotenv
|
|
|
|
from sqlalchemy import String, create_engine, Boolean, text
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship, Session
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
DB_PASS = os.getenv("DOCKER_POSTGRES_PASS")
|
|
|
|
# Create engine for connecting to postgres test db
|
|
engine = create_engine(
|
|
f'postgresql+psycopg2://postgres:{DB_PASS}@localhost:5432/postgres')
|
|
|
|
stmt = text("SELECT x, y FROM some_table WHERE y > :y ORDER BY x, y")
|
|
with Session(engine) as session:
|
|
result = session.execute(stmt, {"y": 6})
|
|
for row in result:
|
|
print(f"x: {row.x} y: {row.y}") |