Esempio n. 1
0
def get_solution_by_id(id):
    sql = 'SELECT * FROM solution WHERE id = "{}" limit 1'.format(id)

    conn = g.db.pool.connection()
    with conn.cursor() as cursor:
        cursor.execute(sql)
        records = cursor.fetchall()
    conn.close()

    solution_list = []
    for record in records:
        solution = Solution()
        solution.from_record(record)
        solution_list.append(solution.__dict__)

    return solution_list[0]
Esempio n. 2
0
def get_solutions(where, pageable):
    pageable = gen_pageable(pageable)
    sql = 'SELECT * FROM solution {} {}'.format(where, pageable)
    sql_total_count = 'SELECT COUNT(*) FROM solution {}'.format(where)

    conn = g.db.pool.connection()
    with conn.cursor() as cursor:
        cursor.execute(sql)
        records = cursor.fetchall()
        solution_list = []
        for record in records:
            solution = Solution()
            solution.from_record(record)
            solution_list.append(solution.__dict__)

        cursor.execute(sql_total_count)
        total_count = cursor.fetchone()
    conn.close()

    return total_count[0], solution_list