58
Apache CouchDB 0.9.0 リリース記念資料 id:yssk22 http://d.hatena.ne.jp/yssk22

Couch Db.0.9.0.Pub

Embed Size (px)

DESCRIPTION

CouchDB 0.9.0 Overview in Japanese

Citation preview

Page 1: Couch Db.0.9.0.Pub

Apache CouchDB 0.9.0リリース記念資料id:yssk22

http://d.hatena.ne.jp/yssk22

Page 2: Couch Db.0.9.0.Pub

CouchDB復習

Page 3: Couch Db.0.9.0.Pub

1. ドキュメント指向

Page 4: Couch Db.0.9.0.Pub

JSONのデータをためる入れ物

Page 5: Couch Db.0.9.0.Pub

{"_id" : "文書1""_rev" : "リビジョン""title" : "CouchDBについて""Content" : "いろいろ"}

Page 6: Couch Db.0.9.0.Pub

2. Web+DB

Page 7: Couch Db.0.9.0.Pub

REST

Page 8: Couch Db.0.9.0.Pub

HTTP

Page 9: Couch Db.0.9.0.Pub

3. 非リレーショナル

Page 10: Couch Db.0.9.0.Pub

MapReduce:= SQLめんどう

Page 11: Couch Db.0.9.0.Pub

HTTP map

reduce

HTTP Request

HTTP Response

Page 12: Couch Db.0.9.0.Pub

4. Replication

Page 14: Couch Db.0.9.0.Pub

0.9.0の話

Page 15: Couch Db.0.9.0.Pub

Changes (公式より)• Modular configuration.• Performance enhancements for document and view access.• More resilient replication process.• Replication streams binary attachments.• Administrator role and basic authentication.• Document validation functions in design documents.• Show and list functions for rendering documents and views as

developer controlled content-types.• External process server module.• Attachment uploading from Futon.• Etags for views, lists, shows, document and attachment

requests.• Miscellaneous improvements to build, system integration, and

portability.

Page 16: Couch Db.0.9.0.Pub

目玉?

Page 17: Couch Db.0.9.0.Pub

Show and list functions for rendering documents and views as developer controlled content-types.

Page 18: Couch Db.0.9.0.Pub

Blogアプリで考える。

Page 19: Couch Db.0.9.0.Pub

タイトル、タグ、 内容文書のIDは日付で。

Page 20: Couch Db.0.9.0.Pub
Page 21: Couch Db.0.9.0.Pub
Page 22: Couch Db.0.9.0.Pub

アプリケーションサーバー丌要論

Page 23: Couch Db.0.9.0.Pub

特にRESTful/RESTonlyなアプリケーションはCouchDBでOK

Page 24: Couch Db.0.9.0.Pub

RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy

Page 25: Couch Db.0.9.0.Pub

RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy

省略

Page 26: Couch Db.0.9.0.Pub

JavaScriptでRenderingを書く

Page 27: Couch Db.0.9.0.Pub

Show

Page 28: Couch Db.0.9.0.Pub

RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy

Page 29: Couch Db.0.9.0.Pub

{"_id": "_design/test","_rev": "9-938762531","language": "javascript","views": {},"shows": {

"display": "(function (doc, req) {if (doc) {return ¥"<h1>¥" + doc.title + ¥"</h1><div>¥"+ doc.content + ¥"</div>¥";} else {if (req.docId) {return ¥"New World¥";} else {return ¥"Empty World¥";}}})"

}

Page 30: Couch Db.0.9.0.Pub

GET

/my_blog/_design/test/_show/display/2009_04_20_1

DB デザインドキュメントのID

shows のキー レンダリングするドキュメントのID

Page 31: Couch Db.0.9.0.Pub

<h1>今日は疲れた</h1><div><p>CouchDBの機能調査をしていたけどドキュメントがない</p></div>

Page 32: Couch Db.0.9.0.Pub

Restful Rails でいうところの、show をやってくれる

Page 33: Couch Db.0.9.0.Pub

IDにマッチする文書が見つからなければHTML Formを返すとか

Page 34: Couch Db.0.9.0.Pub

Controller#new, Controller#edit相当はできる!

Page 35: Couch Db.0.9.0.Pub

list

Page 36: Couch Db.0.9.0.Pub

RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy

Page 37: Couch Db.0.9.0.Pub

{"_id": "_design/test","_rev": "9-938762531","language": "javascript","views": {},"lists": {

"simple": "(function (head, row, req, row_info) {if (row) {return {body: ¥"<h1>¥" + row.key + ¥"</h1>¥" + ¥"<h2>¥" + row.value.title + ¥"</h2>¥" + ¥"<div>¥" + row.value.content + ¥"</div>¥"}; } else if (head) {return {body: ¥"<h1>My Blog (¥" + head.total_rows + ¥"件のエントリ)</h1>¥"};} else {return {body: ¥"</ul>¥" + ¥"<p>前へ: ¥" + (row_info ? row_info.first_key : ¥"¥") + ¥" 次へ: ¥" + (row_info ? row_info.prev_key : ¥"¥") + ¥"</p>¥"};}})"}}

Page 38: Couch Db.0.9.0.Pub

simple:function (head, row, req, row_info) {

if (row) {return {body: "<h1>" + row.key + "</h1>" + "<h2>" + row.value.title + "</h2>" + "<div>" + row.value.content + "</div>"

}; } else if (head) {return {body: "<h1>My Blog (" + head.total_rows + "件のエントリ)</h1>"};

} else {return {body: "<p>前へ: " +

(row_info ? row_info.first_key : "" ) + " 次へ: " + (row_info ? row_info.prev_key : "") + "</p>"

};}

})

