CouchDB 관련 링크

Posted at 2010/02/09 09:25// Posted in 나만의 작업

공식 Apache CouchDB homepage

CouchDB: The Definitive Guide
http://books.couchdb.org/relax/

Damien Katz Relaxing on CouchDB
CouchDB에 대해 Damien Katz(CouchDB를 만든)와 인터뷰한 내용.


웹 문서들

얼랭으로 구현된 문서 기반 분산 데이터베이스, CouchDB
http://www.dbguide.net/know/know102001.jsp?mode=view&pg=1&idx=3468

문서기반 분산 데이터베이스 CouchDB
http://xeraph.egloos.com/4617633

CouchDB implementation
http://horicky.blogspot.com/2008/10/couchdb-implementation.html

Programming CouchDB with Javascript (TODO application)
http://jan.prima.de/~jan/plok/archives/108-Programming-CouchDB-with-Javascript.html

Interactive CouchDB
This is a CouchDB emulator/visualizer written in 100% JavaScript, which implements key concepts like collation, map/reduce and incremental reduce. 
It also acts as a 2-minute CouchDB tutorial. No documents were harmed in this process. 
http://labs.mudynamics.com/wp-content/uploads/2009/04/icouch.html

CouchIn15Minutes
15분만에 CouchDB 시작하기(DB 생성, Document 생성, View 생성등 맛보기)
http://wiki.apache.org/couchdb/CouchIn15Minutes

Markov Chains using CouchDB's Group Reduce
http://jchrisa.net/drl/_design/sofa/_show/post/markov_chains_using_couchdb_s_g

CouchDB MapReduce example: word count
http://jchrisa.net/drl/_design/sofa/_show/post/couchdb_mapreduce_example

Couchdb Vs MySQL insert performance test data of the speed test
http://www.codeweblog.com/couchdb-vs-mysql-insert-performance-test-data-of-the-speed-test/


Jchris's toast at master - GitHub
http://github.com/jchris/toast/tree/master

CouchDB & CouchApp Managing Design Documents
http://www.blog.dannygagne.com/?p=43

database-queries-the-couchdb-way
http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html


Slide
Tag CouchDB

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret


Apache CouchDB가 0.9.1버젼에서 0.10.0 버젼으로 뛰었다.

11시간전에 DAMIEN KATZ 블로그에 올라왔다. 


이번 버젼 개선사항은  
  • Added modular configuration file directories.
  • Miscellaneous improvements to build, system integration, and portability.

이렇다고 한다. 

조금 더 편리하게 만들기 위해 노력한 것 같다.  

그 외에도 Show와 List API에 변화가 생겼다. 자세한 건 좀 더 살펴봐야겠다.



 

'나만의 작업 > DataBase' 카테고리의 다른 글

[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.  (2) 2009/10/14
[CouchDB] HTTP view API  (0) 2009/09/29
[CouchDB] HTTP Document API  (0) 2009/07/14
[CouchDB] Compaction  (0) 2009/07/13
[CouchDB] HTTP database API  (2) 2009/07/09
[CouchDB] API Cheatsheet  (0) 2009/07/09
[CouchDB] 초간단 Mac에서 CouchDB 실행하기  (0) 2009/07/07
[CouchDB] 1. CouchDB가 뭐지?  (2) 2009/07/07
[오라클] 초성검색  (2) 2009/04/28
  1. [NC]...YellOw
    2009/10/14 22:32 [Edit/Del] [Reply]
    오~~ 뭔지 모르겠지만 버리님 내공이 팍팍 쌓인다는건 느낄 수 있네요.
    싸늘한 날씨에 감기 조심하세요~
    • 버리야
      2009/10/15 00:55 [Edit/Del]
      내공은 저~너머에..ㅠㅠ
      저 오늘 예방접종 주사 맞았어요
      이제 끄떡없다는..
      [NC]...YellOw님두 감기 조심하세요~

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] HTTP view API

