== erlhive ==
사용자 커뮤니티 구축을 돕는 얼랭 프레임워크
퍼시스턴트에 mnesia를 사용한다
http://erlhive.sourceforge.net
따라해보기
~ $ svn checkout http://erlhive.svn.sourceforge.net/svnroot/erlhive/trunk/lib/erlhive
erlhive
~ $ cd erlhive/
~/erlhive $ ls
CHANGE_LOG TODO USER_GUIDE ebin src
Makefile TYPE_GRAMMAR dbspec examples temp
~/erlhive $ make
~/erlhive $ erl -pa ebin
Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0]
[kernel-poll:false]
Eshell V5.5.3 (abort with ^G)
1> erlhive:run_this_once().
true
2> mnesia:start().
ok
3> erlhive:admin(fun(M)-> M:list_users() end).
[<<"guest">>,<<"root">>]
4> erlhive:admin(fun(M)-> M:create_user(<<"wookay">>, []) end).
true
5> erlhive:admin(fun(M)-> M:list_users() end).
[<<"guest">>,<<"root">>,<<"wookay">>]
6> erlhive:with_user(<<"wookay">>, fun(M)-> M:create_variable(name,
[]) end).
true
7> erlhive:with_user(<<"wookay">>, fun(M)-> M:list_variables() end).
[name]
8> erlhive:with_user(<<"wookay">>, fun(M)-> M:store_obj(name, "woo-
kyoung") end).
true
9> erlhive:with_user(<<"wookay">>, fun(M)-> M:get_obj(name) end).
"woo-kyoung"
10>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
다시 실행해 보면
~/erlhive $ erl -pa ebin
Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0]
[kernel-poll:false]
Eshell V5.5.3 (abort with ^G)
1> mnesia:start().
ok
2> erlhive:with_user(<<"wookay">>, fun(M)-> M:get_obj(name) end).
"woo-kyoung"
== couchdb ==
얼랭으로 만든 Document Based Database.
http://couchdb.com
따라해보기
~/build $ svn checkout http://couchdb.googlecode.com/svn/trunk/
couchdb
~/build $ cd couchdb/
~/build/couchdb $ cd CouchProjects/
~/build/couchdb/CouchProjects $ ls
Clients Emakefile Lucene build.sh
make_win_kit.cmd
CouchDb Fabric Makefile build_couch.erl
version
CouchDb.sln FabricServer ReadMe.txt couch_inets
Demos Libraries bintools dist
빌드 전 Makefile을 열어 패스 설정
~/build/couchdb/CouchProjects $ ./build.sh
CouchDb has been built successfully!
~/build/couchdb/CouchProjects $ ./build.sh --install=/Users/wookay/
couchdb
~/build/couchdb/CouchProjects $ cd
~ $ cd couchdb/
~/couchdb $ ls
bin couch.ini db_root logs
boot couch_httpd.conf ht_utils readme.txt
conf couchdb lib
~/couchdb $ ./bin/startCouchDb.sh
Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0]
[kernel-poll:false]
couch 0.6.4 (LogLevel=info)
CouchDb is starting
CouchDb has started. Time to Relax.
Eshell V5.5.3 (abort with ^G)
시작하면 8888에 웹서버도 띄워진다
http://localhost:8888/
자. 그럼 REST 방식으로 데이터베이스를 만들어보자.
~ $ telnet localhost 8888
Trying ::1...
Connected to localhost.
Escape character is '^]'.
PUT /test HTTP/1.0
HTTP/1.0 201 Created
Server: inets/develop
Date: Tue, 28 Aug 2007 07:58:55 GMT
Cache-Control: no-cache
Pragma: no-cache
Expires: Tue, 28 Aug 2007 07:58:55 GMT
Damien: awesome
Content-Type: application/xml; charset=utf-8
Connection: close
<?xml version="1.0"?><success/>Connection closed by foreign host.
잘 되는군하.
이제 문서를 만들어 봐야하는데 일단 간단히 php를 이용해보자
서브버전으로 받은 소스에 관련 라이브러리가 포함되어 있는데 압축이 되어 있으므로 일단 푼다
~ $ cd ~/build/couchdb/CouchProjects/Libraries
~/build/couchdb/CouchProjects/Libraries $ ls
CouchDb-C-Library.tar.gz c sample.php
CouchDb-PHP-Library.tar.gz php
~/build/couchdb/CouchProjects/Libraries $ tar xvzf CouchDb-PHP-
Library.tar.gz
~/build/couchdb/CouchProjects/Libraries $ cd CouchDb-PHP-Library
~/build/couchdb/CouchProjects/Libraries/CouchDb-PHP-Library $ ls
CouchDb Library Net_URL Tests
HTTP_Request Net_Socket PEAR
여기에 다음과 같은 내용의 sample.php 파일을 만들어 보자
<?php
include "CouchDb/Couch.php";
$server = "localhost";
$database = "test";
$couch = new Couch($server, $database);
$doc = new CouchDocument;
$doc->set("title", "hola");
$docId = $couch->save($doc);
echo $docId;
?>
실행하면
~/build/couchdb/CouchProjects/Libraries/CouchDb-PHP-Library $ php
sample.php
D5C07F53F013D5CB35A465C899F4FB79
브라우저에서 확인해보자
http://localhost:8888/test/D5C07F53F013D5CB35A465C899F4FB79
왠지 REST에 익숙해질 것 같은 느낌. 상큼하도다