def read(conn, asset_id, keys=FIELDS): """ Fetch one or more schedules from the database. Returns a list of dicts or one dict. """ schedules = [] mk = mkdict(keys) with db.cursor(conn) as c: c.execute(queries.read_schedule(keys), [asset_id]) schedules = [mk(schedule) for schedule in c.fetchall()] return schedules
def read(conn, asset_id, keys=FIELDS): """ Fetch one or more schedules from the database. Returns a list of dicts or one dict. Assets' is_active field is updated before returning. """ schedules = [] mk = mkdict(keys) with db.cursor(conn) as c: c.execute(queries.read_schedule(keys), [asset_id]) schedules = [mk(schedule) for schedule in c.fetchall()] # [schedules.update({'is_active': is_active(schedules)}) for schedule in schedules] # if asset_id and len(assets): # return schedules[0] return schedules