Posted at 2009/09/29 09:50// Posted in 나만의 작업/DataBase
CouchDB wiki에 있는 내용을 보고 정리한 내용입니다. 
제가 하고싶은걸 실습한 것이기 때문에 삭제된 내용도 있습니다.


view(뷰)는 Couch document를 쿼리하거나 리포팅할때 사용되는 주요툴이다.
뷰는 자바스크립트 function으로 정의된다.
function(doc) {
  emit(null, doc);
}

Creating Views
permanent view를 만들기 위해 function은 특별한 design document에 먼저 저장되어 있어야 한다.
design document의 id는 _design으로 시작하고 view attribute는 map과 optional하게 reduce를 갖는다.
design document의 모든 view는 index되어 있다.

design document
{
  "_id":"_design/company",
  "_rev":"12345",
  "language": "javascript",
  "views":
  {
    "all": {
      "map": "function(doc) { if (doc.Type == 'customer')  emit(null, doc) }"
    },
    "by_lastname": {
      "map": "function(doc) { if (doc.Type == 'customer')  emit(doc.LastName, doc) }"
    },
    "total_purchases": {
      "map": "function(doc) { if (doc.Type == 'purchase')  emit(doc.Customer, doc.Amount) }",
      "reduce": "function(keys, values) { return sum(values) }"
    }
  }
}


Altering/Changing Views

하나의 뷰나 여러개의 뷰들을 바구기 위해선 document바꿀때랑 똑같다.

Access/Query
database에 document가 한번 저장되어있으면 모든 view는 이 URL로 반환받을 수 있다.
http://localhost:5984/database/_design/company/_view/all

요청은 이렇게..
GET /some_database/_design/company/_view/all HTTP/1.0
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT

응답은 다음과 같다.
HTTP/1.1 200 OK
 Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
 Content-Length: 318
 Connection: close

 {
    "total_rows": 3,
    "offset": 0,
    "rows": [{
        "id":"64ACF01B05F53ACFEC48C062A5D01D89",
        "key": null,
        "value": {
          "LastName":"Katz",
          "FirstName":"Damien",
          "Address":"2407 Sawyer drive, Charlotte NC",
          "Phone":012555754211
        }
      }, {
        "id":"5D01D8964ACF01B05F53ACFEC48C062A",
        "key": null,
        "value": {
          "LastName":"Kerr",
          "FirstName":"Wayne",
          "Address":"123 Fake st., such and such",
          "Phone":88721320939
        }
      }, {
        "id":"EC48C062A5D01D8964ACF01B05F53ACF",
        "key": null,
        "value":
        {
          "LastName":"McCracken",
          "FirstName":"Phil",
          "Address":"1234 Fake st., such and such",
          "Phone":7766552342
        }
      }
    ]
 }


Temporary Views
한번 쿼리 날리고 말것(CouchDB database에 view를 저장하고 싶지않으면) _temp_view라는 특별한 view를 통해 할 수 있다.
Temporary View는 개발중에만 사용하는 것이 좋다.

요청
POST /some_database/_temp_view  HTTP/1.0
Content-Length: 48
Date: Mon, 10 Sep 2007 17:11:10 +0200
Content-Type: application/json

{
  "map" : "function(doc) { if (doc.foo=='bar') { emit(null, doc.foo); } }"
}

응답
{
  "total_rows": 1,
  "offset": 0,
  "rows": [{
      "id": "AE1AD84316B903AD46EF396CAFE8E50F",
      "key": null,
      "foo": "bar"
    }
  ]
}

NOTE : CouchDB 0.9.0에선 _temp_view에 POST 요청시 Content-Type: application/json를 써줘야한다.

Querying Options

