Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
Last active January 29, 2016 08:37
Show Gist options
  • Save andreaseriksson/f5dd607464f5929b187f to your computer and use it in GitHub Desktop.
Save andreaseriksson/f5dd607464f5929b187f to your computer and use it in GitHub Desktop.

http://www.glydergun.com/diving-into-ecto-part-2/

http://kholbekj.surge.sh/2016/01/06/convenience-queires-with-ecto.html

Another dynamic query builder using ecto

https://groups.google.com/forum/#!topic/elixir-ecto/uxUKfqm8jLQ

Repo.get_by(Fisherman, name: "Lew")

account = Repo.one(from a in Account, order_by: [desc: a.id], limit: 1)

Store in a model

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

last_post = Post |> Post.published |> Post.sorted |> MyApp.Repo.one

Ecto.Adapters.SQL.query(Repo, "SELECT count(1) FROM users", [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment