Supabase.Realtime.PostgresTypes (supabase_realtime v0.5.0)

Copy Markdown

Transforms postgres_changes payload column values from strings to native Elixir types.

Supported Types

Postgres typeElixir type
bool, booleanboolean()
int2, int4, int8, smallint,integer()
integer, bigint
float4, float8, real, doublefloat()
numericinteger() or float()
json, jsonbdecoded term
timestamp, timestamptzDateTime.t()
dateDate.t()
time, timetzTime.t()
uuidString.t()
text, varchar, char, name,String.t()
citext
Array types (e.g. _int4, _text)list() of the inner type

Any type not listed above is returned as-is.

Examples

columns = [
  %{"name" => "id", "type" => "int8"},
  %{"name" => "active", "type" => "bool"},
  %{"name" => "score", "type" => "float8"}
]

record = %{"id" => "42", "active" => "true", "score" => "9.5"}

PostgresTypes.transform(record, columns)
#=> %{"id" => 42, "active" => true, "score" => 9.5}

Summary

Functions

Transforms a record map using column metadata from the event payload.

Functions

transform(record, columns)

@spec transform(map() | nil, [map()]) :: map() | nil

Transforms a record map using column metadata from the event payload.

Parameters

  • record - The record map with string values
  • columns - List of column metadata maps with "name" and "type" keys