Ejemplo n.º 1
0
def get(name: str):
    try:
        fruit: Fruit = SESSION.query(Fruit).filter(Fruit.name == name).one()
        return JSONResponse(fruit.dumps(), 200)
    except Exception as error:
        SESSION.rollback()
        logger.error(error)
        return PlainTextResponse("Bad Request", 400)
Ejemplo n.º 2
0
def add_user(user_id, user_name, first_name, last_name):
    users = SESSION.query(Users).get(user_id)
    if users:
        return False
    else:
        users = Users(user_id, user_name, first_name, last_name)
    SESSION.add(users)
    SESSION.commit()
    return True
Ejemplo n.º 3
0
def put(payload: Payload):
    try:
        fruit: Fruit = SESSION.query(Fruit).filter(
            Fruit.name == payload.name).one()
        fruit.count = payload.count
        SESSION.commit()
        return PlainTextResponse("OK", 200)
    except Exception as error:
        SESSION.rollback()
        logger.error(error)
        return PlainTextResponse("Bad Request", 400)
def init_db():
    SESSION.merge(Fruit(**{"name": "apple", "count": 1}))
    SESSION.commit()
 def add(self):
     SESSION.add(self)
 def query(cls):
     return SESSION.query(cls)
 def commit():
     SESSION.commit()
Ejemplo n.º 8
0
def clean_db():
    SESSION.query(Fruit).delete()
Ejemplo n.º 9
0
def get_all_users():
    users = SESSION.query(Users).all()
    SESSION.commit()
    return users