This repository was archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
TouchDB Ektorp Views
mschoch edited this page May 15, 2012
·
8 revisions
It may not be obvious at first how you can use TouchDB Views (implemented in Java) with the standard Ektorp API. Below is small example of how it can be done.
-
First set up your TDServer as described in the page Getting Started
-
Next, define a view with design document name and view name you want.
String dDocName = "ddoc";
String viewName = "people";
TDView view = db.getViewNamed(String.format("%s/%s", dDocName, viewName));
- Next, add the map/reduce implementation blocks for this view.
view.setMapReduceBlocks(new TDViewMapBlock() {
@Override
public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {
String type = (String)document.get("type");
if("person".equals(type)) {
emitter.emit(null, document.get("_id"));
}
}
}, null, "1.0");
- Now you can query this view using the normal Ektorp API:
ViewQuery viewQuery = new ViewQuery().designDocId(dDocName).viewName(viewName);
ViewResult viewResult = couchDbConnector.queryView(viewQuery);
- If you follow these steps, custom CouchDbDocument subclasses and the repository support classes should also work.