ヘッダ

フッタ

本体

Page 39: Couch Db.0.9.0.Pub

GET/my_blog/_design/test/_list/simple/posts_by_date

lists のキー MapReduce View のキー

Page 40: Couch Db.0.9.0.Pub
Page 41: Couch Db.0.9.0.Pub

RESTful Rails でいうところの、Controller#indexをやってくれるもの

Page 42: Couch Db.0.9.0.Pub

MapReduce からレンダリングまでイッキに。

Page 43: Couch Db.0.9.0.Pub

コンテントネゴシエーションもできる

Page 44: Couch Db.0.9.0.Pub

JavaScript Runtime の初期化時に、以下の要領でType設定

registerType("all", "*/*");registerType("text", "text/plain", "txt");registerType("html", "text/html");registerType("xhtml", "application/xhtml+xml", "xhtml");registerType("xml", "application/xml", "text/xml", "application/x-xml");registerType("json", "application/json", "text/x-json");registerType("js", "text/javascript", "application/javascript", "application/x-javascript");registerType("css", "text/css");registerType("ics", "text/calendar");registerType("csv", "text/csv");registerType("rss", "application/rss+xml");registerType("atom", "application/atom+xml");registerType("yaml", "application/x-yaml", "text/yaml");registerType("multipart_form", "multipart/form-data");

Page 45: Couch Db.0.9.0.Pub

respondWith で返す!

return respondWith(req, {html : function() {return {

body:"<p>Ha ha, you said ¥"" + doc.word + "¥"."};

},xml : function() {return {

body: "<xml ...>"};

},fallback : "html"

});

Page 46: Couch Db.0.9.0.Pub

3XX とかもOK

Page 47: Couch Db.0.9.0.Pub

return {"code": 303, "body": "See Other", "headers": {"Location": "/"}};

Page 48: Couch Db.0.9.0.Pub

•Show and list functions for rendering documents and views as developer controlled content-types.

0.9.0 新機能!

Page 49: Couch Db.0.9.0.Pub

•一言で

0.9.0 新機能(その他)!

Page 50: Couch Db.0.9.0.Pub

Basic 認証とデータバリデーションができるようになって、いろいろ既存機能向上した

Page 51: Couch Db.0.9.0.Pub

jQuery と CouchDBでアプリは完成できる!?あと、Apache mod*があると便利

Page 52: Couch Db.0.9.0.Pub

余談:CouchDBで作るとおもしろそうなアプリ

Page 53: Couch Db.0.9.0.Pub

OpenSocialContainer

Page 54: Couch Db.0.9.0.Pub

OpenSocialContainer の要件

Page 55: Couch Db.0.9.0.Pub

JavaScript (gadgets)+ REST (API)+ KV Store (Persistence)

Page 56: Couch Db.0.9.0.Pub

これはCouch

Page 57: Couch Db.0.9.0.Pub
Page 58: Couch Db.0.9.0.Pub

• 公式▫ http://couchdb.apache.org/

• ドキュメント(違▫ http://localhost:5984/_utils/couch_tests.html?script/

couch_tests.js

• OpenSocial with CouchDB▫ http://github.com/yssk22/webjourney/tree/opensoci

al▫ まだ何もつくっていない▫ 開発者募集中 Apache Shindig と jQuery と (必要があればRails)でなんとかなるんじゃないかと。

• id:yssk22 が記述するすべてのコンテンツは個人の意見であり、勤務先の組織とは一切無関係のものです。