Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Sample design document

nisbus edited this page · 5 revisions
Clone this wiki locally

Create a new database and call it odata.
Create new document in futon and paste this into it.
Go to [http://localhost:5984/odata/design/odata/show/odata_service/design/odata](http://localhost:5984/odata/_design/odata/show/odataservice/design/odata) which will result in your first OData feed.

{
“_id”: “_design/odata”,
“language”: “javascript”,
“views”: {
“test”: {
“map”: “function(doc) {\n emit(doc,doc);\n}”,
“reduce”: “function(keys, values, rereduce) {\n \n}”
}
},
“lists”: {
“odata_convert”: “function(head, req) {\n var host = req.headers.Host;\n var path = req.path;\n var pathurl = \”\“;\n for(var b in path){\n\tif (b < path.length-1)\n\t pathurl = pathurl+’/’+path[b];\n }\n var baseUrl = \”http://\“+host+pathurl;\n send(’<?xml version=\”1.0\" encoding=\“iso-8859-1\” standalone=\“yes\”?><feed xml:base=\“‘baseUrl’\” xmlns:d=\“http://schemas.microsoft.com/ado/2007/08/dataservices\” xmlns:m=\“http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\” xmlns=\“http://www.w3.org/2005/Atom\”>’);\n send(‘

path[path.length-1]‘’);\n var row;\n while(row = getRow())\n {\n\tsend(‘’);\n\tsend(‘’row.key‘’);\n\tfor(var prop in row.value) {\n\t if(row.value.hasOwnProperty(prop))\t\t\n\t\tsend(‘<’+prop+’>’+row.value[prop]‘</’prop+’>’);\n\t};\n\tsend(‘’);\n\tsend(‘’);\n\tfor(var prop in row.value){\n\t if(row.value.hasOwnProperty(prop)){\t\t\t \n\t\tif(typeof(row.value[prop]) === \“number\”)\t\t \n\t\t{\n\t\t send(‘<d:’+prop+’ m:type=\“Edm.Double\”>’+row.value[prop]‘</d:’prop+’>’);\t\t \n\t\t}\n\t\telse if (!isNaN(Date.parse(row.value[prop])))\n\t\t{\n\t\t var d = Date.parse(row.value[prop]);\n\t\t var date = new Date(d).toUTCString();\n\t\t send(‘<d:’+prop+’ m:type=\“Edm.DateTime\”>’+date+’</d:’+prop+’>’); \n\t\t}\n\t\telse\n\t\t{\n\t\t send(‘<d:’+prop+’>’+row.value[prop]‘</d:’prop+’>’); \n\t\t}\n\t }\n\t}\n\tsend(‘’);\n\tsend(‘’);\n\tsend(‘’);\n }\n send(‘’); \n}"
},
“shows”: {
“odata_service”: “function(doc, req) { \n var host = req.headers.Host;\n var path = req.path;\n var pathurl = \”\“;\n for(var b in path){\n\tif (b < 3)\n\t pathurl = pathurl+’/’+path[b];\n }\n var baseUrl = \”http://\“+host+pathurl+\”/list/odataconvert/\“;\n\n var returnBody = ’”http://www.w3.org/2005/Atom\" xmlns:app=\“http://www.w3.org/2007/app\” xmlns=\“http://www.w3.org/2007/app\” xml:base=\\\“‘baseUrl’\\\”>‘path[path.length-1]’‘;\n if(doc){\n\tif (doc.views){\n\t for(var prop in doc.views) {\n\t\tif(doc.views.hasOwnProperty(prop)){\n\t\t returnBody = returnBody+’‘;\n\t\t returnBody = returnBody+’‘\“\\\”\"prop+\“\\\”\"+’‘;\n\t\t}\n\t }\n\t}\n\n }\n returnBody = returnBody+’’;\n return {\n\theaders : {\n\t \“Content-Type\” : \“text/xml\”\n\t},\n\tbody : returnBody};\n}"
}
}

There is a publicly available test document here

and the sample output

Something went wrong with that request. Please try again.