woylie

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/3 and
    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.Schema from a protocol into a behaviour. Schemas are configured
    with use Flop.Schema and the @flop_options attribute now.
  • Take the schema module instead of a struct in Flop.Schema.field_info/2,
    Flop.Schema.get_field/3 and Flop.Schema.primary_key/1.
  • Default cursor_value_func to Flop.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/1 and tiebreaker/1 from Flop.Schema.

Fixed

  • Do not make a module named in an ecto_type a compile-time dependency of the
    schema.
  • Read a cursor value through the schema given as :for, so that a field’s
    :path is 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

Where Next? Top

Trending in News & Updates Top

mat-hek
Popcorn, the library that runs Elixir code in the browser, is now stable :popcorn: This is possible because it now builds on a very stab...
New
danj
Some root certs are compromised, updates are needed to maintain TLS security. As reported by Mozilla the eMudhra intermediate CA privat...
New
mandar1045
Stampede 1.2 is out, and I finally got to try it at a bigger scale. What’s new --find-limit: instead of a fixed number of users, it add...
New
bartblast
Hologram v0.12.1 has been released. Bug Fixes Fix the browser painting a frame between an action and a next action it puts with no dela...
New
bartblast
I talk to a lot of people in the Elixir community, and most of them already know about Hologram. But before they give it a try they want ...
New
mikehostetler
ReqLLM v1.29.0 has been released. Security update ReqLLM 1.29.0 fixes GHSA-6vww-5m28-f26v. Versions 1.9.0 through 1.28.0 did not verify ...
New
woylie
Flop 0.29.1 has been released. Fixed Fall back to the field name when a cursor or Flop.Schema.get_field/3 reads a join or custom field...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews