【发布时间】:2015-11-05 16:37:01
【问题描述】:
由于我想连接到 OrientDB,因此我正试图围绕如何在不使用 Ecto 的情况下将 Phoenix 与不同的 DB 驱动程序一起使用。有一个名为 MarcoPolo 的二进制驱动程序,奇怪的是,我能够使用 poolboy 创建一个工作池来连接它——但不仅仅是一个简单的连接。我对 Elixir 还是很陌生。
这就是我所做的:
在 mix.exs 中定义依赖
defp deps do
[{:phoenix, "~> 1.0.3"},
{:phoenix_html, "~> 2.1"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:cowboy, "~> 1.0"},
{:poolboy, "~> 1.5"},
{:marco_polo, "~> 0.2"}
]
end
在 lib/myapp/orientdb_repo.ex 中为我的 repo 创建一个模块
defmodule MyApp.OrientRepo do
use MarcoPolo
end
在 lib/myapp.ex 中定义 worker
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Start the endpoint when the application starts
supervisor(MyApp.Endpoint, []),
# Here you could define other workers and supervisors as children
# worker(MyApp.Worker, [arg1, arg2, arg3]),
worker(MyApp.OrientRepo, [user: "admin", password: "admin", connection: {:db, "database", :graph}])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
但是当我尝试启动服务器时,它告诉我 MarcoPolo 未定义:
== Compilation error on file lib/myapp/orientdb_repo.ex ==
** (UndefinedFunctionError) undefined function: MarcoPolo.__using__/1
MarcoPolo.__using__([])
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8
我认为这应该是可用的,因为我包括了马可波罗。可能这是非常简单的事情,但我就是不明白......
【问题讨论】: