Ruby on CouchDB - SimplyStored and RockingChair

Post on 15-Jan-2015

3.439 views 4 download

Tags:

description

Presentation by Jonathan Weiss about Ruby on CouchDB at Ruby User Group Berlin in Marc 2010. Present SimplyStored, a nice wrapper for Ruby object. RockingChair is an in-memory CouchDB for speeding up your tests.

Transcript of Ruby on CouchDB - SimplyStored and RockingChair

Jonathan Weiss, 04.03.2010Peritor GmbH

SimplyStored & RockingChairRuby on CouchDB

Thursday, March 4, 2010

Peritor

2

Cloud-Management und -Deployment made easy

http://scalarium.com

Thursday, March 4, 2010

Database Requirements

High availability

Easy replication and copy

Clustering

3

Thursday, March 4, 2010

4

CouchDBrelax

Thursday, March 4, 2010

Die Lösung

5

Built for the Web

Scales

Performant

Replication built-in

Flexible schema

Thursday, March 4, 2010

CouchDB

6

{ "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true}

Thursday, March 4, 2010

CouchDB

7

{ "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true}

Thursday, March 4, 2010

CouchDB

8

{ "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true}

Thursday, March 4, 2010

CouchDB - CRUD

Create and update:

PUT /starwars/BCCD12CBB

Read:

GET /starwars/BCCD12CBB

Delete:

DELETE /starwars/BCCD12CBB

9

Thursday, March 4, 2010

CouchDB

How do I query my data?

10

Thursday, March 4, 2010

CouchDB

11

Views!

Thursday, March 4, 2010

CouchDB

12

function(doc) { if (doc.headware) { for (var hat in doc.headware) { emit(hat, 1); } }}

Thursday, March 4, 2010

CouchDB

13

function(keys, values, rereduce) { return sum(values);}

Thursday, March 4, 2010

CouchDB

14

function(keys, values, rereduce) { return sum(values);}

Thursday, March 4, 2010

Queries

SQL

15

SELECT * FROM

`users` WHERE

`users`.id = 5

AND `status` = 1;

CouchDB JavaScript

function(doc) {

if (doc['ruby_class'] == 'User' && doc['status'] == 1) {

emit([doc.project_id, doc.created_at], null);

}

}

Thursday, March 4, 2010

Queries

ActiveRecord

16

SimplyStored

class Project

include SimplyStored::Couch

has_many :users

end

Project.first.users

class Project < ActiveRecord::Base

has_many :users

end

Project.first.users

Thursday, March 4, 2010

SimplyStored

http://github.com/peritor/simply_stored17

SimplyStored

Models

Associations

Validations

Callbacks

Dynamic finder

S3 attachments

Paranoid delete

Thursday, March 4, 2010

SimplyStored

Standing on the shoulders of giants:

- CouchPotato

- CouchRest

- RestClient

- HTTP

- CouchDB

http://github.com/peritor/simply_stored

Thursday, March 4, 2010

RockingChair

In-memory CouchDB

- Just a big Hash

- Speeds up your tests

- Tests can run in parallel

- Nice for debugging

http://github.com/jweiss/rocking_chair

Thursday, March 4, 2010

Now show me some Code!

Thursday, March 4, 2010

© Peritor GmbH - Alle Rechte Vorbehalten

Peritor GmbHBlücherstr. 22, Hof III Aufgang 610961 Berlin

Tel.: +49 (0)30 69 20 09 84 0Fax: +49 (0)30 69 20 09 84 9

Internet: www.peritor.comE-Mail: info@peritor.com

Thursday, March 4, 2010