Skip to content

Commit

Permalink
doctests: Doctests!
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Sep 25, 2024
1 parent c231cfb commit 0a5c2ae
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions lib/notifications/db/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,49 @@ defmodule Notifications.Db.Notification do
`Notifications.Db.Notification`'s and retrieves the Detour's
associated info.
## Example
The `query` parameter defaults to
`Notifications.Db.Notification.Queries.base()`, but can be specified
explicitly
iex> Notifications.Db.Notification.Queries.base()
...> |> Notifications.Db.Notification.Queries.select_detour_info()
...> |> Skate.Repo.all()
[
%Notifications.Db.Notification{
detour: %Notifications.Db.Detour{}
},
%Notifications.Db.Notification{
detour_id: nil,
detour: nil
},
_
]
iex> Notifications.Db.Notification.Queries.select_detour_info()
...> |> Skate.Repo.all()
[
%Notifications.Db.Notification{
detour: %Notifications.Db.Detour{ ... }
},
%Notifications.Db.Notification{
detour_id: nil,
detour: nil
},
_
]
## Examples
There is a `base` query struct that can be provided at the
beginning of a query:
iex> :detour
...> |> insert()
...> |> Notifications.Notification.create_activated_detour_notification_from_detour()
...>
iex> all_detour_notifications =
...> Notifications.Db.Notification.Queries.base()
...> |> Notifications.Db.Notification.Queries.select_detour_info()
...> |> Skate.Repo.all()
...> |> Skate.Repo.preload(:detour)
...>
iex> match?(
...> [
...> %Notifications.Db.Notification{
...> detour: %Notifications.Db.Detour{}
...> }
...> ], all_detour_notifications
...> )
true
If `base` is omitted, then it's inferred:
iex> :detour
...> |> insert()
...> |> Notifications.Notification.create_activated_detour_notification_from_detour()
...>
iex> all_detour_notifications =
...> Notifications.Db.Notification.Queries.select_detour_info()
...> |> Skate.Repo.all()
...> |> Skate.Repo.preload(:detour)
...>
iex> match?(
...> [
...> %Notifications.Db.Notification{
...> detour: %Notifications.Db.Detour{}
...> }
...> ], all_detour_notifications
...> )
true
"""
@spec select_detour_info(Ecto.Query.t()) :: Ecto.Query.t()
Expand Down

0 comments on commit 0a5c2ae

Please sign in to comment.