Skip to content

Releases: woylie/flop

0.25.0

14 Jan 01:18
5cb212c
Compare
Choose a tag to compare

Added

  • Added Flop.Filter.update_value/3 for updating the filter value for a field
    in a list of filters.

Fixed

  • Determine pagination type if pagination parameter has errors.

0.24.1

18 Nov 05:38
13a5e02
Compare
Choose a tag to compare

Changed

  • Flop.push_order/3 now allows you to use a descending order as the initial
    sort order.

0.24.0

14 Nov 11:20
46bf7b1
Compare
Choose a tag to compare

Changed

  • If an invalid operator is passed in a filter, the error will now include the
    list of allowed operators for that field.

0.23.0

26 Sep 00:32
37dd91b
Compare
Choose a tag to compare

Added

  • Added directions option to Flop.push_order/3.

Fixed

  • Escape backlash character in queries using one of the like operators.

0.22.1

18 Jul 12:19
e36c3b1
Compare
Choose a tag to compare

Fixed

  • Updated version requirement for Ecto to ~> 3.10.3. Flop 0.22.0 relies
    on a feature added in that version and doesn't compile with lower versions.

0.22.0

17 Jul 06:16
5b40ca8
Compare
Choose a tag to compare

This release includes a substantial refactoring to lay the groundwork for the
upcoming adapter feature. While this release contains deprecations and changes,
they are either backward compatible or affect functions that are unlikely to be
used by end users. The primary aim has been to ensure a seamless transition and
maintain compatibility with previous versions.

Added

  • Added a Flop.FieldInfo struct that contains metadata for a field for use
    by adapters.
  • Added the Flop.Schema.field_info/2 function, which derives field information
    and replaces the previous Flop.Schema.field_type/2 function with a more
    standardized and structured output.

Changed

  • The Ecto-specific options alias_fields, compound_fields, custom_fields,
    and join_fields within Flop.Schema, as well as repo and query_opts
    within use Flop, are now nested under the adapter_opts keyword. The old
    configuration format is still supported.

Deprecated

  • Flop.Schema.field_type/2 was deprecated in favor of
    Flop.Schema.field_info/2.

Removed

  • Removed Flop.Schema.apply_order_by/3.
  • Removed Flop.Schema.cursor_dynamic/3.

Upgrade guide

While the old configuration format is still supported, you are invited to
update your application to the new structure to prepare for future versions.

To do this, place the field configuration for Flop.Schema under
adapter_opts:

@derive {
  Flop.Schema,
  filterable: [],
  sortable: [],
-  alias_fields: [],
-  compound_fields: [],
-  custom_fields: [],
-  join_fields: []
+  adapter_opts: [
+    alias_fields: [],
+    compound_fields: [],
+    custom_fields: [],
+    join_fields: []
+  ]
}

Similarly for use Flop, you can nest repo and query_opts under
adapter_opts:

use Flop,
  default_limit: 50,
-  repo: MyApp.Repo,
-  query_opts: [prefix: "some-prefix"]
+  adapter_opts: [
+    repo: MyApp.Repo,
+    query_opts: [prefix: "some-prefix"]
+  ]

0.21.0

01 Jul 23:19
a5962c0
Compare
Choose a tag to compare

Added

  • Introduced operators as a new option for restricting acceptable operators
    for a custom field.
  • Added bindings option for custom fields, allowing required named bindings to
    be added via Flop.with_named_bindings/4.
  • The ecto_type option on join and custom fields now supports
    references: {:from_schema, MySchema, :some_field}.
  • The ecto_type option now supports a convenient syntax for adhoc enums:
    {:ecto_enum, [:one, :two]}.
  • Improved documentation with added type definitions: t:Flop.Schema.option/0,
    t:Flop.Schema.join_field_option/0, t:Flop.Schema.custom_field_option/0,
    and t:Flop.Schema.ecto_type/0, describing options available when deriving
    the Flop.Schema protocol.

Changed

  • Breaking change: Filter values are now dynamically cast based on the
    field type and operator, instead of allowing any arbitrary filter value. This
    change ensures that invalid filter values cause validation errors instead of
    cast errors.
  • The options for deriving the Flop.Schema protocol and for use Flop
    now undergo stricter validation with NimbleOptions.
  • Flop.Cursor.encode/1 now explicitly sets the minor version option for
    :erlang.term_to_binary/2 to 2, aligning with the new default in OTP 26.
    Before, this option was not set at all.
  • Added a decoded_cursor field to the Flop struct. This field temporarily
    stores the decoded cursor between validation and querying and is
    discarded when generating the meta data.

Deprecated

  • The tuple syntax for defining join fields has been deprecated in favor of a
    keyword list.

Fixed

  • Resolved an issue where setting replace_invalid_params to true still
    caused validation errors for pagination and sorting parameters due to cast
    errors, instead of defaulting to valid parameters.
  • Fixed the type specification for Flop.Filter.allowed_operators/1.

Upgrade notes

The newly implemented dynamic casting of filter values could impact your code:

  • Filter values failing to cast into the determined type will now yield a
    validation error or result in the removal of the invalid filter if the
    replace_invalid_params option is enabled.
  • The value field of the Flop.Filter struct now holds the cast value
    instead of the original parameter value. For instance, while handling
    parameters generated via an HTML form with Flop, previously all filter values
    would be represented as strings in the struct. However, they may now be
    integers, DateTime structs, and so forth. Look out for this if you are
    directly reading or manipulating Flop.Filter structs.
  • For join and custom fields, the type is determined with the ecto_type
    option. Previously, this option was only used for operator validation.
    Ensure the correct Ecto type is set. If the option is omitted, the filter
    values will continue to use their incoming format.
  • Manual casting of filter values in a custom filter function is no longer
    required if the ecto_type option is set.
  • If join fields point to Ecto.Enum fields, previously you could simply set
    ecto_type to string. This will continue to work if the filter value is
    passed as a string, but passing it as an atom will cause an error. Make sure
    to correctly reference the schema field
    ({:from_schema, MySchema, :some_field}) or directly pass the Enum values
    ({:ecto_enum, [:one, :two}).
  • To enable Flop.Phoenix to build a query string for filter parameters, the
    filter value must be convertible into a string via to_string/1. If
    ecto_type is set to a custom Ecto type that casts values into a struct, the
    String.Chars protocol must be implemented for that struct.

Please review the newly added "Ecto type option" section in the Flop.Schema
module documentation.

Join field syntax

If you are using tuples to define join fields when deriving Flop.Schema,
update the configuration to use keyword lists instead:

@derive {
  Flop.Schema,
  join_fields: [
-    owner_name: {:owner, :name}
+    owner_name: [binding: :owner, field: :name]
  ]
}

0.20.3

23 Jun 00:09
0a754a2
Compare
Choose a tag to compare

Changed

  • Flop.count/3 will now wrap queries that have GROUP BY clauses in a
    subquery.

Fixed

  • Fixed cursor-based pagination on composite types.

0.20.2

09 Jun 06:46
4f72005
Compare
Choose a tag to compare

Changed

  • Added nutrition facts about use Flop and @derive Flop.Schema.
  • The minimum Elixir version is now 1.11.

Fixed

  • Fixed a deprecation warning about Logger.warn/1.
  • Fixed a deprecation warning about passing an MFA to :with in
    cast_assoc/cast_embed introduced in Ecto 3.10.2.

0.20.1

19 May 08:27
1150661
Compare
Choose a tag to compare

Added

  • Added the :count override option to Flop.count/3.

Changed

  • The default_pagination_type can now be set in the schema.

Fixed

  • Don't raise function clause error in Flop.to_previous_cursor/1 and
    Flop.to_next_cursor/1 when the start cursor or end cursor are nil.