Flop.Phoenix.to_query

You're seeing just the function to_query, go back to Flop.Phoenix module for more information.
Link to this function

to_query(flop)

View Source (since 0.6.0)

Specs

to_query(Flop.t()) :: keyword()

Converts a Flop struct into a keyword list that can be used as a query with Phoenix route helper functions.

Examples

iex> to_query(%Flop{})
[]

iex> f = %Flop{order_by: [:name, :age], order_directions: [:desc, :asc]}
iex> to_query(f)
[order_directions: [:desc, :asc], order_by: [:name, :age]]
iex> f |> to_query |> Plug.Conn.Query.encode()
"order_directions[]=desc&order_directions[]=asc&order_by[]=name&order_by[]=age"

iex> f = %Flop{page: 5, page_size: 20}
iex> to_query(f)
[page_size: 20, page: 5]

iex> f = %Flop{first: 20, after: "g3QAAAABZAAEbmFtZW0AAAAFQXBwbGU="}
iex> to_query(f)
[first: 20, after: "g3QAAAABZAAEbmFtZW0AAAAFQXBwbGU="]

iex> f = %Flop{
...>   filters: [
...>     %Flop.Filter{field: :name, op: :=~, value: "Mag"},
...>     %Flop.Filter{field: :age, op: :>, value: 25}
...>   ]
...> }
iex> to_query(f)
[
  filters: %{
    0 => %{field: :name, op: :=~, value: "Mag"},
    1 => %{field: :age, op: :>, value: 25}
  }
]
iex> f |> to_query() |> Plug.Conn.Query.encode()
"filters[0][field]=name&filters[0][op]=%3D~&filters[0][value]=Mag&filters[1][field]=age&filters[1][op]=%3E&filters[1][value]=25"