Avrora.Schema (avrora v0.18.1) View Source

Convenience wrapper struct for erlavro records.

Link to this section Summary

Functions

Convert erlavro format to the struct.

An example of a reference lookup which returns empty JSON body

Convert struct to erlavro format and look it up in avro_schema_store.

Link to this section Types

Link to this type

reference_lookup_fun()

View Source

Specs

reference_lookup_fun() :: (String.t() -> {:ok, String.t()} | {:error, term()})

Specs

t() :: %Avrora.Schema{
  full_name: String.t(),
  id: nil | integer(),
  json: String.t(),
  lookup_table: reference(),
  version: nil | integer()
}

Link to this section Functions

Link to this function

from_erlavro(schema, attributes \\ [])

View Source

Specs

from_erlavro(term(), keyword()) :: {:ok, t()} | {:error, term()}

Convert erlavro format to the struct.

Examples

iex> payload =
...>   {:avro_record_type, "Payment", "io.confluent", "", [],
...>        [
...>          {:avro_record_field, "id", "", {:avro_primitive_type, "string", []}, :undefined,
...>           :ascending, []},
...>          {:avro_record_field, "amount", "", {:avro_primitive_type, "double", []}, :undefined,
...>           :ascending, []}
...>        ], "io.confluent.Payment", []}
iex> {:ok, schema} = Avrora.Schema.from_erlavro(payload)
iex> schema.id
nil
iex> schema.full_name
"io.confluent.Payment"
Link to this function

parse(payload, reference_lookup_fun \\ &Avrora.Schema.reference_lookup/1)

View Source

Specs

parse(String.t(), reference_lookup_fun()) :: {:ok, t()} | {:error, term()}

Parse Avro schema JSON and convert to struct.

Examples

iex> json = ~s({"namespace":"io.confluent","type":"record","name":"Payment","fields":[{"name":"id","type":"string"},{"name":"amount","type":"double"}]})
iex> {:ok, schema} = Avrora.Schema.parse(json)
iex> schema.full_name
"io.confluent.Payment"

Specs

reference_lookup(String.t()) :: {:ok, String.t()} | {:error, term()}

An example of a reference lookup which returns empty JSON body

Specs

to_erlavro(t()) :: {:ok, term()} | {:error, term()}

Convert struct to erlavro format and look it up in avro_schema_store.

Examples

iex> json = ~s({"namespace":"io.confluent","type":"record","name":"Payment","fields":[{"name":"id","type":"string"},{"name":"amount","type":"double"}]})
iex> {:ok, schema} = Avrora.Schema.parse(json)
iex> {:ok, {type, _, _, _, _, _, full_name, _}} = Avrora.Schema.to_erlavro(schema)
iex> full_name
"io.confluent.Payment"
iex> type
:avro_record_type