아래와 같은 URL query arguments가 허용된다.

    * GET
            key=keyvalue

            startkey=keyvalue

            startkey_docid=docid

            endkey=keyvalue

            endkey_docid=docid

            limit=max rows to return This used to be called "count" previous to Trunk SVN r731159

            stale=ok

            descending=true

            skip=number of rows to skip

            group=true Version 0.8.0 and forward

            group_level=int

            reduce=false Trunk only (0.9)

            include_docs=true Trunk only (0.9)
           
    *  POST

            {"keys": ["key1", "key2", ...]} Trunk only (0.9)
           

'나만의 작업 > DataBase' 카테고리의 다른 글

[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.  (2) 2009/10/14
[CouchDB] HTTP view API  (0) 2009/09/29
[CouchDB] HTTP Document API  (0) 2009/07/14
[CouchDB] Compaction  (0) 2009/07/13
[CouchDB] HTTP database API  (2) 2009/07/09
[CouchDB] API Cheatsheet  (0) 2009/07/09
[CouchDB] 초간단 Mac에서 CouchDB 실행하기  (0) 2009/07/07
[CouchDB] 1. CouchDB가 뭐지?  (2) 2009/07/07
[오라클] 초성검색  (2) 2009/04/28

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] HTTP Document API

Posted at 2009/07/14 10:02// Posted in 나만의 작업/DataBase
CouchDB wiki에 있는 내용을 보고 정리한 내용입니다.
제가 하고싶은걸 실습한 것이기 때문에 삭제된 내용도 있습니다.


Naming/Addressing
CouchDB에 저장된 Document들은 DocID를 가진다. DocID는 유니크한 아이디. 두개의 document는 같은 database안에 같은 identifier를 가질 수 없다.

"test"라는 이름의 database안의 some_doc_id, another_doc_id, BA1F48C5418E4E68E5183D5BD1F06476 이름의 document가 있다.
http://localhost:5984/test/some_doc_id
http://localhost:5984/test/another_doc_id
http://localhost:5984/test/BA1F48C5418E4E68E5183D5BD1F06476

JSON
CouchDB document는 간단한 JSON object이다.
{
 "_id":"some_doc_id",
 "_rev":"D1C946B7",
 "Subject":"I like Plankton",
 "Author":"Rusty",
 "PostedDate":"2006-08-15T17:30:12-04:00",
 "Tags":["plankton", "baseball", "decisions"],
 "Body":"I decided today that I don't like baseball. I like plankton."
}

Working With Documents Over HTTP

document생성

buri라는 database안의 document들의 리스트를 얻을려면,
~]curl -i http://localhost:5984/buri/_all_docs

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: CouchDB/0.9.0 (Erlang OTP/R13B)
Etag: "EUBRVUD02OXJJT4QD3O565AWW"
Date: Sat, 04 Jul 2009 12:01:04 GMT
Content-Type: text/plain;charset=utf-8
Cache-Control: must-revalidate

{"total_rows":3,"offset":0,"rows":[
{"id":"038dac2f6d16d32cfa4f0beedd1b970f","key":"038dac2f6d16d32cfa4f0beedd1b970f","value":{"rev":"1-752793712"}},
{"id":"_design/log","key":"_design/log","value":{"rev":"1-1517763105"}},
{"id":"test_doc","key":"test_doc","value":{"rev":"1-2073410021"}}
]}

하나의 document의 정보를 알고 싶으면(기본필드(_id, _rev)외에 따로 추가한 필드가 없어서 응답받은 JSON은 이렇다.
~]curl http://localhost:5984/buri/test_doc
{"_id":"test_doc","_rev":"1-2073410021"}

Accessing Previous Revisions

특정한 revision의 document를 가져오고 싶으면,
~]curl http://localhost:5984/buri/test_doc?rev=1-2073410021
{"_id":"test_doc","_rev":"1-2073410021"}

document의 가능한 revision을 찾기 위해선,
~]curl http://localhost:5984/buri/test_doc?revs=true
{"_id":"test_doc","_rev":"1-2073410021","_revisions":{"start":1,"ids":["2073410021"]}}

