def selectone(db, table, **kw):
    """Selects a single element from the database if exists, or None"""
    kw['limit'] = 1
    r = [r for r in db.select(table, **kw)]
    if not r:
        return None
    return r[0]