SlideShare una empresa de Scribd logo
1 de 26
COUCHDB

<- Watch the car   Oliver Kurowski, @okurow
Who am I
 Oliver Kurowski
 Degree in Computer Science Beuth School of applied Sciences Berlin


 First Computer: Apple II 1983
 Since 2003: kw automotive GmbH


 Write articles in Magazines
 2012: Book „CouchDB mit PHP“ (www.CouchDBmitPHP.de)


 Twitter: @okurow
 Mail: oliver@thinkcouchdb.com




                                      Oliver Kurowski, @okurow
TRANSFORMATIONS

                  Oliver Kurowski, @okurow
Transformation Functions
Documents are JSON objects
Results of views are also JSON objects

CouchDB can transfrom those JSON Objects on server side.

Shows:           Transformation for documents
Lists:           Transformation for views

Shows and lists are performed during request, results are not stored (like views).




                                         Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I




                Oliver Kurowski, @okurow
Shows:Transform Documents I
Data document (JSON):        Show function in a design doc:
 {                           “shows“: {
 “_id“: “1“,                  “toHTML“:“function(doc,req) {
 “make“: “Audi“,                 var outS=‘‘;
 “model“: “A3“,                  outS=‘<b>‘+doc.maker+‘ ‘+doc.model+‘</b><br>`;
 “year“: 2000,                   outS+=‘Year of Prod.: ‘+doc.year+‘<br>‘;
 “price“: 5.400                  outS+=‘Price: ‘+doc.price;
 }                              return outS; }“
                              }



Result of _show/toHTML/1 :
 Audi A3
 Year of Prod.: 2000
 Price: 5.400




                                   Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {
     var comments=0;
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data.“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {                                              Result of _show/headline/1 :
     var comments=0;                                                             CouchDB is great (2 comments)
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
     outS+= doc.body + ‘<br>`;
     if (doc.comments && doc.comments.length>0) {
       outS+= ‘<hr>Comments:<br>`;
       for (var curComment in doc.comments) {
        outS+=doc.comments[curComment].name+‘:<br>`;
        outS+=doc.comments[curComment].text+‘<br>`;
      }
   }
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
Shows:Transform Documents II
Data document (JSON):
{
    “_id“: “1“,
    “author“: “Oliver Kurowski“,
    “headline“: “CouchDB is great“,
    “body“: “CouchDb is a great database for schemeless data.“ ,
    “comments“: [ {“name“: “John“, “text“: “Yes, it really is“},
                    {“name“: “Jane“, “text“: “What about couchbase?“} ]
}

“shows“: {
  “headline“:“function(doc,req) {                                              Result of _show/headline/1 :
     var comments=0;                                                             CouchDB is great (2 comments)
     if (doc.comments) { comments=doc.comments.length };
     var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`;
     return outS; }“,
   “detail“:“function(doc,req) {
     var outS=‘<b>‘ + doc.headline + ‘</b><br>`;
                                                                               Result of _show/detail/1 :
     outS+= doc.body + ‘<br>`;                                                   CouchDB is great
     if (doc.comments && doc.comments.length>0) {                                CouchDb is a great database for schemeless data.
       outS+= ‘<hr>Comments:<br>`;
       for (var curComment in doc.comments) {                                    Comments:
        outS+=doc.comments[curComment].name+‘:<br>`;                             John:
        outS+=doc.comments[curComment].text+‘<br>`;                              Yes, it really is
      }                                                                          Jane:
   }                                                                             What about couchbase?
   return outS; }“
}
                                                                    Oliver Kurowski, @okurow
The Request Object
Shows and lists can access the Request Object containing:
(the most interesting)

Info:           Informations about the Database
Id:             called document ID (null, if not given)
requested
_path:          The request in parts (divided by /) as Array
headers:        Header, sent from the client
userCTX:        Information about the user, usefull for access limitations!
query:          Parameters of the call

The field req.query allows the use of own parameters that can be used in a
show/list function.
F.e: _show/toHTML/1?showPrice=true

handled in the show function:   if(req.query.showPrice==true) { ….}

                                         Oliver Kurowski, @okurow
Shows:Talking Parrots
Data documents :                      Design document :
{                                     {
    “_id“: “lora“,                         “_id“: “_design/parrot“,
    “name“: “Lora LoL“,                    “shows{
    “owner“: “Emily“,                       "introduce": "function(doc,req) {
    “color“: [“red“ , “#ff0000“ ] ,            var outS='';
    “languages“: [ “english“ ]                 if(doc) {     // doc with id in database found
}                                                outS+='<font color='+doc.color[1]+'>'+doc.name
                                                       +' belongs to '+doc.owner+'</font>';
{                                                if(req.query.say) {
    “_id“: “polly“,                                if(doc.languages) {
    “name“: “Polly Poll“,                            outS+=' and says: '+req.query.say;
    “owner“: “Ernest“,                             }else{
    “color“: [“blue“ , “#0000ff“ ],                  outS+='tweet';
    “languages“: [ “english“ ]                     }
}                                                }
                                               } else { // no doc found
                                                 if(req.path[5]!=undefined) { // no id given
{                                                  outS+='I dont know '+req.path[5];
    “_id“: “agnus“,                              }else{
    “name“: “Agnus Angry“,                          outS+='which parrot?';
    “owner“: “Ernest“,                           }
    “color“: [“grey“ , “#cococo“ ]            }
}                                             return outS; }“
                                          }
                                      }



                                                  Oliver Kurowski, @okurow
Shows: Talking Parrots
http://localhost:5984/parrots/_design/parrot/_show/introduce/
->which parrot?

http://localhost:5984/parrots/_design/parrot/_show/introduce/polly
->Polly Poll belongs to Ernest

http://localhost:5984/parrots/_design/parrot/_show/introduce/pollx
->I dont know pollx

http://localhost:5984/parrots/_design/parrot/_show/introduce/lora?say=Hello
->Lora Loll belongs to Emily and says: Hello

http://localhost:5984/parrots/_design/parrot/_show/introduce/agnus?say=Hello
->Agnus Angry belongs to Ernest tweet




                                       Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I




                Oliver Kurowski, @okurow
List:Transform view results I
Result of a View byPrice:                          A simple list function:
{"total_rows":5,"offset":0,                         “lists“: {
"rows":[                                              “asLI “:“function(head,req) {
{"id":"1","key":5.400,"value":“Audi-A3-                 start({'code':200,'headers':{'Content-Type':'text/html'}});
2000“}, {"id":"2","key":9.000,"value":“VW-Golf-         while(row=getRow()) {
2008“}, {"id":"3","key":12.000,"value":“VW-Polo-          send(‘<li>‘+row.value+‘ :‘ +row.key+‘</li>‘);
2010“}, {"id":"4","key":15.000,"value":“VW-Golf-        }
2009“}, {"id":"5","key":16.000,"value":“Audi-A4-      }“
2009“} ]}                                           }


result from _list/asLi/byPrice :
 •   Audi-A3-2000 : 5.400
 •   VW-Golf-2008 : 9.000
 •   VW-Polo-2010 : 12.000
 •   VW-Golf-2009 : 15.000
 •   Audi-A4-2009 : 16.000


- All arguments from a view can also be used in a list call
(startkey, endkey, skip, limit etc)

- Like Shows, you have access to the request Object with all ist possibilities.
                                                              Oliver Kurowski, @okurow
List:Transform view results II
Different headers can be sent
“lists“: {
  “asXML “:“function(head,req) {
    start({'code':200,'headers':{'Content-Type':'application/xml'}});
    var xmlS=‘<cars>‘;
    while(row=getRow()) {
      xmlS+=‘<car id=‘ + row.id + ‘>‘+row.value+‘ :‘ +row.key+‘</car>‘);
    }
    xmlS+=‘</cars>‘;
   return xmlS;
  }“
}


result from _list/asXML/byPrice :
<cars>
<car id=‘1‘>Audi-A3-2000 : 5.400</car>
<car id=‘2‘>VW-Golf-2008 : 9.000</car>
<car id=‘3‘ >VW-Polo-2010 : 12.000</car>
<car id=‘4‘>VW-Golf-2009 : 15.000</car>
<car id=‘5‘>Audi-A4-2009 : 16.000</car>
</cars>




                                                                       Oliver Kurowski, @okurow
http://apache.couchdb.org

Irc: #couchdb




Q (&A?)

                            Oliver Kurowski, @okurow

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

JSON-LD and MongoDB
JSON-LD and MongoDBJSON-LD and MongoDB
JSON-LD and MongoDB
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Pwning the Enterprise With PowerShell
Pwning the Enterprise With PowerShellPwning the Enterprise With PowerShell
Pwning the Enterprise With PowerShell
 
13 mongoose
13 mongoose13 mongoose
13 mongoose
 
Trees In The Database - Advanced data structures
Trees In The Database - Advanced data structuresTrees In The Database - Advanced data structures
Trees In The Database - Advanced data structures
 
Json Web Token - JWT
Json Web Token - JWTJson Web Token - JWT
Json Web Token - JWT
 
Alasql fast JavaScript in-memory SQL database
Alasql fast JavaScript in-memory SQL databaseAlasql fast JavaScript in-memory SQL database
Alasql fast JavaScript in-memory SQL database
 
CouchDB Vs MongoDB
CouchDB Vs MongoDBCouchDB Vs MongoDB
CouchDB Vs MongoDB
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
Advanced HTTP Caching
Advanced HTTP CachingAdvanced HTTP Caching
Advanced HTTP Caching
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
 
Api security
Api security Api security
Api security
 
Token, token... From SAML to OIDC
Token, token... From SAML to OIDCToken, token... From SAML to OIDC
Token, token... From SAML to OIDC
 
RedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ TwitterRedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ Twitter
 
Attacking REST API
Attacking REST APIAttacking REST API
Attacking REST API
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouse
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 

Destacado

Apresentação cassandra
Apresentação cassandraApresentação cassandra
Apresentação cassandra
Richiely Paiva
 

Destacado (8)

CouchDB Map/Reduce
CouchDB Map/ReduceCouchDB Map/Reduce
CouchDB Map/Reduce
 
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDBMongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
MongoDB Days Silicon Valley: Data Analysis and MapReduce with MongoDB
 
Apresentação cassandra
Apresentação cassandraApresentação cassandra
Apresentação cassandra
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance Benchmarking
 
CouchDB
CouchDBCouchDB
CouchDB
 
MapReduce in Simple Terms
MapReduce in Simple TermsMapReduce in Simple Terms
MapReduce in Simple Terms
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar a Couchdb List and Show Introduction

10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
 
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
MongoDB
 

Similar a Couchdb List and Show Introduction (20)

Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Introduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker NewsIntroduction to CouchDB - LA Hacker News
Introduction to CouchDB - LA Hacker News
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
 
Academy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data managementAcademy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data management
 
MongoDB
MongoDBMongoDB
MongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
 
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 

Último

FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
dlhescort
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
allensay1
 

Último (20)

Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 

Couchdb List and Show Introduction

  • 1. COUCHDB <- Watch the car Oliver Kurowski, @okurow
  • 2. Who am I  Oliver Kurowski  Degree in Computer Science Beuth School of applied Sciences Berlin  First Computer: Apple II 1983  Since 2003: kw automotive GmbH  Write articles in Magazines  2012: Book „CouchDB mit PHP“ (www.CouchDBmitPHP.de)  Twitter: @okurow  Mail: oliver@thinkcouchdb.com Oliver Kurowski, @okurow
  • 3. TRANSFORMATIONS Oliver Kurowski, @okurow
  • 4. Transformation Functions Documents are JSON objects Results of views are also JSON objects CouchDB can transfrom those JSON Objects on server side. Shows: Transformation for documents Lists: Transformation for views Shows and lists are performed during request, results are not stored (like views). Oliver Kurowski, @okurow
  • 5. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 6. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 7. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 8. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 9. Shows:Transform Documents I Oliver Kurowski, @okurow
  • 10. Shows:Transform Documents I Data document (JSON): Show function in a design doc: { “shows“: { “_id“: “1“, “toHTML“:“function(doc,req) { “make“: “Audi“, var outS=‘‘; “model“: “A3“, outS=‘<b>‘+doc.maker+‘ ‘+doc.model+‘</b><br>`; “year“: 2000, outS+=‘Year of Prod.: ‘+doc.year+‘<br>‘; “price“: 5.400 outS+=‘Price: ‘+doc.price; } return outS; }“ } Result of _show/toHTML/1 : Audi A3 Year of Prod.: 2000 Price: 5.400 Oliver Kurowski, @okurow
  • 11. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 12. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 13. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { var comments=0; if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 14. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data.“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { Result of _show/headline/1 : var comments=0; CouchDB is great (2 comments) if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; outS+= doc.body + ‘<br>`; if (doc.comments && doc.comments.length>0) { outS+= ‘<hr>Comments:<br>`; for (var curComment in doc.comments) { outS+=doc.comments[curComment].name+‘:<br>`; outS+=doc.comments[curComment].text+‘<br>`; } } return outS; }“ } Oliver Kurowski, @okurow
  • 15. Shows:Transform Documents II Data document (JSON): { “_id“: “1“, “author“: “Oliver Kurowski“, “headline“: “CouchDB is great“, “body“: “CouchDb is a great database for schemeless data.“ , “comments“: [ {“name“: “John“, “text“: “Yes, it really is“}, {“name“: “Jane“, “text“: “What about couchbase?“} ] } “shows“: { “headline“:“function(doc,req) { Result of _show/headline/1 : var comments=0; CouchDB is great (2 comments) if (doc.comments) { comments=doc.comments.length }; var outS=‘<b>‘ + doc.headline + ‘</b> (‘ + comments + ‘ comments)`; return outS; }“, “detail“:“function(doc,req) { var outS=‘<b>‘ + doc.headline + ‘</b><br>`; Result of _show/detail/1 : outS+= doc.body + ‘<br>`; CouchDB is great if (doc.comments && doc.comments.length>0) { CouchDb is a great database for schemeless data. outS+= ‘<hr>Comments:<br>`; for (var curComment in doc.comments) { Comments: outS+=doc.comments[curComment].name+‘:<br>`; John: outS+=doc.comments[curComment].text+‘<br>`; Yes, it really is } Jane: } What about couchbase? return outS; }“ } Oliver Kurowski, @okurow
  • 16. The Request Object Shows and lists can access the Request Object containing: (the most interesting) Info: Informations about the Database Id: called document ID (null, if not given) requested _path: The request in parts (divided by /) as Array headers: Header, sent from the client userCTX: Information about the user, usefull for access limitations! query: Parameters of the call The field req.query allows the use of own parameters that can be used in a show/list function. F.e: _show/toHTML/1?showPrice=true handled in the show function: if(req.query.showPrice==true) { ….} Oliver Kurowski, @okurow
  • 17. Shows:Talking Parrots Data documents : Design document : { { “_id“: “lora“, “_id“: “_design/parrot“, “name“: “Lora LoL“, “shows{ “owner“: “Emily“, "introduce": "function(doc,req) { “color“: [“red“ , “#ff0000“ ] , var outS=''; “languages“: [ “english“ ] if(doc) { // doc with id in database found } outS+='<font color='+doc.color[1]+'>'+doc.name +' belongs to '+doc.owner+'</font>'; { if(req.query.say) { “_id“: “polly“, if(doc.languages) { “name“: “Polly Poll“, outS+=' and says: '+req.query.say; “owner“: “Ernest“, }else{ “color“: [“blue“ , “#0000ff“ ], outS+='tweet'; “languages“: [ “english“ ] } } } } else { // no doc found if(req.path[5]!=undefined) { // no id given { outS+='I dont know '+req.path[5]; “_id“: “agnus“, }else{ “name“: “Agnus Angry“, outS+='which parrot?'; “owner“: “Ernest“, } “color“: [“grey“ , “#cococo“ ] } } return outS; }“ } } Oliver Kurowski, @okurow
  • 18. Shows: Talking Parrots http://localhost:5984/parrots/_design/parrot/_show/introduce/ ->which parrot? http://localhost:5984/parrots/_design/parrot/_show/introduce/polly ->Polly Poll belongs to Ernest http://localhost:5984/parrots/_design/parrot/_show/introduce/pollx ->I dont know pollx http://localhost:5984/parrots/_design/parrot/_show/introduce/lora?say=Hello ->Lora Loll belongs to Emily and says: Hello http://localhost:5984/parrots/_design/parrot/_show/introduce/agnus?say=Hello ->Agnus Angry belongs to Ernest tweet Oliver Kurowski, @okurow
  • 19. List:Transform view results I Oliver Kurowski, @okurow
  • 20. List:Transform view results I Oliver Kurowski, @okurow
  • 21. List:Transform view results I Oliver Kurowski, @okurow
  • 22. List:Transform view results I Oliver Kurowski, @okurow
  • 23. List:Transform view results I Oliver Kurowski, @okurow
  • 24. List:Transform view results I Result of a View byPrice: A simple list function: {"total_rows":5,"offset":0, “lists“: { "rows":[ “asLI “:“function(head,req) { {"id":"1","key":5.400,"value":“Audi-A3- start({'code':200,'headers':{'Content-Type':'text/html'}}); 2000“}, {"id":"2","key":9.000,"value":“VW-Golf- while(row=getRow()) { 2008“}, {"id":"3","key":12.000,"value":“VW-Polo- send(‘<li>‘+row.value+‘ :‘ +row.key+‘</li>‘); 2010“}, {"id":"4","key":15.000,"value":“VW-Golf- } 2009“}, {"id":"5","key":16.000,"value":“Audi-A4- }“ 2009“} ]} } result from _list/asLi/byPrice : • Audi-A3-2000 : 5.400 • VW-Golf-2008 : 9.000 • VW-Polo-2010 : 12.000 • VW-Golf-2009 : 15.000 • Audi-A4-2009 : 16.000 - All arguments from a view can also be used in a list call (startkey, endkey, skip, limit etc) - Like Shows, you have access to the request Object with all ist possibilities. Oliver Kurowski, @okurow
  • 25. List:Transform view results II Different headers can be sent “lists“: { “asXML “:“function(head,req) { start({'code':200,'headers':{'Content-Type':'application/xml'}}); var xmlS=‘<cars>‘; while(row=getRow()) { xmlS+=‘<car id=‘ + row.id + ‘>‘+row.value+‘ :‘ +row.key+‘</car>‘); } xmlS+=‘</cars>‘; return xmlS; }“ } result from _list/asXML/byPrice : <cars> <car id=‘1‘>Audi-A3-2000 : 5.400</car> <car id=‘2‘>VW-Golf-2008 : 9.000</car> <car id=‘3‘ >VW-Polo-2010 : 12.000</car> <car id=‘4‘>VW-Golf-2009 : 15.000</car> <car id=‘5‘>Audi-A4-2009 : 16.000</car> </cars> Oliver Kurowski, @okurow