Releases: woylie/flop
Releases · woylie/flop
0.17.1
0.17.0
Added
- Added the filter operators
not_in
andnot_contains
. - Added examples for integration with Relay to the documentation.
- Added examples for the parameter format to the documentation.
Changed
- Refactored the query builder. This does not affect users of the library, but
makes the code base more readable and lays the groundwork for upcoming
features. - Added the
:query_opts
option to Flop callbacks to pass on options to the
Ecto repo on query execution. If you are already using the:prefix
option
you now have to pass this through:query_opts
.
If you configured the Repo :prefix
in the application config:
config :flop,
- prefix: "some-prefix"
+ query_opts: [prefix: "some-prefix"]
If you set the :prefix
when calling the Flop functions:
- Flop.validate_and_run(Pet, params, prefix: "some-prefix")
+ Flop.validate_and_run(Pet, params, query_opts: [prefix: "some-prefix"])
0.16.1
0.16.0
Added
- You can now define a configuration module with
use Flop
to set defaults
instead of or in addition to the application configuration. This makes it
easier to work with multiple Ecto repos. - The new function
Flop.bindings/3
returns the necessary bindings for a
given Flop query. You can use it in case you want to optimize your queries by
only joining tables that are actually needed. - Added a
count_query
option to override the count query used by
Flop.run/3
,Flop.validate_and_run/3
andFlop.validate_and_run!/3
. - You can get a list of allowed operators for a given Ecto type or a given
schema field withFlop.Filter.allowed_operators/1
and
Flop.Filter.allowed_operators/2
now.
Changed
- Breaking: The
:empty
and:not_empty
filters now require a boolean value.
If no value is passed, the filter is ignored, just as it is handled for all
other filter operators. This change was necessary to make the integration
with filter forms (checkboxes) easier. - Breaking: The default order needs to be passed as a map now when deriving
Flop.Schema
. The previous implementation already converted the two separate
configuration keys to a map. This meant that the configuration passed when
derivingFlop.Schema
had a different format from the one you had to pass
when overriding the default order with theopts
.
With this change, the configuration format is the same everywhere. A compile
time exception is raised if you are still using the old format, guiding you in
the update. - It is now validated that the filter operator matches the field type.
- The compile time validation of the options passed when deriving
Flop.Schema
has been improved. - Allow passing page as string to
Flop.set_page/2
. - Allow passing offset as string to
Flop.set_offset/2
.
0.15.0
Added
- Add
Flop.reset_filters/1
andFlop.reset_order/1
. - Add
Flop.current_order/2
to retrieve the order of a given field. - Add
Flop.to_next_page/2
andFlop.to_previous_page/1
. - Add
Flop.set_cursor/2
,Flop.to_next_cursor/1
and
Flop.to_previous_cursor/1
. - Add
Flop.set_offset/2
,Flop.to_previous_offset/1
,Flop.to_next_offset_2
andFlop.reset_cursors/2
. - Add
Flop.nest_filters/3
for converting filters between a key/value map and
a list ofFlop.Filter
parameters. - You can now set the
default_pagination_type
option, which forces a certain
set of parameters when defaults are applied and the pagination type cannot
be determined from the given parameters. - Add optional
default
argument toget_option
. - Add
pagination
option. If set totrue
, pagination parameters are not cast.
Changed
Flop.map_to_filter_params/2
returns maps with string keys if the original
map has string keys now.- The
has_previous_page?
value of theFlop.Meta
struct is now alwaystrue
iffirst
is used withafter
.has_next_page?
is alwaystrue
when
last
is used withbefore
. push_order/2
resets the:after
and:before
parameters now, since the
cursors depend on the order.validate_and_run/3
andvalidate_and_run!/3
pass all given options to
the validate functions now, allowing you to override defaults set in the
schema.- If the
pagination_types
option is used, parameters for other pagination
types will not be cast now instead of casting them and returning validation
errors.
Removed
- Remove
Flop.Cursor.get_cursor_from_map/2
. Use
Flop.Cursor.get_cursor_from_node/2
instead.
0.14.0
Added
- Add
:contains
operator. - Add
Flop.map_to_filter_params/2
.
Changed
Flop.validate/2
andFlop.validate_and_run/3
return{:error, Flop.Meta.t}
instead of{:error, Ecto.Changeset.t}
now. The Meta struct has the new
fields:errors
and:params
, which are set when validation errors occur.
This accompanies the changes inFlop.Phoenix
, which include the
implementation of thePhoenix.HTML.FormData
protocol for theFlop.Meta
struct.Flop.validate!/2
andFlop.validate_and_run!/3
raise a
Flop.InvalidParamsError
instead of anEcto.InvalidChangesetError
now.- Add
:schema
key toFlop.Meta
. This field points to the schema module set
by passing the:for
option. - Minimum Ecto version changed to 3.5.
- Replace
Operator
andOrderDirection
custom Ecto types with Ecto.Enum. - Update
Flop.Meta
struct default values for the fields:flop
,
:has_next_page?
and:has_previous_page?
.
0.13.2
0.13.1
0.13.0
Added
- Support ordering by join fields.
- Support ordering by compound fields.
- Support join fields as cursor fields.
- New function
Flop.Schema.get_field/2
. Flop.Cursor.get_cursor_from_edge/2
andFlop.Cursor.get_cursor_from_node/2
can get cursor values from join and compound fields now.
Changed
To get the pagination cursor value from a join field, Flop needs to know how
to access the field value from the returned struct or map. The configuration
format for join fields has been changed to allow specifying the path to the
nested field.
Before:
@derive {
Flop.Schema,
join_fields: [
owner_name: {:owner, :name}
]
}
After:
@derive {
Flop.Schema,
join_fields: [
owner_name: [binding: :owner, field: :name, path: [:owner, :name]]
]
}
The :path
is optional and inferred from the :binding
and :field
options,
if omitted.
The old configuration format is still accepted. All of these settings are
equivalent:
[owner_name: {:owner, :name}]
[owner_name: [binding: :owner, field: :name]]
[owner_name: [binding: :owner, field: :name, path: [:owner, :name]]]
Fixed
- Cursor pagination failed when one of the cursor field values was
nil
.
0.12.0
Added
- Allow to define join fields in
Flop.Schema
. - Allow to define compound fields in
Flop.Schema
. - Support filtering by join fields.
- Support filtering by compound fields.
- New filter operator
empty
. - New filter operator
not_empty
.
Changed
- Rename option
get_cursor_value_func
tocursor_value_func
. - Silently ignore filters with
nil
value for the field or the value instead of
raising anArgumentError
.