コード例 #1
0
def showRecords():
    session = Session()
    movies = session.query(Movie).all()

    for m in movies:
        print(f'{m.title} released on {m.release_date}')

    actors = session.query(Actor).all()

    for a in actors:
        print(f'{a.name} born on {a.birthday}')
コード例 #2
0
def addContactDetails():
    Base.metadata.create_all(engine)
    session = Session()
    # SELECT * FROM my_movie_db.actors where name = 'Adivi Shesu';
    # customerData = session.query(Customer).filter(Customer.name==customerName)
    # movies = session.query(Movie).all()
    # actor = session.query(actorObj).filter(actorObj.name == 'Adivi Shesu')
    actorId = 0
    # User.query.filter(User.email.endswith('@example.com')).all()
    # actor = Actor.query.filter(Actor.name=='Adivi Shesu').all()
    """with engine.connect() as con:
        rs = con.execute('SELECT * FROM my_movie_db.actors where name = ' +'Adivi Shesu')"""

    metadata = MetaData(bind=None)
    table = Table('actors', metadata, autoload=True, autoload_with=engine)
    stmt = select([table]).where(table.columns.name == 'Adivi Shesu')

    connection = engine.connect()
    results = connection.execute(stmt).fetchall()

    print(str(results[0][1], 'utf-8'))
    print(results[0][2])

    actor = Actor(str(results[0][1], 'utf-8'), results[0][2])
    actor.id = results[0][0]

    contactDetails = ContactDetails("123 123 1234", "Hitech city,Hyderabad", actor)
    session.add(contactDetails)

    session.commit()
    session.close()
コード例 #3
0
def addContactDetails():
    Base.metadata.create_all(engine)
    session = Session()

    actor = session.query(Actor).filter(Actor.name == 'Adivi Shesu').all()
    a = actor[0]
    contactDetails = ContactDetails("123 123 1234", "Hitech city,Hyderabad", a)
    session.add(contactDetails)

    session.commit()
    session.close()
コード例 #4
0
def addStuntmanToActor():
    Base.metadata.create_all(engine)
    session = Session()

    actor = session.query(Actor).filter(Actor.name == 'Adivi Shesu').first()

    stuntman = Stuntman("Bheem",True, actor)

    session.add(stuntman)
    session.commit()
    session.close()
コード例 #5
0
def addRecods():
    # Generate database schema
    Base.metadata.create_all(engine)

    session = Session()

    sira = Movie("Sira", date(1978, 8, 19))
    #persist data
    session.add(sira)

    chiru = Actor("Chiru", date(2000, 8, 19))
    #persist data
    session.add(chiru)

    #movies and actors relationship establishments
    sira.actors = [chiru]

    #commit and close session
    session.commit()
    session.close()