SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

PLATAFORMA DE AFILIAÇÃO
PLATAFORMA DE AFILIAÇÃOPLATAFORMA DE AFILIAÇÃO
PLATAFORMA DE AFILIAÇÃO
Effiliation
 
Presentacion infografias 2
Presentacion infografias 2Presentacion infografias 2
Presentacion infografias 2
patiescobar
 

Andere mochten auch (20)

Apache Kafka, Un système distribué de messagerie hautement performant
Apache Kafka, Un système distribué de messagerie hautement performantApache Kafka, Un système distribué de messagerie hautement performant
Apache Kafka, Un système distribué de messagerie hautement performant
 
Redis keynote
Redis keynoteRedis keynote
Redis keynote
 
Apache Storm - Introduction au traitement temps-réel avec Storm
Apache Storm - Introduction au traitement temps-réel avec StormApache Storm - Introduction au traitement temps-réel avec Storm
Apache Storm - Introduction au traitement temps-réel avec Storm
 
Présentation CSR
Présentation CSRPrésentation CSR
Présentation CSR
 
PLATAFORMA DE AFILIAÇÃO
PLATAFORMA DE AFILIAÇÃOPLATAFORMA DE AFILIAÇÃO
PLATAFORMA DE AFILIAÇÃO
 
Fiche 2 Speed DéMo Web 2 0
Fiche 2 Speed DéMo Web 2 0Fiche 2 Speed DéMo Web 2 0
Fiche 2 Speed DéMo Web 2 0
 
Moonlight 43
Moonlight 43Moonlight 43
Moonlight 43
 
Nollet
NolletNollet
Nollet
 
Speed Demo 7 Minutes Pour Comprendre Le Web 2 0 Et Labus De La Liberté Dexpre...
Speed Demo 7 Minutes Pour Comprendre Le Web 2 0 Et Labus De La Liberté Dexpre...Speed Demo 7 Minutes Pour Comprendre Le Web 2 0 Et Labus De La Liberté Dexpre...
Speed Demo 7 Minutes Pour Comprendre Le Web 2 0 Et Labus De La Liberté Dexpre...
 
Génération de photos 2.0
Génération de photos 2.0Génération de photos 2.0
Génération de photos 2.0
 
Presentacion infografias 2
Presentacion infografias 2Presentacion infografias 2
Presentacion infografias 2
 
2011 01-27 Alicante Camon #ttontherocks: "Life imitates Twitter"
2011 01-27 Alicante Camon #ttontherocks: "Life imitates Twitter"2011 01-27 Alicante Camon #ttontherocks: "Life imitates Twitter"
2011 01-27 Alicante Camon #ttontherocks: "Life imitates Twitter"
 
E recrutement les outils web REALIZ
E recrutement les outils web REALIZE recrutement les outils web REALIZ
E recrutement les outils web REALIZ
 
Boutique ecologique
Boutique ecologiqueBoutique ecologique
Boutique ecologique
 
PréSentation Csr
PréSentation CsrPréSentation Csr
PréSentation Csr
 
2010 Dinamarca, he ahí tus Hijos (canto de ballenas)
2010 Dinamarca, he ahí tus Hijos (canto de ballenas)2010 Dinamarca, he ahí tus Hijos (canto de ballenas)
2010 Dinamarca, he ahí tus Hijos (canto de ballenas)
 
Francilbois RéSeaux 15 Sept 09
Francilbois RéSeaux 15 Sept 09Francilbois RéSeaux 15 Sept 09
Francilbois RéSeaux 15 Sept 09
 
Leucémie
LeucémieLeucémie
Leucémie
 
Le voyage du héros et la quête du BON projet
Le voyage du héros et la quête du BON projetLe voyage du héros et la quête du BON projet
Le voyage du héros et la quête du BON projet
 
YoolinkPro partenaire
YoolinkPro partenaireYoolinkPro partenaire
YoolinkPro partenaire
 

Ähnlich wie Relaxing With CouchDB

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
 

Ähnlich wie Relaxing With CouchDB (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...
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Relaxing With CouchDB