Exemplo n.º 1
0
def handler(event, context):
    with session_scope(rds_session) as session:
        body = json.loads(event['body'])
        first_name = body.get('firstname')
        last_name = body.get('lastname')
        person = People(first_name=first_name, last_name=last_name)
        session.add(person)
        session.commit()
        return json_response(200, {"message": "New Person {} {} added.".format(first_name, last_name)})
Exemplo n.º 2
0
def handler(event, context):
    with session_scope(rds_session) as session:
        results = raw_query(session)
        return json_response(
            200, {
                "people": [{
                    "id": person[0],
                    "first_name": person[1],
                    "last_name": person[2]
                } for person in results]
            })
Exemplo n.º 3
0
def handler(event, context):
    with session_scope(rds_session) as session:
        if not engine.dialect.has_table(engine, 'people'):
            Base.metadata.create_all(engine)
            message = 'Table created'
        else:
            session.query(People).delete()
            message = 'Table reset'
        insert_names(session)
        session.commit()
        return json_response(200, {"message": message})
Exemplo n.º 4
0
def handler(event, context):
    with session_scope(rds_session) as session:
        people = session.query(People).all()
        return json_response(200, {"people": [person.response for person in people]})
Exemplo n.º 5
0
def handler(event, context):
    with session_scope(rds_session) as session:
        query = sqlalchemy_query(session)
        return json_response(200, {"people": [person.response for person in query]})