2014: 99 attendees
2015: 257 attendees
(or, the data structure for the apocalypse)
https://github.com/pfraze/crdt_notes
defmodule MyApp.Post do
use Ecto.Model
import Ecto.Query
schema "posts" do
field :body, :string
field :published, :boolean
field :published_at, :datetime
field :title, :string
has_many :comments, MyApp.Comment
end
end
MyApp.Comment
|> join(:left, [c], p in assoc(c, :post))
|> where([_, p], p.id == 1)
|> select([c, _], c)
|> MyApp.Repo.all
def published(query) do
from p in query,
where: p.published == true
end
def sorted(query) do
from p in query,
order_by: [desc: p.published_at]
end
def for_post(query, post) do
from c in query,
join: p in assoc(c, :post)
where: p.id == ^post.id
end
def popular(query) do
query |> where([c], c.votes > 10)
end
alias MyApp.Post
alias MyApp.Comment
published_posts = Post
|> Post.published
|> MyApp.Repo.all
last_post = Post
|> Post.published
|> Post.sorted
|> MyApp.Repo.one
recent_popular_comments = Comment
|> Comment.for_post(last_post)
|> Comment.popular
|> MyApp.Repo.all