TouchDB Android dynamic views for query

363 Views Asked by At

I successfully got my Android app to sync with my iriscouch database. In this database I have about 100 documents, each representing one line of public transport with its corresponding stations, like:

   {
   "_id": "1",
   "_rev": "1-9658663cc48789829fb505ce2e0fd4ce",
   "name": "1",
   "stations": [
       {
           "_id": "Stefan-Fadinger-Platz",
           "name": "Stefan-Fadinger-Platz",
           "long": "16.35464100",
           "lat": "48.16771000"
       },
       {
           "_id": "Julius-Raab-Platz",
           "name": "Julius-Raab-Platz",
           "long": "16.38323500",
           "lat": "48.21135300"
       },
       {
           "_id": "Schwedenplatz U",
           "name": "Schwedenplatz U",
           "long": "16.37765200",
           "lat": "48.21178500"
       },
    ....
    }

How can I access this data from Android based on user selection, for example getting all stations for line 1? As far as I've read, I need to create a view for each query, but I don't think manually creating 100 views is performant. Is there a dynamic way?

1

There are 1 best solutions below

0
On

You can create views locally in TouchDB.

http://wiki.apache.org/couchdb/HTTP_view_API

They work the same as regular CouchDB views. You can provide parameters to the views that help you filter based on a user selection.