【问题标题】:Erlang boss_db hello world?Erlang boss_db hello world?
【发布时间】:2012-09-07 19:27:30
【问题描述】:

最近我尝试为 Erlang 安装并运行 boss_db ORM 的演示。

这是我所做的:

  • 克隆存储库
  • cd boss_db/
  • rebar get-deps
  • 将一个简单的 mydb.erl 文件放入src/

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

    DBOptions = [{适配器,pgsql}, {db_host, "localhost"}, {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

我在这里做错了什么?它应该如何运行?

附:我也尝试运行 application:start(boss_db),但结果是一样的。

附言我已经阅读了documentation 两次,但我仍然不知道如何运行整个内容。

【问题讨论】:

    标签: postgresql orm erlang erlang-otp rebar


    【解决方案1】:

    您没有将依赖项添加到代码路径。这就是为什么在找不到它们时会引发异常的原因。不要 cd 进入 ebin 和 erl。而是运行

    erl -pa ebin -pa deps/*/ebin
    

    从当前目录。

    顺便说一句,这不是做这类事情的好方法。而是使用 rebar 创建一个新的空应用程序。在 rebar.config 中将 boss_db 作为依赖项添加到您的应用程序。将自己的源文件放在 src 下。然后

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

    【讨论】:

    • cashmere,我用 rebar 创建了一个新的空应用程序,将 boss_db 放入 deps 并编辑了 rebar.config。现在我运行 erl -pa ebin -pa deps/*/ebin,但 code:is_loaded(boss_db) 返回 false。此外,code:is_loaded(myapp) 也返回 false。
    • 您是否先编译了您的应用程序? (rebar get-deps 编译)
    • 嗯,您的应用程序结构是什么样的?我认为如果您不指定 rebar,默认情况下 rebar 会将您的文件命名为 myapp_app 。在控制台上尝试 application:start(myapp)。
    • application:start(myapp) 返回 'ok',但又一次,code:is_loaded 对 boss_db 和 myapp 都返回 false。
    【解决方案2】:
    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
    

    这些步骤对我有用。 code:is_loaded() 在您运行 erl 后将无法正常工作。只有在调用模块时,才会加载代码。

    我确实遇到了应用程序关闭,但这是因为代码正在尝试连接到 Postgres DB 并且无法连接到它

    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}]}]}
    

    【讨论】:

      猜你喜欢
      • 2011-09-29
      • 2011-05-12
      • 2012-01-04
      • 2014-10-15
      • 2023-04-11
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      • 2018-01-15
      相关资源
      最近更新 更多