Kanta.Translations.Messages.Finders.GetMessage (kanta v0.4.2)
Query module aka Finder responsible for finding gettext message
Summary
Functions
Counts resources by specific column.
Filters given resource by specific criterias. Filters should be pass to the function as map %{"field_name" => filter_value}
.
It supports associations: %{"association" => %{"field_name" => filter_value}}
and nested associations %{"association" => %{"nested association" => %{"field_name" => filter_value}}}
Preloads resources for given resource.
Search for rows by given text.
Select specific one column from resource.
Returns unique resources.
Joins resource with another resource.
Functions
all(query \\ base(), opts \\ [])
base()
@spec base() :: Ecto.Query.t()
count(query \\ base(), column)
@spec count(Ecto.Query.t(), atom()) :: Ecto.Query.t()
Counts resources by specific column.
Examples
iex> Kanta.Accounts.UserQueries.count(:email)
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user,
select: count(u0.email)>
filter_query(query \\ base(), filters)
@spec filter_query(Ecto.Query.t(), map() | keyword() | nil) :: Ecto.Query.t()
Filters given resource by specific criterias. Filters should be pass to the function as map %{"field_name" => filter_value}
.
It supports associations: %{"association" => %{"field_name" => filter_value}}
and nested associations %{"association" => %{"nested association" => %{"field_name" => filter_value}}}
Examples
iex> Kanta.Accounts.UserQueries.filter_query(%{"email" => "a@a.com"})
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user, where: u0.email == ^"a@a.com">
find(params \\ [])
one(query \\ base(), opts \\ [])
order_query(query \\ base(), order)
@spec order_query( Ecto.Query.t(), keyword() ) :: Ecto.Query.t()
paginate(query, page \\ 1, per_page \\ 100)
@spec paginate(Ecto.Query.t(), integer() | nil, integer() | nil) :: map()
preload_resources(query \\ base(), preloads)
@spec preload_resources( Ecto.Query.t(), keyword() ) :: Ecto.Query.t()
Preloads resources for given resource.
Examples
iex> Kanta.Accounts.UserQueries.preload_resources(:articles)
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user,
preload: [[:articles]]>
search_query(query \\ base(), search)
@spec search_query(Ecto.Query.t(), any()) :: Ecto.Query.t()
Search for rows by given text.
Examples
iex> Kanta.Accounts.UserQueries.search_query("some text")
#Ecto.Query<from u0 in Kanta.Accounts.User, where: fragment("to_tsvector(?::text) @@ plainto_tsquery(?)", u0, ^"some text")>
select_column(query \\ base(), column)
@spec select_column(Ecto.Query.t(), atom()) :: Ecto.Query.t()
Select specific one column from resource.
Examples
iex> Kanta.Accounts.UserQueries.select_column(:email)
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user, select: u0.email>
undeleted_query(query \\ base())
@spec undeleted_query(Ecto.Query.t()) :: Ecto.Query.t()
unique(query \\ base(), column \\ true)
Returns unique resources.
Examples
iex> Kanta.Accounts.UserQueries.unique()
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user, distinct: true>
with_join(query \\ base(), resource_name, opts \\ [])
@spec with_join(Ecto.Query.t(), atom(), keyword()) :: Ecto.Query.t()
Joins resource with another resource.
Important! The joining has to be defined by join_resource/3 function. Example:
defp join_resource(query, :articles, opts) do
query
|> join(:left, [user: u], _ in assoc(u, :articles), as: :article)
end
First argument is a query and second argument is pattern-matched atom.
Examples
iex> Kanta.Accounts.UserQueries.with_join(:articles)
#Ecto.Query<from u0 in Kanta.Accounts.User, as: :user,
left_join: u1 in assoc(u0, :articles), as: :article>