Can somebody explain me the last line return (rv[0] if rv else None) if one else rv ? Especially the role of one.
def query_db(query, args=(), one=False):
cur = g.db.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
oneindicates whether or not to return only a single record. Ifoneis true then it returns the first (rv[0]) if there are records to be found (if rv), otherwise it returns all the records.