10

Click here to load reader

CouchDB: A NoSQL database

Embed Size (px)

Citation preview

Page 1: CouchDB: A NoSQL database

Couch DB a NoSql databaseFederico Ramallo

Page 2: CouchDB: A NoSQL database

About meRails developer

Ruby mentor

Certified Scrum Master

Motorcyclist

Co-founder of Tangosource.

Page 3: CouchDB: A NoSQL database

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

Page 4: CouchDB: A NoSQL database

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

Page 5: CouchDB: A NoSQL database

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

Page 6: CouchDB: A NoSQL database

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)

Page 7: CouchDB: A NoSQL database

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

Page 8: CouchDB: A NoSQL database

Use JS frameworks for thefrontend!

Examples:

Backbone.js

Sproutcore

Capuccino

Titanum

Ext.js

The new model is: Browser - Couchdb - Ruby

Page 9: CouchDB: A NoSQL database

What about ruby?Use it as backend to run background tasks like:

Sending emails

Authentication

Page 10: CouchDB: A NoSQL database

ThanksThanks! [email protected]