Spacetimedbex.Schema (spacetimedbex v0.1.2)

Copy Markdown View Source

Fetches and parses SpacetimeDB module schema.

The schema describes tables (columns, types, primary keys), reducers (params), and the typespace (algebraic type definitions). Used by the ClientCache to decode BSATN row data into Elixir maps.

Summary

Functions

Get column definitions for a table.

Fetch and parse schema from a SpacetimeDB instance.

Parse a raw schema JSON map into a structured Schema.

Get primary key column indices for a table.

Types

algebraic_type()

@type algebraic_type() ::
  :bool
  | :u8
  | :i8
  | :u16
  | :i16
  | :u32
  | :i32
  | :u64
  | :i64
  | :u128
  | :i128
  | :u256
  | :i256
  | :f32
  | :f64
  | :string
  | :bytes
  | {:array, algebraic_type()}
  | {:option, algebraic_type()}
  | {:product, [column()]}
  | {:ref, non_neg_integer()}

column()

@type column() :: %{name: String.t(), type: algebraic_type()}

reducer_def()

@type reducer_def() :: %{name: String.t(), params: [column()]}

t()

@type t() :: %Spacetimedbex.Schema{
  reducers: %{required(String.t()) => reducer_def()},
  tables: %{required(String.t()) => table_def()},
  typespace: [term()]
}

table_def()

@type table_def() :: %{
  name: String.t(),
  columns: [column()],
  primary_key: [non_neg_integer()]
}

Functions

columns_for(schema, table_name)

Get column definitions for a table.

fetch(host, database)

Fetch and parse schema from a SpacetimeDB instance.

parse(raw)

Parse a raw schema JSON map into a structured Schema.

primary_key_for(schema, table_name)

Get primary key column indices for a table.