couch db.0.9.0.pub
DESCRIPTION
CouchDB 0.9.0 Overview in JapaneseTRANSCRIPT
Apache CouchDB 0.9.0リリース記念資料id:yssk22
http://d.hatena.ne.jp/yssk22
CouchDB復習
1. ドキュメント指向
JSONのデータをためる入れ物
{"_id" : "文書1""_rev" : "リビジョン""title" : "CouchDBについて""Content" : "いろいろ"}
2. Web+DB
REST
HTTP
3. 非リレーショナル
MapReduce:= SQLめんどう
HTTP map
reduce
HTTP Request
HTTP Response
4. Replication
http://couch.io/CouchDB-Intro-EU.pdf
のP.32からみるとおもしろい
0.9.0の話
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.
目玉?
Show and list functions for rendering documents and views as developer controlled content-types.
Blogアプリで考える。
タイトル、タグ、 内容文書のIDは日付で。
アプリケーションサーバー丌要論
特にRESTful/RESTonlyなアプリケーションはCouchDBでOK
RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy
RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy
省略
JavaScriptでRenderingを書く
Show
RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy
{"_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¥";}}})"
}
GET
/my_blog/_design/test/_show/display/2009_04_20_1
DB デザインドキュメントのID
shows のキー レンダリングするドキュメントのID
<h1>今日は疲れた</h1><div><p>CouchDBの機能調査をしていたけどドキュメントがない</p></div>
Restful Rails でいうところの、show をやってくれる
IDにマッチする文書が見つからなければHTML Formを返すとか
Controller#new, Controller#edit相当はできる!
list
RESTful RailsController#indexController#showController#newController#craeteController#updateController#editController#destroy
{"_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>¥"};}})"}}
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>"
};}
})
ヘッダ
フッタ
本体
GET/my_blog/_design/test/_list/simple/posts_by_date
lists のキー MapReduce View のキー
RESTful Rails でいうところの、Controller#indexをやってくれるもの
MapReduce からレンダリングまでイッキに。
コンテントネゴシエーションもできる
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");
respondWith で返す!
return respondWith(req, {html : function() {return {
body:"<p>Ha ha, you said ¥"" + doc.word + "¥"."};
},xml : function() {return {
body: "<xml ...>"};
},fallback : "html"
});
3XX とかもOK
return {"code": 303, "body": "See Other", "headers": {"Location": "/"}};
•Show and list functions for rendering documents and views as developer controlled content-types.
0.9.0 新機能!
•一言で
0.9.0 新機能(その他)!
Basic 認証とデータバリデーションができるようになって、いろいろ既存機能向上した
jQuery と CouchDBでアプリは完成できる!?あと、Apache mod*があると便利
余談:CouchDBで作るとおもしろそうなアプリ
OpenSocialContainer
OpenSocialContainer の要件
JavaScript (gadgets)+ REST (API)+ KV Store (Persistence)
これはCouch
• 公式▫ 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 が記述するすべてのコンテンツは個人の意見であり、勤務先の組織とは一切無関係のものです。