document의 현재 revision을 반환하지만, _revisions라는 필드는 이용가능한 revision ID를 리스트를 갖는다.

_revisions 결과가 하나라서 확인하여 좀 허무하다면,
revision을 증가시키기위해, document에 필드를 추가한 후 다시 _revisions를 확인하기 위해 요청해보면,
~]curl http://localhost:5984/buri/test_doc?revs=true
{"_id":"test_doc","_rev":"2-3544093946","test":"test field","_revisions":{"start":2,"ids":["3544093946","2073410021"]}}

_rev는 현재 revision을 반환하고, _revisions는 revision의 history ids를 가지고 있다.


이용가능한 document revision에 대해 좀 더 많은 정보를 얻고 싶으면, revs_info 파라미터를 이용하면 된다.
JSON 결과는 _revs_info 프로퍼티를 포함한 객체의 배열을 리턴한다.

{
  "_revs_info": [
    {"rev": "123456", "status": "disk"},
    {"rev": "234567", "status": "missing"},
    {"rev": "345678", "status": "deleted"},
  ]
}

PUT
새로운 document를 생성하기 위해선, POST나 PUT operation을 이용하면 된다.
PUT은 document를 생성/수정할 수 있다.

이미 존재하는 document를 수정하기 위해선 JSON body에 _rev 프로퍼티를 포함하고 있어야 한다.
그래야, CouchDB가 edit할지를 안다. database에 document의 현재 저장된 revision이 맞지 않으면, 409 conflict error를 리턴한다.

만약 revision 번호가 database에 있는 값과 매치하면 새로 generated된 revision 번호를 client에 리턴한다.

~]curl -X PUT http://localhost:5984/buri/test_doc -d '{"_id":"test_doc","_rev":"2-3544093946","test":"update field"}'
{"ok":true,"id":"test_doc","rev":"3-2553359885"}


POST
POST는 서버에 generated된 DocID를 생성하기 위해 사용된다. PUT method대신에 사용되기도 하는데 가능한한 POST를 피하는 걸 추천.
proxy나 다른 네트워크가 종종 POST 요청을 재전송해 document 생성 중복요청을 하므로...

DELETE
~]curl -i -X DELETE http://localhost:5984/buri/test_doc?rev=3-2553359885

HTTP/1.1 200 OK
Server: CouchDB/0.9.0 (Erlang OTP/R13B)
Etag: "4-386883723"
Date: Sat, 04 Jul 2009 12:49:12 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 48
Cache-Control: must-revalidate

{"ok":true,"id":"test_doc","rev":"4-386883723"}


All Documents
database의 모든 document의 리스트를 얻기위해 _all_docs URI를 이용

~]curl http://localhost:5984/buri/_all_docs 이런식으로

wiki에 나와있는 예제로 보면~

GET somedatabase/_all_docs HTTP/1.0

HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
  "total_rows": 3, "offset": 0, "rows": [
    {"id": "doc1", "key": "doc1", "value": {"rev": "4324BB"}},
    {"id": "doc2", "key": "doc2", "value": {"rev":"2441HF"}},
    {"id": "doc3", "key": "doc3", "value": {"rev":"74EC24"}}
  ]
}


revision ID와 DocID에 정렬로 모든 document의 리스트를 보여준다.
query argument에 descending=true 를 보내면 정렬이 descending으로 결과를 리턴한다.

~]curl http://localhost:5984/buri/_all_docs?descending=true 이런식으로

HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
  "total_rows": 3, "offset": 0, "rows": [
    {"id": "doc3", "key": "doc3", "value": {"_rev":"74EC24"}}
    {"id": "doc2", "key": "doc2", "value": {"_rev":"2441HF"}},
    {"id": "doc1", "key": "doc1", "value": {"_rev": "4324BB"}},
  ]
}

query string 파라미터를 startkey, endkey와 limit을 주면 결과를 제한할 수 있다.

