#!/usr/bin/python3
'''List all States using SQLAlchemy'''

from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
from model_state import Base, State
from model_city import City
import sys

if __name__ == "__main__":
    engine = create_engine('mysql+mysqldb://{}:{}@localhost/{}'.
                           format(sys.argv[1], sys.argv[2], sys.argv[3]),
                           pool_pre_ping=True)
    Session = sessionmaker(bind=engine)
    session = Session()

    for S, C in (session.query(State, City).filter(State.id == City.state_id)
                 .order_by(City.id)):
        print(S.name + ": (" + str(C.id) + ") " + C.name)
