'DATABASE'에 해당되는 글 9건
- [CouchDB] Apache CouchDB 0.10.0 이 나왔답니다. (2) 2009/10/14
- [CouchDB] HTTP view API 2009/09/29
- [CouchDB] HTTP Document API 2009/07/14
- [CouchDB] Compaction 2009/07/13
- [CouchDB] HTTP database API (2) 2009/07/09
- [CouchDB] API Cheatsheet 2009/07/09
- [CouchDB] 초간단 Mac에서 CouchDB 실행하기 2009/07/07
- [CouchDB] 1. CouchDB가 뭐지? (2) 2009/07/07
- [Spring] Hitting the database (8) 2007/11/04
[CouchDB] Apache CouchDB 0.10.0 이 나왔답니다.
Posted at 2009/10/14 11:38// Posted in 나만의 작업/DataBase- Added modular configuration file directories.
- Miscellaneous improvements to build, system integration, and portability.
'나만의 작업 > 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 |
[CouchDB] HTTP view API
Posted at 2009/09/29 09:50// Posted in 나만의 작업/DataBaseview(뷰)는 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 |
[CouchDB] HTTP Document API
Posted at 2009/07/14 10:02// Posted in 나만의 작업/DataBase제가 하고싶은걸 실습한 것이기 때문에 삭제된 내용도 있습니다.
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 |
[CouchDB] Compaction
Posted at 2009/07/13 13:54// Posted in 나만의 작업/DataBaseCompaction
Compaction은 database파일을 다시 쓰는 것.
outdated document revision을 제거하고 document를 삭제한다.
~]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"}
'나만의 작업 > 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 |
[CouchDB] HTTP database API
Posted at 2009/07/09 18:38// Posted in 나만의 작업/DataBase실행은 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 |
-
[NC]...YellOw2009/07/12 02:30 [Edit/Del] [Reply]늘~ 열심히 하고 있네요. 보기 좋네요.
지금 비가 제법 내리고 있는거 같더라구여. 덕분에 차분한 밤을 보내고 있습니다 ^.~-
2009/07/17 11:49 [Edit/Del]늘 말씀드리는 거지만...속고 계신거에요...ㅋㅋㅋ
주말내내 비가 정말 많이 내렸던 듯..
덕분에 저도 밤에 차분히 보냈답니다..ㅋㅋ
-
[CouchDB] API Cheatsheet
Posted at 2009/07/09 18:30// Posted in 나만의 작업/DataBase2009년 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
'나만의 작업 > DataBase' 카테고리의 다른 글
| [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 |
| 자주 쓰지 않아서 잊어버리는 간단한 Oracle SQL문들 (4) | 2009/04/22 |
[CouchDB] 초간단 Mac에서 CouchDB 실행하기
Posted at 2009/07/07 21:37// Posted in 나만의 작업/DataBaseone-click으로 가장 간단하게 Mac에서 실행하는 방법! 이보다 더 간단할 수 없다.
링크 : http://janl.github.com/couchdbx/
2009년 7월 현재 0.9.0-R13B 버젼을 받을 수 있다.
이 버젼엔 Erlang R13B, Spidermonkey 1.7 and ICU 3.8 가 포함되어 있다.
앞으로 계속 업데이트 될테니 저 링크에서 다운로드 받으세요~~
다운로드 후 더블클릭 하면 실행된다.! 끝!
'나만의 작업 > DataBase' 카테고리의 다른 글
| [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 |
| 자주 쓰지 않아서 잊어버리는 간단한 Oracle SQL문들 (4) | 2009/04/22 |
| Oracle instant client 설치(Mac OSX, Windows) (0) | 2009/01/07 |
[CouchDB] 1. CouchDB가 뭐지?
Posted at 2009/07/07 10:34// Posted in 나만의 작업/DataBaseCouchDB는 아파치 오픈소스 프로젝트이고, DB이지만 Non-Relational Database이고 document-oriented기반이라고 합니다.
뭔가..새로운 포스가 느껴지는데.. 뭔가 개성이 강한 느낌..으로 조금 더 살펴보면,
Couch를 사전에서 찾아보면 이런 뜻을 가지고 있는데..
2 《문어·시어》 침상, 잠자리
3 《일반적으로》 휴식처 《풀밭 등》;(야생 동물의) 은신처, 굴(lair)
딱 이름만 듣고는 이런 DB를 만들고 싶지 않았을까란 생각은 들지만, Cluster Of Unreliable Commodity Hardware의 약자라고 하네요..
특징은
* 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은 처음에 C++로 만들어졌지만 도중에 Erlang으로 교체되었고, CouchDB의 default view server는 C를 사용한 모질라의 Spidermonkey Javascript library를 이용합니다.
Apache 2.0 License 이고, CouchDb설치시에 웹서버가 같이 설치되어 Client와 HTTP로 통신하고 Data(Document)를 JSON으로 주고 받는다고 합니다.
처음에 호기심 가지고 보다보니 참 개성강한 듯 하군요.
'나만의 작업 > DataBase' 카테고리의 다른 글
| [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 |
| 자주 쓰지 않아서 잊어버리는 간단한 Oracle SQL문들 (4) | 2009/04/22 |
| Oracle instant client 설치(Mac OSX, Windows) (0) | 2009/01/07 |
| JAVA DB - Derby (4) | 2007/05/12 |
[Spring] Hitting the database
Posted at 2007/11/04 20:56// Posted in 나만의 작업/Spring* Hitting the database
1) Spring의 DataAccessException
java.sql.SQLException은 checked Exception입니다. 즉, 개발자가 try-catch로 잡아줘야 합니다.
이는 코드를 난잡하게 만들수 있습니다. 그리고 SQLException이 제공하는 예외는 Spring에 비해서 매우 종류가 많지 않습니다.
DataAccessException은 SQLException이나
HibernateException등과 같이 특정 기술에 의존적인 예외를 던지지 않기때문에, 데이터 접근 인터페이스가 구현에 의존적인 예외가 아닌
스프링의 일반적인 DataAccessException을 던지게 함으로써, 특정한 퍼시스턴스 구현에 결합되는 일을 방지합니다.
DataAccessException은 RuntimeException이기 때문에
unchecked Exception에 속하기 때문에 개발자가 반드시 처리하지 않아도 됩니다. unchecked Exception이 발생하는
경우는 대개 복구가 불가능한 것이기 때문에 개발자가 직접 처리해야 할 필요는 없습니다. 만약 복구가 가능한 것이라면 예외를 잡아 호출 스택으로
전달되도록 할 수도 있습니다. (처리하고 싶으면 잡아서 처리하고, 하고 싶지 않으면 Spring에서 잡도록 내버려 둬도 됩니다.)
Spring의 DAO Exception 분류 체계는 매우 세밀하기 때문에, 서비스 객체가
잡고자 하는 exception의 타입과 호출 스택에 전달하고자 하는 exception을 정확히 선택할 수 있습니다.
2) Spring에서 데이터 접근
Spring은 데이터 접근 프로세스에 있어서 고정된(변하지 않는) 부분을 template(템플릿)으로 가변적인(변하는) 부분을 callback(콜백)으로 구분합니다.
template은 프로세스의 고정된 부분을 관리하는 반면, callback은 구체적인 구현을 넣어야 하는 장소입니다.
template은 데이터 저장소로의 연결 취득, 트랜잭션 제어, 자원반환, 예외 처리등하고싶을 일을 구현하기 위해
중복적으로 해야하는 작업들입니다.
callback 인터페이스의 구현 클래스는 질의문 생성, 파라미터 바인딩, 결과 집합 마샬링(marshalling) 등 애플리케이션에 특정적인 부분을 정의합니다.
[그림] 스프링 DAO 템플릿과 콜백 클래스의 역할 ( 차후에 추가 )
* JDBC 코드의 문제점은 무엇일까요? (Quiz)
Spring에서의 JdbcTemplate
Spring이 JDBC 프레임워크는 자원 관리와 에러 처리의 부담을 떠맡음으로써 JDBC 코드를 깨끗하게 만들어 줍니다.
JdbcTemplate 클래스가 작업하기 위해 필요한 것은 DataSource뿐입니다.
- JdbcTemplate과 함께 쓰이는 Class
//---------------------------------------------------------------
// 데이터 쓰기
//---------------------------------------------------------------
-
PreparedStatementCreator : 이 인터페이스의 구현 클래스는 PreparedStatement를 생성시킬 책임을 갖는다. 이 인터페이스를 구현할 때에는 인자로 넘어온 Connection으로부터 PreparedStatement를 생성하고 리턴해줘야 한다. 그러나 예외 처리에 대해서는 신경쓰지 않아도 된다.
/**
* One of the two central callback interfaces used by the JdbcTemplate class.
* This interface creates a PreparedStatement given a connection, provided
* by the JdbcTemplate class. Implementations are responsible for providing
* SQL and any necessary parameters.
*/
public interface PreparedStatementCreator {
/**
* Create a statement in this connection. Allows implementations to use
* PreparedStatements. The JdbcTemplate will close the created statement.
* @param con Connection to use to create statement
* @return a prepared statement
* @throws SQLException there is no need to catch SQLExceptions
* that may be thrown in the implementation of this method.
* The JdbcTemplate class will handle them.
*/
PreparedStatement createPreparedStatement(Connection con) throws SQLException;
} SqlProvider : SqlProvider 인터페이스의 getSql() 이라는 하나의 메소드를 구현함으로써 클래스가 SQL 문자열을 JdbcTemplate 클래스에 제공할 수 있게 된다. 이렇게 하면 JdbcTemplate 클래스가 자신이 실행하는 모든 SQL 문장에 대해 로그를 남기는 것이 가능해진다.
public interface SqlProvider {
/**
* Return the SQL string for this object, i.e.
* typically the SQL used for creating statements.
* @return the SQL string, or <code>null</code>
*/
String getSql();
}-
PreparedStatementSetter : PreparedStatementCreatr를 보완. 파라미터를 세팅하기만 하고 모든 예외 처리는 JdbcTemplate 클래스가 해 줄 것이다.
public interface PreparedStatementSetter {
/**
* Set parameter values on the given PreparedStatement.
* @param ps the PreparedStatement to invoke setter methods on
* @throws SQLException if a SQLException is encountered
* (i.e. there is no need to catch SQLException)
*/
void setValues(PreparedStatement ps) throws SQLException;
} -
BatchPreparedStatement : 갱신하고자 하는 레코드가 둘 이상일 경우.
public interface BatchPreparedStatementSetter {
/**
* Set parameter values on the given PreparedStatement.
* @param ps the PreparedStatement to invoke setter methods on
* @param i index of the statement we're issuing in the batch, starting from 0
* @throws SQLException if a SQLException is encountered
* (i.e. there is no need to catch SQLException)
*/
void setValues(PreparedStatement ps, int i) throws SQLException;
/**
* Return the size of the batch.
* @return the number of statements in the batch
*/
int getBatchSize();
}
// ------------------------------------------------------------------------------------
// 데이터 읽기
// ------------------------------------------------------------------------------------
스프링을 사용하지 않은 이전의 JDBC 에서는 데이터베이스에 질의를 한 후에 ResultSet을 순환하여
결과를 얻어내야 하는데 스프링은 그 일을 대신 해 준다. -
RowCallbackHandler
-
RowMapperResultReader -> 2.x 버젼부터 RowMapperResultSetExtractor 사용
-
CallableStatementCallback : 저장 프로시저 호출하기
3) DaoSupport
DaoSupport class사용시의 문제점은
MemberDaoImpl, PostDaoImpl, BoardDaoImpl 등의 class가 있다고 하면 JdbcTemplate을 이용하여 구현을 하려고 하면
JdbcTemplate을 설정하는 코드가 각각의 클래스의 Setter 메소드를 이용하여 세팅이 되야하는데, 이것을 중복을 유발합니다.
DAO 클래스마다 중복적으로 발생하는 JdbcTemplate설정을 추상화 계층으로 끌어올려 JdbcDaoSupport Class를 만들어서, Support 클래스는 데이터베이스와의 통신에 사용되는 클래스에 직접적으로 접근할 수 있도록 해줍니다.
JdbcDaoSupport클래스는 Connection 객체를 얻기 위해 getConnection() 메소드를 호출하면 됩니다.
JdbcDaoSupport 클래스를 이용하면 DataSource를 Spring 설정파일에서 매핑시켜주지 않아도 됩니다.
4) Spring의 ORM 프레임워크 지원 기능
- lazy loading : 객체들의 관계 전체를 그대로 얻기 원하지 않을 경우 필요로 하는 데이터만 가져올 수 있도록 해줌
- eager fetching : ( <-> lazy loading) : 하나의 질의로 전체 객체들을 한번에 얻어오는 것
- caching : 주로 읽기만 하는 데이터의 경우 매번 Database에서 가져오기를 원치 않을 때 사용.
- cascading : 제약사항
5) Hibernate와의 연동
Hibernate에서는 SessionFactory를 이용하여 session객체를 생성하는 것이 가장 중요하고,
설정파일에서 SessionFactory를 property로 추가(DataSource)합니다.
6) Caching
Cache 설정파일을 만들고, Spring 설정파일에서 cache 설정파일이 어디있는지 설정해주고,
cache대상과 비울 대상을 메소드로 설정합니다.(XML이나 Annotation으로 설정)
'나만의 작업 > Spring' 카테고리의 다른 글
| [Spring] 스프링에서 VelocityTools 환경설정 (2) | 2008/03/20 |
|---|---|
| [Spring] 스프링 MVC를 이용한 웹 요청 처리 (4) | 2008/03/13 |
| [Spring] Bean과 BeanFactory의 후처리 (8) | 2008/02/12 |
| [Spring] 자동 묶기(Autowire) (2) | 2008/02/12 |
| [Spring] 세터 주입(Setter Injection)의 대안 (5) | 2008/02/05 |
| [Spring] 빈 묶기(Bean wiring) (2) | 2008/02/05 |
| [Spring] 스프링 컨테이너의 두 종류 (0) | 2008/02/05 |
| [Spring] Spring 환경설정 (4) | 2008/01/28 |
| [Spring] Hitting the database (8) | 2007/11/04 |
-
-
-
-
2007/11/07 09:37 [Edit/Del] [Reply]내가 이런데 댓글 안 다는거 알지?
K군 표현에 의하면 전락한 개발자라... ㅋㅋ
타오를때 열심히 해라~ 그래야 MIT도 가고 스탠퍼드도 가고 버클리도 가고 하니까~



싸늘한 날씨에 감기 조심하세요~
저 오늘 예방접종 주사 맞았어요
이제 끄떡없다는..
[NC]...YellOw님두 감기 조심하세요~