~]curl http://localhost:5984/buri/_all_docs?startkey="doc2"&limit=2 이런식으로 보내면

GET somedatabase/_all_docs?startkey="doc2"&limit=2 HTTP/1.0


HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
  "total_rows": 3, "offset": 1, "rows": [
    {"id": "doc2", "key": "doc2", "value": {"_rev":"2441HF"}},
    {"id": "doc3", "key": "doc3", "value": {"_rev":"74EC24"}}
  ]
}

doc2 부터 두개의 값을 리턴받을 수 있다.

~]curl http://localhost:5984/buri/_all_docs?startkey="doc2"&endkey="doc3"

GET somedatabase/_all_docs?startkey="doc2"&endkey="doc3" HTTP/1.0

doc2와 doc3사이에 포함된 값을 리턴한다.


GET somedatabase/_all_docs?startkey="doc2"&limit=2&descending=true HTTP/1.0


HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
  "total_rows": 3, "offset": 1, "rows": [
    {"id": "doc3", "key": "doc3", "value": {"_rev":"74EC24"}}
    {"id": "doc2", "key": "doc2", "value": {"_rev":"2441HF"}},
  ]
}

all_docs_by_seq

update됐거나, delete된 모든 document를 볼 수 있다.
~]curl http://localhost:5984/buri/_all_docs_by_seq
{"total_rows":3,"offset":0,"rows":[
{"id":"038dac2f6d16d32cfa4f0beedd1b970f","key":2,"value":{"rev":"1-752793712"}},
{"id":"a52617f0a61a11fa894a2ce6f62e3a7c","key":3,"value":{"rev":"2-695380571","deleted":true}},
{"id":"_design/log","key":5,"value":{"rev":"1-1517763105"}},
{"id":"test","key":6,"value":{"rev":"2-1465437068","deleted":true}},
{"id":"test_doc","key":10,"value":{"rev":"4-386883723","deleted":true}},
{"id":"test2_doc","key":11,"value":{"rev":"1-1479752545"}}
]}


Attachments

Document는 email과 값은 첨부파일을 가지고 있을 수 있다. 첨부파일을 사용하는 두가지 방법이 있는데 하나는 document에 인라인으로 기술하는 방법.
두번째 방법은 첨부파일을 위한 REST API을 이용하는 방법이 있다.

Inline Attachments

생성시 document의 _attachments attribute를 이용한다.
JSON 구조는 name, content_type, base64로 인코드된 첨부파일의 데이터를 가진다.
document가 리턴될때 첨부파일의 실제 데이터는 포함하지 않고 metadata만 반환된다. 실제 데이터는 따로 URI로 분라되어 fetch되어 있다.
document 요청시 첨부파일을 접근해야할때는 query parameter에 ?attachments=true를 포함해서 보낸다.

첨부파일이 있는 document 생성
{
  "_id":"attachment_doc",
  "_attachments":
  {
    "foo.txt":
    {
      "content_type":"text\/plain",
      "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
    }
  }
}

document를 요청하면,

GET /database/attachment_doc

이렇게 응답을 얻는다.
{
  "_id":"attachment_doc",
  "_rev":1589456116,
  "_attachments":
  {
    "foo.txt":
    {
      "stub":true,
      "content_type":"text\/plain",
      "length":29
    }
  }
}

첨부파일을 요청하면
GET /database/attachment_doc/foo.txt

foo.txt파일의 내용인
This is a base64 encoded text
자동적으로 디코드되서 리턴된다.

Multiple Attachments

{
  "_id":"attachment_doc",
  "_attachments":
  {
    "foo.txt":
    {
      "content_type":"text\/plain",
      "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
    },

   "bar.txt":
    {
      "content_type":"text\/plain",
      "data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
    }
  }
}

Standalone Attachments

CouchDB 0.9버젼에 추가되었다. 그 전 버젼에선 이용할 수 없다.

Content-Type 헤더를 이용하여 MIME type을 이용한다.

요청은 이렇게..

PUT somedatabase/document/attachment?rev=123 HTTP/1.0
Content-Length: 245
Content-Type: image/jpeg

<JPEG data>

응답은 이렇게 온다.
{"ok": true, "id": "document", "rev": "765B7D1C"}

첨부파일을 바꿀땐(수정)

PUT somedatabase/document/attachment?rev=765B7D1C HTTP/1.0
Content-Length: 245
Content-Type: image/jpeg

<JPEG data>

첨부파일을 삭제
DELETE somedatabase/document/attachment?rev=765B7D1C HTTP/1.0

ETags/Caching

CouchDB는 document 요청을 위해 ETag Header를 보낸다.

GET 요청의 예
GET /database/123182719287


응답
cache-control: no-cache,
pragma: no-cache
expires: Tue, 13 Nov 2007 23:09:50 GMT
transfer-encoding: chunked
content-type: text/plain;charset=utf-8
etag: "615790463"

POST 요청도 새롭게 추가되거나 document가 업데이트 하기 위해 ETag header를 리턴한다.





'나만의 작업 > DataBase' 카테고리의 다른 글

[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.  (2) 2009/10/14
[CouchDB] HTTP view API  (0) 2009/09/29
[CouchDB] HTTP Document API  (0) 2009/07/14
[CouchDB] Compaction  (0) 2009/07/13
[CouchDB] HTTP database API  (2) 2009/07/09
[CouchDB] API Cheatsheet  (0) 2009/07/09
[CouchDB] 초간단 Mac에서 CouchDB 실행하기  (0) 2009/07/07
[CouchDB] 1. CouchDB가 뭐지?  (2) 2009/07/07
[오라클] 초성검색  (2) 2009/04/28

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] Compaction

Posted at 2009/07/13 13:54// Posted in 나만의 작업/DataBase
CouchDB의 Reference중 Compaction
CouchDB 공식 wiki에 적혀있는 내용을 간략히 정리해서 쓴 글입니다.

Compaction
Compaction은 database파일을 다시 쓰는 것.
outdated document revision을 제거하고 document를 삭제한다.

curl을 이용하여 테스트해보자!
~]curl http://localhost:5984/buri ('buri'라는 이름의 DB의 간략한 정보를 볼 수 있다.)
{"db_name":"buri","doc_count":2,"doc_del_count":2,"update_seq":6,"purge_seq":0,"compact_running":false,
"disk_size":16361,"instance_start_time":"1246416252648676"}

~]curl -X POST http://localhost:5984/buri/_compact   (compactio수행)
{"ok":true}

~]curl http://localhost:5984/buri (DB정보 확인)
{"db_name":"buri","doc_count":2,"doc_del_count":2,"update_seq":6,"purge_seq":0,"compact_running":false,
"disk_size":14807,"instance_start_time":"1246707347739253"}

disk_size가 줄었다는거~로 확인할 수 있다.

'나만의 작업 > DataBase' 카테고리의 다른 글

[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.  (2) 2009/10/14
[CouchDB] HTTP view API  (0) 2009/09/29
[CouchDB] HTTP Document API  (0) 2009/07/14
[CouchDB] Compaction  (0) 2009/07/13
[CouchDB] HTTP database API  (2) 2009/07/09
[CouchDB] API Cheatsheet  (0) 2009/07/09
[CouchDB] 초간단 Mac에서 CouchDB 실행하기  (0) 2009/07/07
[CouchDB] 1. CouchDB가 뭐지?  (2) 2009/07/07
[오라클] 초성검색  (2) 2009/04/28

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] HTTP database API

Posted at 2009/07/09 18:38// Posted in 나만의 작업/DataBase
CouchDB의 Reference중 HTTP database API

CouchDB wiki에 있는 내용을 보고 실행해 본 과정을 올립니다.
제 나름의 정리이기에 생략된 것도 있습니다.
실행은 curl을 통해서 주로 하였습니다.


