SlideShare a Scribd company logo
1 of 49
Download to read offline
relaxing with couchdb
          will leinweber
       will@bitfission.com




                   acts_as_conference 2009
                                             1
2
this talk: why & how




                       3
what is couchdb?




                   4
document database
no schema




                    5
erlang
concurrent
scalable




             6
built for the web
restful
json




                    7
json
{ quot;titlequot;: quot;A Brief History of Slinkiesquot;,
  quot;chaptersquot;: [
  { quot;titlequot;: quot;Sorta like a springquot;,
     quot;textquot;: quot;Round and metal...quot; },
  { quot;titlequot;: quot;Stairsquot;,
     quot;textquot;: quot;They can go down, but not upquot; }],
  quot;_idquot;: quot;4b859...quot;,
  quot;_revquot;: quot;3280991488quot;
}




                                                  8
multi version concurrency control
no locking
         locking   mvcc
 write                    reads




                                    9
add only
never in a bad state




                       10
incremental replication
eventual consistency
winning documents




                          11
couchdb only apps
javascript + html




                    12
multiple databases
  for a single app




                     13
integrate with full text search




                                  14
file attachment




                  15
views
(not queries)




                16
stored as design documents




                             17
view server
javascript (spidermonkey)
ruby and python too




                            18
map
reduce (optional)




                    19
goes through each document
very slow




                             20
map step
emits keys value pairs




                         21
persisted index
keeps track of changes




                         22
keep your views fresh




                        23
http benefits




                24
cacheable
load balancers




                 25
easy interface
understand and implement




                           26
getting started




                  27
install couch from svn head
get erlang, spidermonkey, icu




                                28
gem install jchris-couchrest
lightweight api wrapper




                               29
db = CouchRest.database!(quot;http://localhost:5984/booksquot;)
response = db.save(:title => quot;recipesquot;) # =>
            {quot;revquot;=>quot;2351730874quot;, quot;idquot;=>quot;07cb62...quot;,
            quot;okquot;=>true}

doc = db.get response[quot;idquot;] # => {quot;titlequot;=>quot;recipesquot;,
            quot;_idquot;=>quot;07cb62...quot;, quot;_revquot;=>quot;2351730874quot;}




                                                          30
$ curl http://localhost:5984/books/07cb6232593b61dd022d1c05b1c7deac
{quot;_idquot;:quot;07cb6232593b61dd022d1c05b1c7deacquot;,quot;_revquot;:quot;2351730874quot;,
quot;titlequot;:quot;recipesquot;}




                                                                  31
doc[quot;titlequot;] = quot;cook bookquot;
doc.save # => true
db.get response[quot;idquot;] # => {quot;titlequot;=>quot;cook bookquot;,
      quot;_idquot;=>quot;07cb623...quot;, quot;_revquot;=>quot;3767210759quot;}

doc.destroy # => true
db.get response[quot;idquot;] # => RestClient::ResourceNotFound




                                                          32
33
simple view
function(doc) {
  if (doc.type == quot;bookquot;) {
    emit(null, doc);
  }
                         db.view(quot;books/allquot;)
}




                                                34
view with keys
function(doc) {
  emit(doc.type, doc);
}
                db.view(quot;books/allquot;    )['rows'].size   # => 10
                db.view(quot;all/by_typequot; )['rows'].size    # => 30
                db.view(quot;all/by_typequot;,
                        :key => quot;bookquot;)['rows'].size    # => 10




                                                                  35
map reduce
// map                     // reduce
function(doc) {            function(keys,values) {
  emit(doc.type, doc);        return(values.length);
                           }
}


 db.view(quot;count/by_typequot;) # => {quot;rowsquot;=>
                            {quot;valuequot;=>3, quot;keyquot;=>nil}]}
 db.view(quot;count/by_typequot;, :group => true) # =>
            {quot;rowsquot;=>[{quot;valuequot;=>10, quot;keyquot;=>quot;articlequot;},
                      {quot;valuequot;=>10, quot;keyquot;=>quot;bookquot;},
                      {quot;valuequot;=>10, quot;keyquot;=>quot;userquot;}]}
 db.view(quot;count/by_typequot;, :key => quot;bookquot;) # =>
                {quot;rowsquot;=>[{quot;valuequot;=>10, quot;keyquot;=>nil}]}




                                                         36
versioning
{
    quot;titlequot;: quot;Slinkies!quot;,
    quot;versionquot;: 4,
    quot;master_idquot;: quot;3de0c...quot;,
    quot;_idquot;: quot;af322...quot;,
    quot;chaptersquot;: [...]
}




                               37
