Database lib/DSL currently targeting PostgreSQL.
Some thoughts and ideas on best practices building Ember apps after 2 years building and maintaining 6+ apps. This is less about the obvious best practices, like use ember-cli, and more along the lines of when to use what technique. As with every best practice there are exceptions to every rule.
This file contains 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
defp execute_in_direction(repo, :forward, level, {:create_if_not_exists, %Index{}=index}) do | |
if !repo.adapter.ddl_exists?(repo, index, @opts) do | |
repo.adapter.execute_ddl(repo, {:create, index}, @opts) | |
end | |
end | |
defp execute_in_direction(repo, :backward, level, {:drop_if_exists, %Index{}=index}) do | |
if !repo.adapter.ddl_exists?(repo, index, @opts) do | |
repo.adapter.execute_ddl(repo, {:create, index}, @opts) | |
end |
This file contains 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 | |
use Ecto.Model | |
schema "users" do | |
field :email, :string | |
field :hashed_password, :string | |
field :password, :string, virtual: true | |
field :password_confirmation, virtual: true | |
timestamps |
This file contains 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
# config/config.ex | |
config :app, App.Repo, | |
database: "my_app_dev", | |
username: "postgres", | |
password: "nope", | |
hostname: "localhost", | |
extensions: [{Extensions.Json, library: Poison}] |
This file contains 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 Extensions.JSON do | |
alias Postgrex.TypeInfo | |
@behaviour Postgrex.Extension | |
@json ["json", "jsonb"] | |
def init(_parameters, opts), | |
do: Keyword.fetch!(opts, :library) | |
def matching(_library), |
This file contains 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
# Generated with mix ecto.gen.migration add_user_settings_and_address | |
defmodule App.Repo.Migrations.AddUserSettingsAndAddress do | |
use Ecto.Migration | |
def change do | |
alter table(:users) do | |
add :settings, :json | |
add :addresses, :json | |
end | |
end |
This file contains 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 App.Models.User do | |
use Ecto.Model | |
schema "users" do | |
field :email, :string | |
field :crypted_pass, :string | |
field :settings, App.Models.Settings.Type | |
field :addresses, App.Models.Address.Type | |
timestamps |
This file contains 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 App.Models.Settings do | |
defstruct [ | |
newsletter: false, | |
publish_profile: true, | |
email_notifications: true | |
] | |
defmodule Type do | |
@behaviour Ecto.Type | |
alias App.Models.Settings |
This file contains 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 App.Models.Address do | |
defstruct [:address, :address2, :city, :region, :postal, :country] | |
defmodule Type do | |
@behaviour Ecto.Type | |
alias App.Models.Address | |
def type, do: :json | |
def cast(addrs) when is_list(addrs) do |