Naming and Addressing

database 이름은 모두 소문자 a-z, 숫자 0-9, _$()+-/ 문자로 이뤄져야 하고 slash(/)로 끝나야한다.
http://couchserver/databasename/
http://couchserver/another/databasename/
http://couchserver/another/database_name(1)/

주의! 대문자는 database 이름에 포함되어서는 안된다.
http://couchserver/DBNAME/ (invalid)
http://couchserver/DatabaseName/ (invalid)
http://couchserver/databaseName/ (invalid)

URL에서 DB이름에 slash(/)를 넣기 위해선 escape 처리를 해야한다.
DB이름이 "his/her" 이면 url을 이렇게 써서 보내야 한다.
http://localhost:5984/his%2Fher

List Databases
CouchDB server에 있는 모든 database들의 리스트 조회 /_all_dbs
~] curl http://localhost:5984/_all_dbs

HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 05:39:28 +0000GMT
Content-Length: 37
Content-Type: application/json
Connection: close

["somedatabase", "anotherdatabase"]


PUT (Create New Database)

위에 slash있는 Database이름을 만들어 보면

~]curl -X PUT http://localhost:5984/buri/test/
{"error":"invalid_json","reason":"undefined"}

escape처리해서 보내야 하므로~

~]curl -i -X PUT http://localhost:5984/buri%2Ftest/

HTTP/1.1 201 Created
Server: CouchDB/0.9.0 (Erlang OTP/R13B)
Date: Sat, 04 Jul 2009 10:56:20 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 12
Cache-Control: must-revalidate

{"ok":true}

이렇게 PUT 메소드를 실행하여 새로운 database를 만들었다!
성공하면 201 이미 존재한다면 412 HTTP status를 응답받는다.

DELETE
database를 지우고 싶으면 DELETE method를 이용하면 된다.

~]curl -X DELETE http://localhost:5984/buri%2Ftest
{"ok":true}

성공하면 200, 존재하지 않는다면 404 error HTTP status를 응답받는다.

Database Information
~]curl http://localhost:5984/buri

{"db_name":"buri","doc_count":2,"doc_del_count":2,"update_seq":6,"purge_seq":0,"compact_running":false,
"disk_size":16361,"instance_start_time":"1246416252648676"}






'나만의 작업 > DataBase' 카테고리의 다른 글

[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.  (2) 2009/10/14
[CouchDB] HTTP view API  (0) 2009/09/29
[CouchDB] HTTP Document API  (0) 2009/07/14
[CouchDB] Compaction  (0) 2009/07/13
[CouchDB] HTTP database API  (2) 2009/07/09
[CouchDB] API Cheatsheet  (0) 2009/07/09
[CouchDB] 초간단 Mac에서 CouchDB 실행하기  (0) 2009/07/07
[CouchDB] 1. CouchDB가 뭐지?  (2) 2009/07/07
[오라클] 초성검색  (2) 2009/04/28
  1. [NC]...YellOw
    2009/07/12 02:30 [Edit/Del] [Reply]
    늘~ 열심히 하고 있네요. 보기 좋네요.
    지금 비가 제법 내리고 있는거 같더라구여. 덕분에 차분한 밤을 보내고 있습니다 ^.~
    • 2009/07/17 11:49 [Edit/Del]
      늘 말씀드리는 거지만...속고 계신거에요...ㅋㅋㅋ
      주말내내 비가 정말 많이 내렸던 듯..
      덕분에 저도 밤에 차분히 보냈답니다..ㅋㅋ

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] API Cheatsheet

Posted at 2009/07/09 18:30// Posted in 나만의 작업/DataBase
CouchDB Reference중 API Cheatsheet
 2009년 7월 현재 0.9.0버젼의 CouchDB 공식 wiki에 작성되어 있는 API Cheatsheet를 옮겨 적어놓습니다.


