def insertState(conn, state_name):
    '''Prints the state given by param'''
    new_state = State()
    new_state.name = state_name
    conn.add(new_state)
    conn.commit()
    print(new_state.id)
def add_state(db):
    """adds state to the DB"""
    session = db[1]
    s = State()
    s.name = "Louisiana"
    session.add(s)
    session.commit()
    r = session.query(State).filter(State.name == "Louisiana")
    print(r[0].id)
    session.close()
    db[0].dispose()
def ins_state():
    """add a state in  the database"""
    engine = create_engine('mysql+mysqldb://{}:{}@localhost:3306/{}'.format(
        sys.argv[1], sys.argv[2], sys.argv[3]))
    Session = sessionmaker(bind=engine)
    session = Session()
    s = State()
    s.name = "Louisiana"
    session.add(s)
    session.commit()
    resp = session.query(State).filter(State.name == "Louisiana")
    print(resp[0].id)
    session.close()
    engine.dispose()
Пример #4
0
def model_state_insert():
    """
    Adds the State object “Louisiana” to the database.

    Takes 3 arguments: mysql username, mysql password and database name.
    """

    engine = create_engine('mysql+mysqldb://{}:{}@localhost/{}'.format(
        sys.argv[1], sys.argv[2], sys.argv[3]),
                           pool_pre_ping=True)
    Base.metadata.create_all(engine)

    Session = sessionmaker(bind=engine)
    session = Session()

    new_state = State()
    new_state.name = 'Louisiana'
    session.add(new_state)
    session.commit()
    print(new_state.id)

    session.close()
Пример #5
0
#!/usr/bin/python3
import sys
from model_state import Base, State
from sqlalchemy import create_engine, insert
from sqlalchemy.orm import sessionmaker

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

    Base.metadata.create_all(engine)
    Session = sessionmaker(bind=engine)
    session = Session()

    new = State()
    new.name = "Louisiana"
    session.add(new)
    session.commit()
    print(new.id)
    session.close()
Пример #6
0
#!/usr/bin/python3
""" prints the State object from the database hbtn_0e_6_usa
"""
if __name__ == '__main__':
    import sys
    from sqlalchemy import create_engine
    from model_state import Base, State
    from sqlalchemy.orm import sessionmaker
    if len(sys.argv) == 4:
        engine = create_engine(
            'mysql+mysqldb://{}:{}@localhost:3306/{}'.format(
                sys.argv[1], sys.argv[2], sys.argv[3]))
        Base.metadata.create_all(engine)
        Session = sessionmaker(bind=engine)
        conn = Session()
        new_state = State()
        new_state.name = 'Louisiana'
        conn.add(new_state)
        conn.commit()
        print("{}".format(new_state.id))
        conn.close()
Пример #7
0
#!/usr/bin/python3
"""script that prints the first State object from the database
hbtn_0e_6_usa"""
from sqlalchemy import (create_engine)
from model_state import Base, State
from sqlalchemy.orm import sessionmaker
import sys

if __name__ == "__main__":
    """Connecting"""
    engine = create_engine('mysql+mysqldb://{}:{}@localhost:3306/{}'.format(
        sys.argv[1], sys.argv[2], sys.argv[3]),
                           pool_pre_ping=True)
    Base.metadata.create_all(engine)
    Session = sessionmaker(bind=engine)
    session = Session()
    estado = State()
    estado.name = 'Louisiana'
    session.add(estado)
    session.commit()
    print(estado.id)
    session.close()
Пример #8
0
#!/usr/bin/python3
""" Start link class to table in database """
import sys
from model_state import Base, State
from sqlalchemy import (create_engine)
from sqlalchemy.orm import sessionmaker

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

    Base.metadata.create_all(engine)

    Session = sessionmaker(bind=engine)
    session = Session()

    state = State()
    state.name = "Louisiana"
    session.add(state)
    session.commit()

    q = session.query(State).filter(State.name == 'Louisiana').first()
    print("{}".format(q.id))

    session.close()
Пример #9
0
#!/usr/bin/python3
'''Lists all State objects from the database hbtn_0e_6_usa'''
from sys import argv
from model_state import Base, State
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

if __name__ == '__main__':
    arguments, state = argv[1:4], "Louisiana"
    connection = 'mysql+mysqldb://{}:{}@localhost/{}'
    engine = create_engine(connection.format(*arguments), pool_pre_ping=True)

    Base.metadata.create_all(engine)
    session_m = sessionmaker(bind=engine)
    session = session_m()

    new_state = State()
    new_state.name = state
    session.add(new_state)
    session.commit()

    print(new_state.id)
    session.close()
#!/usr/bin/python3
"""
adds the State object “Louisiana” to the database hbtn_0e_6_usa
"""

import sys
from model_state import Base, State
from sqlalchemy.orm import sessionmaker
from sqlalchemy import (create_engine)
from model_state import Base, State

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

    myObj = State()
    myObj.name = "Louisiana"
    session.add(myObj)
    session.commit()
    print(myObj.id)
Пример #11
0
#!/usr/bin/python3
""" sql """
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from model_state import Base, State
import sys

if __name__ == "__main__":
    result = None
    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()
    newS = State()
    newS.name = "Louisiana"
    session.add(newS)
    session.commit()
    print(newS.id)
#!/usr/bin/python3
'''
script that adds the State object “Louisiana” to the database hbtn_0e_6_usa
'''


from sqlalchemy import (create_engine)
from sqlalchemy.orm import sessionmaker
from model_state import Base, State
from sys import argv


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

    new = State()
    new.name = 'Louisiana'
    session.add(new)
    session.commit()
    print(new.id)

    session.close()
#!/usr/bin/python3
"""Select States module"""

if __name__ == "__main__":
    from model_state import Base, State
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker
    import sys
    size = len(sys.argv) - 1
    engine = None
    if size == 3:
        conn_values = "mysql+mysqldb://{}:{}@localhost:3306/{}"\
                    "".format(sys.argv[1], sys.argv[2], sys.argv[3])
        engine = create_engine(conn_values, pool_recycle=3600)
        Base.metadata.create_all(engine)
        Session = sessionmaker(bind=engine)
        session = Session()
        new_object = State()
        new_object.name = "Louisiana"
        session.add(new_object)
        session.commit()
        print(new_object.id)
        session.close()
Пример #14
0
#!/usr/bin/python3
"""Module."""
import sys
from model_state import Base, State

from sqlalchemy import (create_engine)
from sqlalchemy.orm import sessionmaker


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()
    lou = State()
    lou.name = "Louisiana"
    session.add(lou)
    session.commit()
    print(lou.id)
    session.close()
Пример #15
0
#!/usr/bin/python3
"""Start link class to table in database
"""
import sys

from sqlalchemy.orm.session import Session
from model_state import Base, State
from sqlalchemy.orm import sessionmaker
from sqlalchemy import (create_engine)

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

    Session = sessionmaker(bind=engine)
    session = Session()

    lou_state = session.query(State.name, State.id).all()
    popeyes = State()
    popeyes.id = len(lou_state) + 1
    popeyes.name = 'Louisiana'
    print(popeyes.id)
    session.add(popeyes)
    session.commit()
    session.close()