2012-09-14 216 views
2

最近我嘗試安裝並運行Erlang的boss_db ORM演示。erlang boss_db hello world?

這裏是我做過什麼:

  • 克隆庫
  • cd boss_db/
  • rebar get-deps
  • 把一個簡單的mydb.erl文件到src/

    -module(mydb). 
    
    -compile(export_all). 
    
    start() -> 
    

    DBOptions = [{adapte R,pgsql的}, {DB_HOST, 「本地主機」}, {DB_PORT,5432}, {db_username, 「postgres的」}, {DB_PASSWORD 「爲mypass」},
    {cache_enable,FALSE}, {cache_exp_time ,0}],

    boss_db:start(DBOptions)。

  • rebar compile

  • cd ebin/
  • 運行erl
  • mydb:start()

這裏是我得到:

** exception exit: shutdown 

Whatam我做錯了什麼?它應該如何運行?

P.S.我試圖運行應用程序:開始(boss_db),但結果是一樣的。

P.P.S.我已經閱讀了documentation兩次,但我仍然不知道如何運行整個事情。

回答

1
git clone git://github.com/evanmiller/boss_db.git 
cd boss_db/ 
rebar get-deps 
emacs src/mydb.erl 
rebar compile 
erl -pa ./ebin ./deps/*/ebin 

這些步驟爲我工作。在運行erl後,code:is_loaded()將無法​​正常工作。只有當模塊被調用時,代碼纔會被加載。

我確實得到了應用程序關閉,但這是因爲代碼試圖連接到Postgres數據庫並且無法連接到它

Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false] 

Eshell V5.9.2 (abort with ^G) 
1> mydb:start(). 
** exception exit: shutdown 
=ERROR REPORT==== 9-Oct-2012::12:13:07 === 
** Generic server <0.35.0> terminating 
** Last message in was {'EXIT',<0.34.0>, 
         {{badmatch, 
          {error, 
          {{badmatch, 
          {error, 
           {{badmatch,{error,econnrefused}}, 
           [{pgsql_sock,init,1, 
           [{file,"src/pgsql_sock.erl"},{line,51}]}, 
           {gen_server,init_it,6, 
           [{file,"gen_server.erl"},{line,304}]}, 
           {proc_lib,init_p_do_apply,3, 
           [{file,"proc_lib.erl"},{line,227}]}]}}}, 
          [{boss_db_controller,init,1, 
           [{file,"src/boss_db_controller.erl"},{line,31}]}, 
          {gen_server,init_it,6, 
           [{file,"gen_server.erl"},{line,304}]}, 
          {proc_lib,init_p_do_apply,3, 
           [{file,"proc_lib.erl"},{line,227}]}]}}}, 
         [{poolboy,new_worker,2, 
          [{file,"src/poolboy.erl"},{line,348}]}, 
          {poolboy,prepopulate,4, 
          [{file,"src/poolboy.erl"},{line,370}]}, 
          {poolboy,init,2, 
          [{file,"src/poolboy.erl"},{line,74}]}, 
          {gen_fsm,init_it,6, 
          [{file,"gen_fsm.erl"},{line,361}]}, 
          {proc_lib,init_p_do_apply,3, 
          [{file,"proc_lib.erl"},{line,227}]}]}} 
** When Server state == {state, 
          {<0.35.0>,poolboy_sup}, 
          simple_one_for_one, 
          [{child,undefined,boss_db_controller, 
           {boss_db_controller,start_link, 
            [[{size,5}, 
             {max_overflow,10}, 
             {adapter,pgsql}, 
             {db_host,"localhost"}, 
             {db_port,5432}, 
             {db_username,"postgres"}, 
             {db_password,"mypass"}, 
             {cache_enable,false}, 
             {cache_exp_time,0}]]}, 
           temporary,brutal_kill,worker, 
           [boss_db_controller]}], 
          {set,0,16,16,8,80,48, 
           {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[], 
           []}, 
           {{[],[],[],[],[],[],[],[],[],[],[],[],[],[], 
            [],[]}}}, 
          0,1,[],poolboy_sup, 
          {boss_db_controller, 
           [{size,5}, 
           {max_overflow,10}, 
           {adapter,pgsql}, 
           {db_host,"localhost"}, 
           {db_port,5432}, 
           {db_username,"postgres"}, 
           {db_password,"mypass"}, 
           {cache_enable,false}, 
           {cache_exp_time,0}]}} 
** Reason for termination == 
** {{badmatch, 
     {error, 
      {{badmatch, 
       {error, 
        {{badmatch,{error,econnrefused}}, 
         [{pgsql_sock,init,1, 
          [{file,"src/pgsql_sock.erl"},{line,51}]}, 
         {gen_server,init_it,6, 
          [{file,"gen_server.erl"},{line,304}]}, 
         {proc_lib,init_p_do_apply,3, 
          [{file,"proc_lib.erl"},{line,227}]}]}}}, 
      [{boss_db_controller,init,1, 
        [{file,"src/boss_db_controller.erl"},{line,31}]}, 
       {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]}, 
       {proc_lib,init_p_do_apply,3, 
        [{file,"proc_lib.erl"},{line,227}]}]}}}, 
    [{poolboy,new_worker,2,[{file,"src/poolboy.erl"},{line,348}]}, 
    {poolboy,prepopulate,4,[{file,"src/poolboy.erl"},{line,370}]}, 
    {poolboy,init,2,[{file,"src/poolboy.erl"},{line,74}]}, 
    {gen_fsm,init_it,6,[{file,"gen_fsm.erl"},{line,361}]}, 
    {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]} 
+0

適合我,謝謝! – skanatek

2

您沒有向代碼路徑添加依賴項。這就是爲什麼當找不到它們時拋出異常。不要cd進入ebin和erl。反而從當前目錄運行

erl -pa ebin -pa deps/*/ebin 

順便說一句,這不是一個很好的方式來做這種東西。請使用螺紋鋼創建一個新的空應用程序。將reboss.config中的boss_db作爲依賴項添加到您的應用程序中。把你自己的源文件放在src下。然後

rebar get-deps compile 
erl -pa ebin -pa deps/*/ebin 
+0

羊絨,我用螺紋鋼創建了一個新的空應用程序,把boss_db放到了deps並編輯了rebar.config。現在我運行erl -pa ebin -pa deps/*/ebin,但是代碼:is_loaded(boss_db)返回false。而且,代碼:is_loaded(myapp)也返回false。 – skanatek

+0

您是否先編譯您的應用程序? (rebar get-deps編譯) – cashmere

+0

當然我編譯它! – skanatek