Exemplo n.º 1
0
def get_locations_by_building(id):
    curs = db.get_cursor()
    curs.execute(
        """SELECT id, number, building_id 
        FROM locations WHERE building_id = %s""", (id, ))

    return db.map_list(curs.fetchall())
Exemplo n.º 2
0
def get_building(id):
    curs = db.get_cursor()
    curs.execute('SELECT id, name FROM buildings WHERE id = %s', (id))

    if curs.rowcount < 1:
        raise exceptions.NotFound()

    return curs.fetchone().copy()
Exemplo n.º 3
0
def save(building_id, number):
    curs = db.get_cursor()
    curs.execute(
        """INSERT INTO locations (building_id, number) 
        VALUES (%s, %s) RETURNING id, building_id, number""",
        (building_id, number))
    db.commit()
    return curs.fetchone().copy()
Exemplo n.º 4
0
def get_location(id):
    curs = db.get_cursor()
    curs.execute(
        """SELECT id, number, building_id 
        FROM locations WHERE id = %s""", (id, ))

    if curs.rowcount < 1:
        raise exceptions.NotFound()

    return curs.fetchone().copy()
Exemplo n.º 5
0
def get_all_buildings():
    curs = db.get_cursor()
    curs.execute('SELECT id, name FROM buildings')
    return db.map_list(curs.fetchall())
Exemplo n.º 6
0
def save(building_name):
    curs = db.get_cursor()
    curs.execute('INSERT INTO buildings (name) VALUES (%s) RETURNING id, name',
                 (building_name, ))
    db.commit()
    return curs.fetchone().copy()
Exemplo n.º 7
0
def get_all_locations():
    curs = db.get_cursor()
    curs.execute('SELECT id, number, building_id FROM locations')
    return db.map_list(curs.fetchall())