To create new projects:
mix new kv
mix new kv --module KV
To load iex with mix project files:
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, |
defmodule User do | |
defstruct name: "John", last_name "Smith", age: 32 | |
end |
defmodule Ecto101MigrationsSchemas.Department do | |
use Ecto.Schema | |
schema "department" do | |
field :name, :string | |
has_many :employees, Ecto101MigrationsSchemas.Employee | |
timestamps() | |
end |
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 |
defmodule Ecto101MigrationsSchemas.Mixfile do | |
use Mix.Project | |
# ... | |
defp deps do | |
[{:postgrex, "~> 0.13.3"}, | |
{:ecto, "~> 2.1.4"}] | |
end | |
end |
defmodule Ecto101MigrationsSchemas.Mixfile do | |
use Mix.Project | |
# ... | |
def application do | |
[applications: [:logger, :ecto, :postgrex], | |
mod: {Ecto101MigrationsSchemas, []}] | |
end | |
# ... |
defmodule Ecto101MigrationsSchemas.Repo do | |
use Ecto.Repo, otp_app: :ecto_101_migrations_schemas | |
end |
defmodule Ecto101MigrationsSchemas do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
supervisor(Ecto101MigrationsSchemas.Repo, []) | |
] |
use Mix.Config | |
# ... | |
config :ecto_101_migrations_schemas, Ecto101MigrationsSchemas.Repo, | |
adapter: Ecto.Adapters.Postgres, | |
database: "ecto_test", | |
username: "postgres", | |
password: "", | |
hostname: "localhost" | |
config :ecto_101_migrations_schemas, ecto_repos: [Ecto101MigrationsSchemas.Repo] |
To create new projects:
mix new kv
mix new kv --module KV
To load iex with mix project files: