Spacetimedbex (spacetimedbex v0.1.2)

Copy Markdown View Source

SpacetimeDB client library for Elixir.

Provides WebSocket-based real-time connectivity to SpacetimeDB databases using the v2 BSATN binary protocol.

Getting Started

The main entry point is Spacetimedbex.Client — a GenServer that manages a WebSocket connection, local ETS cache, and schema-driven encoding:

defmodule MyApp.SpaceClient do
  use Spacetimedbex.Client

  def config do
    %{
      host: "localhost:3000",
      database: "my_db",
      subscriptions: ["SELECT * FROM users"]
    }
  end

  def on_insert("users", row, state) do
    IO.puts("New user: #{inspect(row)}")
    {:ok, state}
  end
end

{:ok, pid} = Spacetimedbex.Client.start_link(MyApp.SpaceClient, %{})

Module Overview

Code Generation

Generate typed Elixir modules from a live database:

mix spacetimedb.gen --host localhost:3000 --database my_db --module MyApp.SpacetimeDB