PhoenixKitSync.ExtensionTypes (PhoenixKitSync v0.2.5)

Copy Markdown View Source

The wire form of the column types Postgrex returns as a struct of its own: how the exporters write one and how the importers read it back, for the REST and the WebSocket paths alike.

Carried, as text the importer turns back into the same value:

Column typeStructText
intervalPostgrex.Interval"14 mons 3 days 14706000007 microseconds"
inet, cidrPostgrex.INET"10.0.0.1", "10.0.0.0/8", "::1/128"
macaddrPostgrex.MACADDR"08:00:2b:01:02:03"

An interval's three parts are written as Postgres stores them (months, days and microseconds are not folded into one another), in whole numbers, so nothing is rounded.

Not carried: ranges and multiranges, the geometric types (point, line, lseg, box, path, polygon, circle) and tsvector (a list of Postgrex.Lexeme, marked by its first element). The exporter writes %{"__phoenix_kit_unsupported__" => "Postgrex.Range"} in place of such a value, and the importer fails that record, naming the type, instead of storing text that only looks like the value.

Summary

Functions

Reads the text serialize/1 wrote for a column of type back into the struct Postgrex binds: {:ok, struct}, or :error for text that is not that type's.

Writes a struct Postgrex returned for a column value: its text for a type this module carries, the unsupported marker for any other struct.

The column types parse/2 reads.

The type named by an unsupported marker, or nil for any other value.

The unsupported marker for a value that has no wire form and is not a struct (a composite column's tuple, a bit(n) bitstring), named by label.

Functions

parse(type, text)

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

Reads the text serialize/1 wrote for a column of type back into the struct Postgrex binds: {:ok, struct}, or :error for text that is not that type's.

serialize(arg1)

@spec serialize(struct()) :: String.t() | %{required(String.t()) => String.t()}

Writes a struct Postgrex returned for a column value: its text for a type this module carries, the unsupported marker for any other struct.

types()

@spec types() :: [String.t()]

The column types parse/2 reads.

unsupported(marker)

@spec unsupported(term()) :: String.t() | nil

The type named by an unsupported marker, or nil for any other value.

unsupported_marker(label)

@spec unsupported_marker(String.t()) :: %{required(String.t()) => String.t()}

The unsupported marker for a value that has no wire form and is not a struct (a composite column's tuple, a bit(n) bitstring), named by label.