Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Compare: Sample design document

Showing with 23 additions and 0 deletions.
  1. +23 −0 Sample-design-document.textile
View
23 Sample-design-document.textile
@@ -0,0 +1,23 @@
+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/odata_service/_design/odata) which will result in your first OData feed.
+
+```javascript
+{
+ "_id": "_design/odata",
+ "_rev": "5-7be958d6e9ae68f6d1b344ed4507be08",
+ "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('<title type=\"text\">'+path[path.length-1]+'</title>');\n var row;\n while(row = getRow())\n {\n\tsend('<entry>');\n\tsend('<id>'+row.key+'</id>');\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('<content type=\"application/xml\">');\n\tsend('<m:properties>');\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('</m:properties>');\n\tsend('</content>');\n\tsend('</entry>');\n }\n send('</feed>'); \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/odata_convert/\";\n\n var returnBody = '<service xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:app=\"http://www.w3.org/2007/app\" xmlns=\"http://www.w3.org/2007/app\" xml:base=\\\"'+baseUrl+'\\\"><workspace><atom:title>'+path[path.length-1]+'</atom:title>';\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+'<collection href=\\\"'+prop+'\\\">';\n\t\t returnBody = returnBody+'<atom:title>'+\"\\\"\"+prop+\"\\\"\"+'</atom:title></collection>';\n\t\t}\n\t }\n\t}\n\n }\n returnBody = returnBody+'</workspace></service>';\n return {\n\theaders : {\n\t \"Content-Type\" : \"text/xml\"\n\t},\n\tbody : returnBody};\n}"
+ }
+}
+```
Something went wrong with that request. Please try again.