   def by_developer(username, page) do
     developer = Repo.get_by!(Developer, username: username)
 
-    query = page
-    |> posts
-    |> where([p], p.developer_id == ^developer.id)
+    query =
+      page
+      |> posts
+      |> where([p], p.developer_id == ^developer.id)
 
-    posts_count = Repo.one(from p in "posts",
-      where: p.developer_id == ^developer.id,
-      select: fragment("count(*)")
-    )
+    posts_count =
+      Repo.one(
+        from(
+          p in "posts",
+          where: p.developer_id == ^developer.id,
+          select: fragment("count(*)")
+        )
+      )
 
     {Repo.all(query), posts_count, developer}
   end

  def all(page) do
    page
    |> posts
    |> Repo.all
  end

  def by_channel(channel_name, page) do
    channel = Repo.get_by!(Channel, name: channel_name)

    query = page
    |> posts
    |> where([p], p.channel_id == ^channel.id)

    posts_count = Repo.one(from p in "posts",
      where: p.channel_id == ^channel.id,
      select: fragment("count(*)")
    )

    {Repo.all(query), posts_count, channel}
  end

  def by_developer(username, limit: limit) do
    query = from p in Post,
      order_by: [desc: p.inserted_at],
      join: d in assoc(p, :developer),
      limit: ^limit,
      where: d.username == ^username

    Repo.all(query)
  end

    offset = (page - 1) * Application.get_env(:tilex, :page_size)
    limit = Application.get_env(:tilex, :page_size) + 1

    from(
      p in Post,
      order_by: [desc: p.inserted_at],
      join: c in assoc(p, :channel),
      join: d in assoc(p, :developer),
      preload: [channel: c, developer: d],
      limit: ^limit,
      offset: ^offset
    )
  end
end
