Created
July 29, 2014 20:02
-
-
Save dgoldie/552748ac422a8651bc5b to your computer and use it in GitHub Desktop.
Ecto first try
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 EctoTest.Repo.Migrations.CreateDweet do | |
use Ecto.Migration | |
def up do | |
"CREATE TABLE dweets(id serial primary key, content varchar(140), author varchar(50))" | |
end | |
def down do | |
"DROP TABLE dweets" | |
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 EctoTest.Dweet do | |
use Ecto.Model | |
schema "dweets" do | |
field :content, :string | |
field :author, :string | |
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 EctoTest.Mixfile do | |
use Mix.Project | |
def project do | |
[app: :ecto_test, | |
version: "0.0.1", | |
elixir: "~> 0.14.3", | |
deps: deps] | |
end | |
# Configuration for the OTP application | |
# | |
# Type `mix help compile.app` for more information | |
def application do | |
[applications: []] | |
end | |
# Dependencies can be hex.pm packages: | |
# | |
# {:mydep, "~> 0.3.0"} | |
# | |
# Or git/path repositories: | |
# | |
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1"} | |
# | |
# Type `mix help deps` for more examples and options | |
defp deps do | |
[ | |
{ :postgrex, "~> 0.5.3" }, | |
# { :ecto, github: "elixir-lang/ecto" } | |
{ :ecto, "~> 0.2.2" } | |
] | |
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 EctoTest.Repo do | |
use Ecto.Repo, adapter: Ecto.Adapters.Postgres | |
def url do | |
"ecto://postgres:postgres@localhost/ecto_test" | |
end | |
def priv do | |
app_dir(:ecto_test, "priv/repo") | |
end | |
def conf do | |
parse_url "ecto://postgres:postgres@localhost/ecto_test" | |
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 EctoTest.Supervisor do | |
use Supervisor | |
def start_link do | |
:supervisor.start_link(__MODULE__, []) | |
end | |
def init([]) do | |
children = [ | |
worker(EctoTest.Repo, []) | |
] | |
# See http://elixir-lang.org/docs/stable/Supervisor.Behaviour.html | |
# for other strategies and supported options | |
supervise(children, strategy: :one_for_one) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment