Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Native Erlang list functions in CouchDB

I am trying to write Erlang list functions in CouchDB, however, I am not familiar with the data types returned, and how to manipulate them accordingly. I would like some one to show me how to translate the simple Javascript List function below into an Erlang list function. That would be a good point for me to start.

function(head, req) {
var row,resp={},data=[];
  if(head){
    resp["total_rows"] = head.total_rows;   
  }  
  while(row = getRow()) {
    data.push(row);
  }
  resp.rows = data;
  return JSON.stringify(resp);
}

Thanks, in advance.

like image 822
Fortu Avatar asked Jul 14 '12 14:07

Fortu


1 Answers

Have you looked at the couchdb Test Suite. You'll find the erlang views at utils/script/test/erlang_views.js

The code in the test suite often helps me when I'm stuck.

like image 118
thanos Avatar answered Oct 12 '22 22:10

thanos