KEMBAR78
CouchDB: A NoSQL database | PDF
Couch DB a NoSql database
Federico Ramallo
About me
 Rails developer
 Ruby mentor
 Certified Scrum Master
 Motorcyclist




 Co-founder of Tangosource.
What is couchdb?
  JSON document server
  Accesible ONLY via HTTP
  RESTful JSON API
  is schema free
  Distributed, supports replication
  Scales a LOT
  Can take 2k request / second VS Ruby that can take 15/20
  request / second
How to query the database?
  What is a View?
  Is a pre calculated query on the database using map reduce
  Use javascript functions
  example of a map function

function(doc) {
  if(doc.date && doc.title) {
    emit(doc.date, doc.title);
  }
}


  This is a map function that allows you to filter by all records that
  has a title field. a.k.a filter by record type
  Is schema free, so could use a type field or NOT
How to use it with ruby?
  There are several rubygems
  couchrest https://rubygems.org/gems/couchrest
  couch_potato https://github.com/langalex/couch_potato
  couch_foo https://github.com/georgepalmer/couch_foo
  couchDB-Ruby http://rubyforge.org/projects/couchdb/
  The more they try to abstract from couch, the less powerfull they
  are.
  I recommend couchrest because:
  Is light
  Is simillar to couch api
Couchrest Example
CouchRest example using couchrest gem

 require 'couchrest'

 # Connect / create to the database
 server = CouchRest.new("http://localhost:5984")
 db = server.create_db('my-db')

 # Save documents
 db.save({'_id' => 'my-doc', 'will-exist' => 'here'})

 # Get documents
 doc = db.get('my-doc'); doc['will-exist'] #=> 'here'

 db.delete(doc)
How you could use it for big
applications
  Move couchdb as a web server
  Use Ruby for everything else hanging for the _changes feed
  Use js to interact.
  Why?
  Because is super fast
  Because the browser can have the info locally
Use JS frameworks for the
frontend!
  Examples:
  Backbone.js
  Sproutcore
  Capuccino
  Titanum
  Ext.js
  The new model is: Browser - Couchdb - Ruby
What about ruby?
  Use it as backend to run background tasks like:
  Sending emails
  Authentication
Thanks
Thanks! framallo@gmail.com

CouchDB: A NoSQL database

  • 1.
    Couch DB aNoSql database Federico Ramallo
  • 2.
    About me Railsdeveloper Ruby mentor Certified Scrum Master Motorcyclist Co-founder of Tangosource.
  • 3.
    What is couchdb? JSON document server Accesible ONLY via HTTP RESTful JSON API is schema free Distributed, supports replication Scales a LOT Can take 2k request / second VS Ruby that can take 15/20 request / second
  • 4.
    How to querythe database? What is a View? Is a pre calculated query on the database using map reduce Use javascript functions example of a map function function(doc) { if(doc.date && doc.title) { emit(doc.date, doc.title); } } This is a map function that allows you to filter by all records that has a title field. a.k.a filter by record type Is schema free, so could use a type field or NOT
  • 5.
    How to useit with ruby? There are several rubygems couchrest https://rubygems.org/gems/couchrest couch_potato https://github.com/langalex/couch_potato couch_foo https://github.com/georgepalmer/couch_foo couchDB-Ruby http://rubyforge.org/projects/couchdb/ The more they try to abstract from couch, the less powerfull they are. I recommend couchrest because: Is light Is simillar to couch api
  • 6.
    Couchrest Example CouchRest exampleusing couchrest gem require 'couchrest' # Connect / create to the database server = CouchRest.new("http://localhost:5984") db = server.create_db('my-db') # Save documents db.save({'_id' => 'my-doc', 'will-exist' => 'here'}) # Get documents doc = db.get('my-doc'); doc['will-exist'] #=> 'here' db.delete(doc)
  • 7.
    How you coulduse it for big applications Move couchdb as a web server Use Ruby for everything else hanging for the _changes feed Use js to interact. Why? Because is super fast Because the browser can have the info locally
  • 8.
    Use JS frameworksfor the frontend! Examples: Backbone.js Sproutcore Capuccino Titanum Ext.js The new model is: Browser - Couchdb - Ruby
  • 9.
    What about ruby? Use it as backend to run background tasks like: Sending emails Authentication
  • 10.