Skip to content

Commit

Permalink
docs: Clarify the behaviour of Ash.read_first and read_first! by …
Browse files Browse the repository at this point in the history
…adding typespecs (#1722)

I thought that `read_first!` would raise an error in the case of no results found - it won't
  • Loading branch information
sevenseacat authored Jan 19, 2025
1 parent c78d94d commit ca0b9a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2104,8 +2104,10 @@ defmodule Ash do
end

@doc """
Runs an ash query, returning the first result or raise an error. See `read_first/2` for more.
Runs an Ash query, returning the first result or nil, or raising an error. See `read_first/2` for more.
"""
@spec read_first!(resource_or_query :: Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) ::
Ash.Resource.record() | nil
@doc spark_opts: [{1, @read_one_opts_schema}]
def read_first!(query, opts \\ []) do
Ash.Helpers.expect_resource_or_query!(query)
Expand All @@ -2125,6 +2127,8 @@ defmodule Ash do
#{Spark.Options.docs(@read_one_opts_schema)}
"""
@spec read_first(resource_or_query :: Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) ::
{:ok, Ash.Resource.record() | nil} | {:error, Ash.Error.t()}
@doc spark_opts: [{1, @read_one_opts_schema}]
def read_first(query, opts \\ []) do
Ash.Helpers.expect_options!(opts)
Expand Down

0 comments on commit ca0b9a4

Please sign in to comment.