woylie
Flop 0.29.0 has been released.
Added
- Add
Flop.allowed_fields/2, which returns the fields that may be filtered or
sorted for the given options. - Add
Flop.Schema.flop_schema!/1, which returns the configuration of a schema
module. - Add
Flop.Cursor.get_cursor_from_node/3and
Flop.Cursor.get_cursor_from_edge/3, which take the query options and resolve
a field against the schema given as:for. - Accept an arity-3
cursor_value_func, which also receives the options the
query ran with.
Changed
- Turn
Flop.Schemafrom a protocol into a behaviour. Schemas are configured
withuse Flop.Schemaand the@flop_optionsattribute now. - Take the schema module instead of a struct in
Flop.Schema.field_info/2,
Flop.Schema.get_field/3andFlop.Schema.primary_key/1. - Default
cursor_value_functoFlop.Cursor.get_cursor_from_node/3.
Removed
- Remove
default_limit/1,default_order/1,default_pagination_type/1,
filterable/1,max_filters/1,max_limit/1,pagination_types/1,
sortable/1andtiebreaker/1fromFlop.Schema.
Fixed
- Do not make a module named in an
ecto_typea compile-time dependency of the
schema. - Read a cursor value through the schema given as
:for, so that a field’s
:pathis applied when the query returns plain maps rather than structs.
How to upgrade
Change your code to use Flop.Schema and set the options as @flop_options
instead of using @derive to derive the protocol.
defmodule MyApp.Pet do
use Ecto.Schema
+ use Flop.Schema
- @derive {
- Flop.Schema,
- filterable: [:name, :species],
- sortable: [:name, :age]
- }
+ @flop_options [
+ filterable: [:name, :species],
+ sortable: [:name, :age]
+ ]
schema "pets" do
field :name, :string
field :age, :integer
field :species, :string
end
end
The attribute is read when the module finishes compiling, so it can go anywhere
in the module body. If you use an alias in the options, the alias has to be
declared before the module attribute.
The functions that returned a single schema option are gone. Read the effective
value through Flop.get_option/3, which also applies the backend module and the
application environment, or Flop.allowed_fields/2 for filterable and
sortable, which applies the narrowing a query function may have set:
-Flop.Schema.sortable(%MyApp.Pet{})
+Flop.allowed_fields(:sortable, for: MyApp.Pet)
-Flop.Schema.max_limit(%MyApp.Pet{})
+Flop.get_option(:max_limit, for: MyApp.Pet)
The remaining functions take the schema module instead of a struct:
-Flop.Schema.field_info(%MyApp.Pet{}, :name)
+Flop.Schema.field_info(MyApp.Pet, :name)
-Flop.Schema.get_field(pet, :owner_name)
+Flop.Schema.get_field(MyApp.Pet, pet, :owner_name)
An arity-2 cursor_value_func is still supported. You can use a 3-arity
function if you need the schema or other options passed to Flop, for example if
you need to apply the path option of join or custom fields.
-cursor_value_func: fn item, fields -> Map.take(item, fields) end
+cursor_value_func: fn item, fields, opts ->
+ Map.new(fields, &{&1, Flop.Schema.get_field(opts[:for], item, &1)})
+end
Trending in News & Updates
Other Trending Topics
Latest in /Flop
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










