2022-12-08 14:32:38 +13:00
|
|
|
defmodule AshPostgres.CustomAggregate do
|
2022-12-11 09:59:50 +13:00
|
|
|
@moduledoc """
|
|
|
|
A custom aggregate implementation for ecto.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
The dynamic expression to create the aggregate.
|
|
|
|
|
|
|
|
The binding refers to the resource being aggregated,
|
|
|
|
use `as(^binding)` to reference it.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
Ecto.Query.dynamic(
|
|
|
|
[],
|
|
|
|
fragment("string_agg(?, ?)", field(as(^binding), ^opts[:field]), ^opts[:delimiter])
|
|
|
|
)
|
|
|
|
"""
|
2022-12-08 14:32:38 +13:00
|
|
|
@callback dynamic(opts :: Keyword.t(), binding :: integer) :: Ecto.Query.dynamic()
|
|
|
|
|
|
|
|
defmacro __using__(_) do
|
|
|
|
quote do
|
|
|
|
@behaviour AshPostgres.CustomAggregate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|