Skip to content

Instantly share code, notes, and snippets.

View pyzlnar's full-sized avatar

Juan Ramón pyzlnar

  • In front of a monitor
View GitHub Profile
@pyzlnar
pyzlnar / ecto_iex_helpers.ex
Last active September 18, 2023 18:30
A few Ecto helpers that you might want to add to your .iex.exs file. Were created with PSQL in mind
import_if_available(Ecto.Query)
# alias MyApp.Repo
defmodule R do
# Old habits die hard. Take a random of something. You don't care which.
# > R.take(SomeSchema)
def take(schema_or_query) do
schema_or_query
|> limit(1)
|> Repo.one()