DEV Community

Risyad Rais Rafsanjani
Risyad Rais Rafsanjani

Posted on

Using SQLite with Ecto in a Phoenix App

Phoenix (or Ecto) defaults PostgreSQL as their database of choice. What if you just want to do something simple or just start learning Phoenix and too lazy to set up a Postgres server (like me)?

After setting up your Erlang and Elixir in your machine, you need to install hex. If you haven't had it installed, run this:

mix local.hex
Enter fullscreen mode Exit fullscreen mode

Then you need to install Phoenix application generator:

mix archive.install hex phx_new
Enter fullscreen mode Exit fullscreen mode

To kick start your Phoenix project, run this line:

mix phx.new sqlite_app --database sqlite3
Enter fullscreen mode Exit fullscreen mode

Now you're ready to develop your next awesome Phoenix project with SQLite.

What Happened?

The --database flag tells the generator that we want to use SQLite in our project and added ecto_sqlite3 as a dependency so we can use it with Ecto.

Actually, Phoenix is well documented (and from what I heard, Elixir projects are generally well documented). You can find most of what you want to do when kickstarting your Phoenix project in this hexdocs page.

Now run:

mix ecto.create
Enter fullscreen mode Exit fullscreen mode

to create your SQLite database file in your project direcory.

I hope this helps and hope you have some fun times ahead!

Top comments (4)

Collapse
 
ukd1 profile image
Russell Smith

Thanks; I'm learning Elixir, and wanted something less than Postgres.

Collapse
 
atmorojo profile image
Risyad Rais Rafsanjani

Same here! I was just trying to learn Phoenix. Setting up a Postgres for it feels like a lot of commitment.

Collapse
 
tylerlwsmith profile image
Tyler Smith

Thanks! I couldn't find this easily in the docs.

Collapse
 
tochu_cha profile image
K. M.

Thanx!