Skip to content

ExploringElixir/TodolistWithSugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todolist

A Todolist web app written with the Elixir Sugar web framework for "Exploring Elixir" tutorial videos.

Assumptions

You'll need to have Erlang and Elixir installed. You'll also need to have Postgres or MySql installed.

Steps I took to set up the project

  • Create your web app with:
mix new todolist --sup
  • Add the Sugar dependency
defp deps do
  [{:sugar, "~> 0.4.10"}]
end
  • Get the Sugar dependencies
mix deps.get
mix compile
  • Initialize the app as a sugar web app
mix sugar.init
  • Configure the router and server port in the config/config.exs file Add the below code to your config/config.exs file
config :sugar,
  router: Todolist.Router

config :sugar, Todolist.Router,
  https_only: false,
  http: [ port: 4000 ],
  https: false
  • Configure your database settings The Ecto library has already been included inside the sugar dependency and so as the postgrex library so it is expected that the database engine you are using is Postgres.

However, the next step will show how to use MySql instead.

In the below code snippet replace the database connection details with yours.

config :todolist, ecto_repos: [Todolist.Repos.Main]

config :todolist, Todolist.Repos.Main,
  adapter: Ecto.Adapters.Postgres,
  database: "todolist",
  username: "postgres",
  password: "asdffdsa",
  hostname: "localhost"
  • Configure your database to use MySql database instead of Postgres In your config/config.exs file, use the below code instead of the one above.

Replace the database connection details with yours.

Notice that the main thing that changed is the adapter.

config :todolist, ecto_repos: [Todolist.Repos.Main]

config :todolist, Todolist.Repos.Main,
  adapter: Ecto.Adapters.MySQL,
  database: "todolist",
  username: "root",
  password: "",
  hostname: "localhost"

In your mix.exs file, your deps should look like this:

Using Postgres

defp deps do
  [{:sugar, "~> 0.4.10"}]
end

Using MySql

defp deps do
  [{:sugar, "~> 0.4.10"},
  {:mariaex, ">= 0.6.0"}]
end

Then run:

mix deps.get
mix compile
  • To create the database from a mix command we do this:
mix ecto.create -r Todolist.Repos.Main
  • To create a database schema migration file for creating the "todo_items" table we do this:
mix ecto.gen.migration todo_items -r Todolist.Repos.Main
  • To run all schema migrations we do this:
mix ecto.migrate -r Todolist.Repos.Main

Steps to run the project

mix deps.get
mix compile
mix server

References

About

A todolist web app written with the Elixir Sugar web framework for "Exploring Elixir" tutorial videos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published