class to query levels sorted by any key, with optional cursor, limit and reverse