Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Phoenix equivalent to Rails Console

I'm just learning Phoenix and Elixir and I'm coming from Ruby/Rails where I work in the REPL using pry to inspect my database and application state.

I'm trying to figure out how to interact with my database and models in a Phoenix app. I'm aware of iex, but I don't know how to use it inspect my app's database from the repl. Do I need to connect to it with ecto each time from the repl? Is there a rails console equivalent. I've checked the Phoenix docs, Elixir Dose, and the Ecto repo, but can't find what I'm looking for. Am I missing something?

Edit: Based on the answer below I found this section of the ecto docs. Based on this I can do something like ArticlesApi.Repo.all ArticlesApi.Article

like image 678
Chase Avatar asked Oct 26 '15 15:10

Chase


People also ask

Is Elixir Phoenix fast?

Phoenix is slightly faster than Gin (Go web framework) so depending on your use case it can be fast :). Obviously one of the primary selling points is OTP/BEAM VM with all the concurrency, HA, soft realtime etc.

How Fast Is Phoenix framework?

Above screenshot shows that the response timings of the index action from Elixir Phoenix application are around 28 ms (in comparison to 58ms in Rails application).


2 Answers

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.

like image 183
Gazler Avatar answered Sep 21 '22 08:09

Gazler


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

like image 21
Devaroop Avatar answered Sep 20 '22 08:09

Devaroop