是否有一个相当于 Rails Console 的 Phoenix

我正在学习 Phoenix 和 Elixir,我来自 Ruby/Rails,我在 REPL 工作,使用 pry检查我的数据库和应用程序状态。

我正在试图找出如何与我的数据库和模型在凤凰城的应用程序互动。我知道 iex,但我不知道如何使用它检查我的应用程序的数据库从答复。我需要连接到它与 ecto 每次从回复?是否有一个 rails console等价物。我查了凤凰基金会的文件,长生不老药剂量,还有艾克托回收记录,但找不到我要找的东西。我错过了什么吗?

编辑: 基于下面的答案,我找到了 ecto 文档的 这个部分。在此基础上,我可以做类似 ArticlesApi.Repo.all ArticlesApi.Article的东西

21926 次浏览

You can run iex -S mix to run iex with the dependencies in your current mix project included.. You can read about this at http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html

From there you can execute Ecto queries:

iex> MyApp.Repo.all(MyApp.User)

Running iex -S mix phx.server will also start the phoenix server.

For runtime debug, (like byebug or debugger or pry in rails), use

require IEx at the top of your model or controller or views file, then type

IEx.pry to wherever you need it to halt at runtime and continue debugging.

Type h for help inside the console

Most importantly, after all that, restart your server with:

iex -S mix phoenix.server

More info: here

If you're working in development, use iex -S mix phx.server.

If you need into the console of a deployed release, then go to your release directory and run bin/<name of your app> remote_console to open up a remote shell to your app's console.

For me I wanted to run pry inside my Elixir tests. For that your need to prefix your mix test command with iex - S

In full this would be something like

iex -S mix test test/meta_api_web/pages/mutation/update/update_model_test.exs:270