This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
supervisor(Ecto101MigrationsSchemas.Repo, []) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Repo do | |
use Ecto.Repo, otp_app: :ecto_101_migrations_schemas | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Mixfile do | |
use Mix.Project | |
# ... | |
def application do | |
[applications: [:logger, :ecto, :postgrex], | |
mod: {Ecto101MigrationsSchemas, []}] | |
end | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Mixfile do | |
use Mix.Project | |
# ... | |
defp deps do | |
[{:postgrex, "~> 0.13.3"}, | |
{:ecto, "~> 2.1.4"}] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Employee do | |
use Ecto.Schema | |
schema "employee" do | |
field :first_name, :string | |
field :last_name, :string | |
field :hire_date, :date | |
belongs_to :department, Ecto101MigrationsSchemas.Department |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Department do | |
use Ecto.Schema | |
schema "department" do | |
field :name, :string | |
has_many :employees, Ecto101MigrationsSchemas.Employee | |
timestamps() | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule User do | |
defstruct name: "John", last_name "Smith", age: 32 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Repo.Migrations.EmployeeTable do | |
use Ecto.Migration | |
def change do | |
create table(:employee) do | |
add :first_name, :text, null: false | |
add :last_name, :text, null: false | |
add :hire_date, :date, null: false | |
add :department_id, | |
references(:department, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ecto101MigrationsSchemas.Repo.Migrations.DepartmentTable do | |
use Ecto.Migration | |
def change do | |
create table(:department) do | |
add :name, :text, null: false | |
timestamps() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Repo.all(from e in "employee", | |
select: [e.employee_id, e.first_name, e.last_name]) |