Skip to content

Instantly share code, notes, and snippets.

View abadongutierrez's full-sized avatar
💻
working

Rafael Gutiérrez abadongutierrez

💻
working
View GitHub Profile
mix new ecto_test --sup
.
├── README.md
├── config
│ └── config.exs
├── lib
│ └── ecto_test.ex
├── mix.exs
└── test
 ├── ecto_test_test.exs
 └── test_helper.exs
defp deps do
[{:postgrex, ">= 0.0.0"},
{:ecto, "~> 2.0.0"}]
end
def application do
[applications: [:logger, :ecto, :postgrex],
mod: {EctoTest, []}]
end
defmodule EctoTest.Repo do
use Ecto.Repo, otp_app: :ecto_test
end
config :ecto_test, EctoTest.Repo,
adapter: Ecto.Adapters.Postgres,
database: "ecto_test",
username: "postgres",
password: "",
hostname: "localhost"
config :ecto_test, ecto_repos: [EctoTest.Repo]
CREATE TABLE department
(
department_id serial NOT NULL,
name text NOT NULL,
PRIMARY KEY (department_id)
);
CREATE TABLE employee
(
employee_id serial NOT NULL,
def start(_type, _args) do
import Supervisor.Spec, warn: false
# Define workers and child supervisors to be supervised
children = [supervisor(EctoTest.Repo, [])]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: EctoTest.Supervisor]
Supervisor.start_link(children, opts)
alias EctoTest.Repo
import Ecto.Query
Repo.all(from d in "department", select: [d.department_id, d.name])