Click here to load reader
Upload
rubyc-slides
View
1.309
Download
2
Embed Size (px)
Citation preview
Couch DB a NoSql databaseFederico Ramallo
About meRails 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/20request / 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 thathas 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 theyare.
I recommend couchrest because:
Is light
Is simillar to couch api
Couchrest ExampleCouchRest example using couchrest gem
require 'couchrest'
# Connect / create to the databaseserver = CouchRest.new("http://localhost:5984")db = server.create_db('my-db')
# Save documentsdb.save({'_id' => 'my-doc', 'will-exist' => 'here'})
# Get documentsdoc = db.get('my-doc'); doc['will-exist'] #=> 'here'
db.delete(doc)
How you could use it for bigapplications
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 thefrontend!
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
ThanksThanks! [email protected]