versioning
// map                   // reduce
function(doc) {          function(keys, values) {
  emit( doc.master_id,     var max = 0;
        doc );
}                            for(i in values) {
                               if( values[i].version >
                                   values[max].version ) {
                                   max = i;
                               }
                             }
                             return(values[max]);
                         }




                                                             38
view collation
                          {    quot;_idquot;:   quot;def345quot;,
{    quot;_idquot;:   quot;abc012quot;,
                              quot;_revquot;:   quot;2387quot;,
    quot;_revquot;:   quot;2387quot;,
                              quot;typequot;:   quot;commentquot;,
    quot;typequot;:   quot;postquot;,
                              quot;dataquot;:   quot;...quot; }
    quot;dataquot;:   quot;...quot; }

                          {    quot;_idquot;:   quot;r2d2c3quot;,
                              quot;_revquot;:   quot;2653quot;,
                              quot;typequot;:   quot;commentquot;,
                              quot;dataquot;:   quot;...quot; }




                                                     39
view collation
   function(doc) {
     if (doc.type == quot;postquot;) {
       emit([doc._id, 0], doc);
     } else if (doc.type == quot;commentquot;) {
       emit([doc.post, 1], doc);
     }
   }




                                           40
CouchRest::Model
being removed from couchrest
      class Book < CouchRest::Model
        key_accessor :title, :text, :author
        cast :author, :as => quot;Userquot;
        timestamps!
      end

  # config/environment.rb
  CouchRest::Model.default_database =
      CouchRest.database!(quot;appname-#{ENV['RAILS_ENV']}quot;)




                                                           41
others
 langalex-couch_potato
 active couch




                         42
downsides




            43
moving target




                44
arbitrary queries are slow




                             45
lack of supporting tools




                           46
loss of intuition




                    47
what you should do next




                          48
thanks!




          49

More Related Content

What's hot

Going Schema-Free
Going Schema-FreeGoing Schema-Free
Going Schema-Free
spraints
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
Justin Deoliveira
 
Js testing
Js testingJs testing
Js testing
MaslowB
 

What's hot (20)

Going Schema-Free
Going Schema-FreeGoing Schema-Free
Going Schema-Free
 
c++ program for Canteen management
c++ program for Canteen managementc++ program for Canteen management
c++ program for Canteen management
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
 
The State of GeoServer
The State of GeoServerThe State of GeoServer
The State of GeoServer
 
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
 
Building fast interpreters in Rust
Building fast interpreters in RustBuilding fast interpreters in Rust
Building fast interpreters in Rust
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 AttributesEmpty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
 
Js testing
Js testingJs testing
Js testing
 
Supermarket
SupermarketSupermarket
Supermarket
 
GraphQL vs Traditional Rest API
GraphQL vs Traditional Rest APIGraphQL vs Traditional Rest API
GraphQL vs Traditional Rest API
 
Out with Regex, In with Tokens
Out with Regex, In with TokensOut with Regex, In with Tokens
Out with Regex, In with Tokens
 
Automatically Spotting Cross-language Relations
Automatically Spotting Cross-language RelationsAutomatically Spotting Cross-language Relations
Automatically Spotting Cross-language Relations
 
COLLADA & WebGL
COLLADA & WebGLCOLLADA & WebGL
COLLADA & WebGL
 
Java script
Java scriptJava script
Java script
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
More than `po`: Debugging in lldb
More than `po`: Debugging in lldbMore than `po`: Debugging in lldb
More than `po`: Debugging in lldb
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 

Similar to development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasconference 2009, Internet & Technology, Presentations & Spreadsheets

Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
MongoSF
 

Similar to development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasconference 2009, Internet & Technology, Presentations & Spreadsheets (20)

Couch Db.0.9.0.Pub
Couch Db.0.9.0.PubCouch Db.0.9.0.Pub
Couch Db.0.9.0.Pub
 
MongoDB
MongoDBMongoDB
MongoDB
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertext
 
Capistrano2
Capistrano2Capistrano2
Capistrano2
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
Little Big Ruby
Little Big RubyLittle Big Ruby
Little Big Ruby
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 
Couchdb
CouchdbCouchdb
Couchdb
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Better Data Management using TaffyDB
Better Data Management using TaffyDBBetter Data Management using TaffyDB
Better Data Management using TaffyDB
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
Acts As Recommendable
Acts As RecommendableActs As Recommendable
Acts As Recommendable
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Ruby sittin' on the Couch
Ruby sittin' on the CouchRuby sittin' on the Couch
Ruby sittin' on the Couch
 
Umleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appUmleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB app
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasconference 2009, Internet & Technology, Presentations & Spreadsheets