Jacek Chmielewski
Jacek Chmielewski

Reputation: 1793

Horizon client library: is group-by doable?

I'm implementing simple webapp using horizon backend and reactjs frontend. I need to get a collection (table) grouped by specific field. Then I need to order each reduction by another field and limit records in each reduction to 1. Reql query that returns what I need:

r.db('reporter').table('reports')
  .group('project_name')
  .orderBy(r.desc('time_created'))
  .limit(1)

I did not find relevant methods (group) in documentation (http://horizon.io/api/collection/). I'm aware that I may have misunderstood role of Collection object - from my current understanding it is a direct proxy to rethinkdb table and all operations available on table should be available on collection - am I wrong? Is there intermediate layer that I need to implement to get this behaviour?

Upvotes: 2

Views: 88

Answers (2)

jirikolarik
jirikolarik

Reputation: 1267

You can do it on front-end using rxjs groupBy, because horizon.io returns rxjs observables.

https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/groupby.md

Upvotes: 0

mlucy
mlucy

Reputation: 5289

The Horizon API is much more limited than the RethinkDB API. The only methods defined on collections are the ones listed at http://horizon.io/api/collection/ . If you need more complicated behavior, you can embed Horizon in a NodeJS app and define a custom endpoint that issues any ReQL query you want: http://horizon.io/docs/embed/ .

Upvotes: 1

Related Questions