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

Link to this function

all(query \\ base(), opts \\ [])

@spec base() :: Ecto.Query.t()
Link to this function

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)>
Link to this function

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">
Link to this function

find(params \\ [])

Link to this macro

null_or_empty(field)

(macro)
Link to this function

one(query \\ base(), opts \\ [])

Link to this function

order_query(query \\ base(), order)

@spec order_query(
  Ecto.Query.t(),
  keyword()
) :: Ecto.Query.t()
Link to this function

paginate(query, page \\ 1, per_page \\ 100)

@spec paginate(Ecto.Query.t(), integer() | nil, integer() | nil) :: map()
Link to this function

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]]>
Link to this function

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")>
Link to this function

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>
Link to this function

undeleted_query(query \\ base())

@spec undeleted_query(Ecto.Query.t()) :: Ecto.Query.t()
Link to this function

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>
Link to this function

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>