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
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.
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"}
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
A guard to test if the given offset is the first possible (as returned by first/0
).
@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}
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"