View Source Electric.Client.Offset (Electric Client v0.1.2)

Represents an offset in the synchronisation stream from Electric.

Summary

Functions

Return an offset that is guaranteed to be before any real database operations.

The first possible offset in the log.

Parse an offset value from an HTTP header into a %Elixir.Electric.Client.Offset{} struct.

Parse an offset value from an HTTP header into a %Elixir.Electric.Client.Offset{} struct.

A guard to test if the given offset is the first possible (as returned by first/0).

Create a new Elixir.Electric.Client.Offset struct from the given LSN and operation offsets.

Output the an Offset as a string for use in query parameters.

Types

@type int64() :: 0..18_446_744_073_709_551_615
@type op_offset() :: int64() | :infinity
@type t() :: %Electric.Client.Offset{op: op_offset(), tx: tx_offset()}
@type tx_offset() :: int64() | -1

Functions

@spec before_all() :: t()

Return an offset that is guaranteed to be before any real database operations.

@spec first() :: t()

The first possible offset in the log.

@spec from_string(String.t()) :: {:ok, t()} | {:error, String.t()}

Parse an offset value from an HTTP header into a %Elixir.Electric.Client.Offset{} struct.

iex> from_string("-1")
{:ok, %Elixir.Electric.Client.Offset{tx: -1, op: 0}}

iex> from_string("1378734_3")
{:ok, %Elixir.Electric.Client.Offset{tx: 1378734, op: 3}}

iex> from_string("not a real offset")
{:error, "has invalid format"}
@spec from_string!(String.t()) :: t() | no_return()

Parse an offset value from an HTTP header into a %Elixir.Electric.Client.Offset{} struct.

Raises if the offset header value is invalid.

iex> from_string!("-1")
%Elixir.Electric.Client.Offset{tx: -1, op: 0}

iex> from_string!("1378734_3")
%Elixir.Electric.Client.Offset{tx: 1378734, op: 3}

iex> from_string!("not a real offset")
** (ArgumentError) has invalid format
Link to this macro

is_first(offset)

View Source (macro)

A guard to test if the given offset is the first possible (as returned by first/0).

Link to this function

new(tx_offset, op_offset)

View Source
@spec new(non_neg_integer(), non_neg_integer()) :: t()

Create a new Elixir.Electric.Client.Offset struct from the given LSN and operation offsets.

iex> new(2349, 3)
%Elixir.Electric.Client.Offset{tx: 2349, op: 3}
@spec to_string(t()) :: String.t()

Output the an Offset as a string for use in query parameters.

iex> new(2349, 3) |> Elixir.Electric.Client.Offset.to_string()
"2349_3"

iex> before_all() |> Elixir.Electric.Client.Offset.to_string()
"-1"
@spec to_tuple(t()) :: {tx_offset(), op_offset()}