Couchdb w Ruby'm
Upcoming SlideShare
Loading in...5
×
 

Couchdb w Ruby'm

on

  • 1,203 views

 

Statistics

Views

Total Views
1,203
Views on SlideShare
1,199
Embed Views
4

Actions

Likes
0
Downloads
4
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Couchdb w Ruby'm Couchdb w Ruby'm Presentation Transcript

  • CouchDB w ruby'm, na przykładach
  • Kim jestem? 20.04.2010 Stanisław Wasiutyński 2
  • Plan prezentacji CouchDB Ruby ● Nierelacyjna baza danych ● Couchrest ● RESTful JSON API ● Couch_foo ● Widoki (MapReduce) ● Couch_potato ● Replikacje ● Reverse proxy teoria praktyka 20.04.2010 Stanisław Wasiutyński 3
  • 20.04.2010 Stanisław Wasiutyński 4 Źródło: http://blog.nahurst.com/visual-guide-to-nosql-systems
  • tu jestem 20.04.2010 Stanisław Wasiutyński 5 Źródło: http://blog.nahurst.com/visual-guide-to-nosql-systems
  • Document-Oriented ● Wszystkie dane są przechowywane w formie dokumentów o dowolnym rozmiarze. ● Każdy dokument ma unikalną nazwę, oraz posiada dowolną liczbę pól o unikalnej nazwie. ● Każdemu polu (kluczowi) odpowiada wartość dowolnego typu (np. String, Integer, Array, Hash). ● Na dokumentach wykonywane są operacje CRUD (Create, Read, Update, Delete) tylko na całym dokumencie, nigdy na jego fragmencie. 20.04.2010 Stanisław Wasiutyński 6
  • RESTful JSON API { "_id": "fb288af72d22797f5cf68a73a7a5cb89", "_rev": "12-8f531b2a273d35ecd4af58e930525e8c", "couchrest-type": "Line", "no": 117, "begin_date": "2009/10/03", "timetables": [ { "data": {"pon-pt": [...], "sob": [...]}, "stop_id": "acf81f2770a21481bf0e784b7b506d38" }, ... ], "updated_at": "2010/03/08 21:08:50 +0000", "created_at": "2010/01/22 21:50:19 +0000" } 20.04.2010 Stanisław Wasiutyński 7
  • RESTful JSON API Stwórz: POST /db/<id> Czytaj: GET /db/<id> Aktualizuj: PUT /db/<id> Usuń: DELETE /db/<id> 20.04.2010 Stanisław Wasiutyński 8
  • 20.04.2010 Stanisław Wasiutyński 9
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 10
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 11
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 12
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 13
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 14
  • RESTful JSON API [~] ➔ curl http://localhost:5984/ [info] [<0.95.0>] 127.0.0.1 - - 'GET' / 200 {"couchdb":"Welcome","version":"0.11.0"} [~] ➔ curl -X PUT http://localhost:5984/krug [info] [<0.124.0>] 127.0.0.1 - - 'PUT' /krug 201 {"ok":true} [~] ➔ curl -X POST http://localhost:5984/krug -d '{"Temat": "Witaj świecie!"}' [info] [<0.216.0>] 127.0.0.1 - - 'POST' /krug 201 {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a"} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"Temat": "Witaj okrutny świecie!"}' [info] [<0.668.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 409 {"error":"conflict","reason":"Document update conflict."} [~] ➔ curl -X PUT http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be > -d '{"_rev":"1-4777d27f9e980ed1ce8cf94c0bc1d27a", "Temat": "Witaj okrutny świecie!"}' {"ok":true,"id":"8cb7299cc68d35a2ca4a0c18070009be","rev":"2-e51a077b62b9bfbc8faac8aff60733b4"} [info] [<0.774.0>] 127.0.0.1 - - 'PUT' /krug/8cb7299cc68d35a2ca4a0c18070009be 201 [~] ➔ curl http://localhost:5984/krug/8cb7299cc68d35a2ca4a0c18070009be [info] [<0.1264.0>] 127.0.0.1 - - 'GET' /krug/8cb7299cc68d35a2ca4a0c18070009be 200 {"_id":"8cb7299cc68d35a2ca4a0c18070009be","_rev":"2-e51a077b62b9bfbc8faac8aff60733b4", "Temat":"Witaj okrutny u015bwiecie!"} [~] ➔ 20.04.2010 Stanisław Wasiutyński 15
  • Coś więcej niż wymyślny serwer plików. 20.04.2010 Stanisław Wasiutyński 16 http://www.flickr.com/photos/santos/1704875109/
  • Widoki ● Są przechowywane jako dokumenty, ● definiują dowolne funkcje map i reduce, ● służą do budowy wydajnych indeksów, ● pozwalają na niezależne przetwarzanie pojedynczych dokumentów i zwrócenie ich w pożądanym formacie, ● generowane równolegle, inkrementalnie i na żądanie, ● brak dynamicznych zapytań („close to the metal”), ● rozbudowane API. 20.04.2010 Stanisław Wasiutyński 17
  • Map Reduce GET /_design/comments/_view/cenzor?limit=11&reduce=false GET /_design/comments/_view/cenzor?limit=11&reduce=false& startkey=[<id>, <rok>, <miesiąc>, <dzień>]& endkey=[<id>, <rok>, <miesiąc>, <dzień>+3] GET /_design/comments/_view/cenzor?limit=11&group=true&group_level=3 GET /_design/comments/_view/cenzor?group=true&group_level=1&key=[<id>] 20.04.2010 Stanisław Wasiutyński 18
  • Replikacje ● Dwustronne, inkrementalne, ● replikacja podzbioru (przez filtry), ● rozwiązywanie konfliktów. korzyści ● Łatwe skalowanie wszerz, ● praca off-line. curl -X POST http://localhost:5984/_replicate -d {"source": "http://couch.db/remote", "target": "local"} 20.04.2010 Stanisław Wasiutyński 19
  • Replikacje 20.04.2010 Stanisław Wasiutyński 20 http://www.slideshare.net/mlmilleratmit/20100310-miller-sts
  • Ruby 20.04.2010 Stanisław Wasiutyński 21
  • Couchrest Couchrest 20.04.2010 Stanisław Wasiutyński 22
  • 20.04.2010 Stanisław Wasiutyński 23
  • Couch_foo 20.04.2010 Stanisław Wasiutyński 24
  • 20.04.2010 Stanisław Wasiutyński 25
  • Couch_potato 20.04.2010 Stanisław Wasiutyński 26
  • 20.04.2010 Stanisław Wasiutyński 27
  • em_proxy 20.04.2010 Stanisław Wasiutyński 28
  • 20.04.2010 Stanisław Wasiutyński 29
  • O czym nie mówiłem? ● Couchdb-Lucene – pełno-tekstowa wyszukiwarka dokumentów CouchDB, ● Couchdb-Lounge – proxy framework do partycjonowania CouchDB, ● CouchApps - samowystarczalne aplikacje CouchDB, ● bezpieczeństwo, ● binarne załączniki, ● walidacja dokumentów, ● BrowserCouch – CouchDB w przeglądarce. 20.04.2010 Stanisław Wasiutyński 30
  • Więcej o CouchDB na: ● http://couchdb.apache.org/ ● http://www.couch.io/ ● http://wiki.apache.org/couchdb/ ● http://books.couchdb.org/relax/ Oraz: ● http://stackoverflow.com/questions/tagged/couchdb ● http://www.reddit.com/search?q=couchdb 20.04.2010 Stanisław Wasiutyński 31
  • Dziękuję za uwagę. 20.04.2010 Stanisław Wasiutyński 32
  • Fork me: github.com/Stanley 20.04.2010 Stanisław Wasiutyński 33
  • Pytania? 20.04.2010 Stanisław Wasiutyński 34