Open kclay opened 10 years ago
Rethinkdb allows us to have different response return back from the .group method depending on what is passed.
val json = """[ | {"id": 2, "player": "Bob", "points": 15, "type": "ranked"}, | {"id": 5, "player": "Alice", "points": 7, "type": "free"}, | {"id": 11, "player": "Bob", "points": 10, "type": "free"}, | {"id": 12, "player": "Alice", "points": 2, "type": "free"} |]""".stripMargin val seq = Expr(Reflector.fromJson[Seq[Map[String, Any]]](json)) seq.group("player").run /** {"$reql_type$":"GROUPED_DATA","data":[["Alice",[{"id":5,"player":"Alice","points":7,"type":"free"},{"id":12,"player":"Alice","points":2,"type":"free"}]],["Bob",[{"id":2,"player":"Bob","points":15,"type":"ranked"},{"id":11,"player":"Bob","points":10,"type":"free"}]]]} **/ seq.group({ v:Var=> v.pluck("player") }.as[String]).run /** {"$reql_type$":"GROUPED_DATA","data":[[{"player":"Alice"},[{"id":5,"player":"Alice","points":7,"type":"free"},{"id":12,"player":"Alice","points":2,"type":"free"}]],[{"player":"Bob"},[{"id":2,"player":"Bob","points":15,"type":"ranked"},{"id":11,"player":"Bob","points":10,"type":"free"}]]]} **/ seq.group({ v:Var=> v.pluck("player") }.as[String],"id").run /** {"$reql_type$":"GROUPED_DATA","data":[[[{"player":"Alice"},5],[{"id":5,"player":"Alice","points":7,"type":"free"}]],[[{"player":"Alice"},12],[{"id":12,"player":"Alice","points":2,"type":"free"}]],[[{"player":"Bob"},2],[{"id":2,"player":"Bob","points":15,"type":"ranked"}]],[[{"player":"Bob"},11],[{"id":11,"player":"Bob","points":10,"type":"free"}]]]} **/
Rethinkdb allows us to have different response return back from the .group method depending on what is passed.