CouchDB Server Level Requests
info : GET /
all_dbs : GET /_all_dbs
config : GET /_config
stats : GET /_stats
UUIDs : GET /_uuids (takes a count parameter)
replicate : POST /_replicate (see Replication) <-http://wiki.apache.org/couchdb/Replication
source에서 destination으로 복제하고 싶을때

CouchDB Database Level Requests
compact : POST /db/_compact
create : PUT /db
drop : DELETE /db
info : GET /db
all_docs : GET /db/_all_docs
open_doc : GET /db/doc_id
save_doc (CREATE) : POST /db
save_doc (UPDATE) : PUT /db/doc_id
remove_doc : DELETE /db/doc_id
bulk_docs : POST /db/_bulk_docs
query (aka temporary view) : POST /db/_temp_view
view

CouchDB 0.9.0 이전 버젼에서는
GET /db/_view/designname/viewname

CouchDB 0.9.0 이후 버젼에서는
GET /db/_design/designname/_view/viewname



댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret


one-click으로 가장 간단하게 Mac에서 실행하는 방법!  이보다 더 간단할 수 없다.

링크 : http://janl.github.com/couchdbx/

2009년 7월 현재  0.9.0-R13B 버젼을 받을 수 있다.
이 버젼엔 Erlang R13B, Spidermonkey 1.7 and ICU 3.8 가 포함되어 있다.

앞으로 계속 업데이트 될테니 저 링크에서 다운로드 받으세요~~

다운로드 후 더블클릭 하면 실행된다.!  끝!

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret

[CouchDB] 1. CouchDB가 뭐지?

Posted at 2009/07/07 10:34// Posted in 나만의 작업/DataBase
CouchDB???가 뭐지 하고 찾아보니
CouchDB는 아파치 오픈소스 프로젝트이고, DB이지만 Non-Relational Database이고 document-oriented기반이라고 합니다.

뭔가..새로운 포스가 느껴지는데..  뭔가 개성이 강한 느낌..으로 조금 더 살펴보면,




Couch를 사전에서 찾아보면 이런 뜻을 가지고 있는데..
1a 긴 의자, 소파 《기댈 수 있는 등받이와 팔걸이가 있는》
2 《문어·시어》 침상, 잠자리
3 《일반적으로》 휴식처 《풀밭 등》;(야생 동물의) 은신처, 굴(lair)


딱 이름만 듣고는 이런 DB를 만들고 싶지 않았을까란 생각은 들지만,
Cluster Of Unreliable Commodity Hardware의 약자라고 하네요..

특징은

    * RESTful API
    * Schema-less document store (document in JSON format)
    * Multi-Version-Concurrency-Control model
    * User-defined query structured as map/reduce
    * Incremental Index Update mechanism
    * Multi-Master Replication model
    * Written in Erlang (Erlang is good)

가장 중요한 점은 RESTful API를 이용한다는 것!

허걱 Erlang(얼랭)으로 쓰여져있다고 하고 스키마 필요없는 document을 저장하는 방식이고 이 document는 JSON format으로 데이터를 교환한다고 하는군요. 그리고 query는 map/reduce 구조를 이용합니다.


CouchDB는 요런 구조로 생겼다고 하네요.


CouchDB은 처음에 C++로 만들어졌지만 도중에 Erlang으로 교체되었고, CouchDB의 default view server는 C를 사용한 모질라의 Spidermonkey Javascript library를 이용합니다.

Apache 2.0 License 이고, CouchDb설치시에 웹서버가 같이 설치되어 Client와 HTTP로 통신하고 Data(Document)를 JSON으로 주고 받는다고 합니다.

처음에 호기심 가지고 보다보니 참 개성강한 듯 하군요.


  1. 2009/07/07 14:22 [Edit/Del] [Reply]
    먼저 올리다니 반칙이에요 ㅋㅋ

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret