Quarto.Cursor behaviour (Quarto v1.1.5) View Source

Behaviour for custom encoding of cursor values.

Used if you want finer control over how the values are encoded or decoded. Could be used to ensure the cursor are signed or validate cursors at your application boundaries.

defmodule CustomCursor do
  @behaviour Quarto.Cursor

  ...
end

Quarto.Post
|> order_by(desc: :id)
|> Repo.paginate(cursor: CustomCursor)

Link to this section Summary

Callbacks

Decodes a cursor binary.

Decodes a cursor binary.

Encodes an erlang term

Encodes an erlang term.

Link to this section Callbacks

Link to this callback

decode(encoded_cursor, opts)

View Source

Specs

decode(encoded_cursor :: nil | binary(), opts :: keyword()) ::
  {:ok, term()} | {:error, any()}

Decodes a cursor binary.

Returns an :ok tuple if it was able to decode the cursor, or else an :error tuple

Link to this callback

decode!(encoded_cursor, opts)

View Source

Specs

decode!(encoded_cursor :: nil | binary(), opts :: keyword()) :: term()

Decodes a cursor binary.

Returns the cursor or raises when it fails to decode

Link to this callback

encode(decoded_cursor, opts)

View Source

Specs

encode(decoded_cursor :: term(), opts :: keyword()) ::
  {:ok, binary()} | {:error, any()}

Encodes an erlang term

Returns an :ok tuple if it was able to encode the cursor, or else an :error tuple

Link to this callback

encode!(decoded_cursor, opts)

View Source

Specs

encode!(decoded_cursor :: term(), opts :: keyword()) :: binary() | no_return()

Encodes an erlang term.

Returns the cursor or raises when it fails to encodes