from datetime import datetime

from sqlalchemy.orm import sessionmaker, Session

from app.contact import engine
from app.models import Products


def fetch_by_current_date(connection: Session) -> list:
    current: datetime = datetime(datetime.today().year, datetime.today().month, datetime.today().day)
    return connection.query(Products).filter(Products.created >= current).all()


def fetch_by_name(connection: Session, nomination: str) -> list:
    return connection.query(Products).filter(Products.name == nomination).all()


if __name__ == '__main__':
    Session: sessionmaker = sessionmaker(bind=engine)
    session: Session = Session()

    product: list = fetch_by_current_date(connection=session)
    print(product)

    name: str = "milk"
    product: list = fetch_by_name(
        connection=session,
        nomination=name
    )
    print(product)
