コード例 #1
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def findByOwnerId(owner_id):
    param = int(owner_id)
    result = dao.getCursor().execute(
        """SELECT id, time, owner_id, place, description FROM lunch WHERE owner_id = ?""",
        [param]).fetchone()

    lunch = {
        'id': result[0],
        'time': result[1],
        'owner_id': result[2],
        'place': result[3],
        'description': result[4]
    }

    return lunch
コード例 #2
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def getAll():
    fromDb = dao.getCursor().execute(
        """SELECT id, time, owner_id, place, description FROM lunch"""
    ).fetchall()
    result = []

    for row in fromDb:
        lunch = {
            'id': row[0],
            'time': row[1],
            'owner_id': row[2],
            'place': row[3],
            'description': row[4]
        }
        result.append(lunch)

    return result
コード例 #3
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def getActiveByUserId(userId):
    param = int(userId)
    result = dao.getCursor().execute(
        """SELECT id, time, owner_id, place, description FROM lunch 
                                        JOIN users ON users.lunch_id = lunch.id
                                        WHERE users.user_id = ?""",
        [param]).fetchone()
    if result is None:
        return None
    lunch = {
        'id': result[0],
        'time': result[1],
        'owner_id': result[2],
        'place': result[3],
        'description': result[4]
    }

    return lunch
コード例 #4
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def getAllByUserId(userId):
    param = int(userId)
    fromDb = dao.getCursor().execute(
        """SELECT id, time, owner_id, place, description FROM lunch 
                                        JOIN users ON lunch.owner_id = users.user_id
                                        WHERE city in (SELECT city from users where user_id = ?)""",
        [param]).fetchall()

    result = []

    for row in fromDb:
        lunch = {
            'id': row[0],
            'time': row[1],
            'owner_id': row[2],
            'place': row[3],
            'description': row[4]
        }
        result.append(lunch)

    return result
コード例 #5
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def delete(lunchId):
    param = int(lunchId)
    dao.getCursor().execute("""DELETE FROM lunch WHERE id = ?""", [param])
    dao.get_connection().commit()
コード例 #6
0
ファイル: lunchService.py プロジェクト: Dasem/lanit_hackaton
def add(time, owner_id, place, description):
    dao.getCursor().execute(
        """INSERT INTO lunch (time, owner_id, place, description) VALUES (?, ?, ?, ?)""",
        (time, int(owner_id), place, description))
    dao.get_connection().commit()