class

Spacetime::Client

Inherits Reference < Object

Real-time SpacetimeDB client managing WebSocket connections, live SQL subscriptions, transactional reducer/procedure invocations, and an automatic client-side ClientCache.

Constructors

connect(host : String, database : String, token : String | Nil = nil, &block : Options -> ) : self
Source
connect(host : String, database : String, token : String | Nil = nil) : self
Source
new(options : Options = Options.new)
Source

Instance methods

cache
Source
call_procedure(procedure : String, args : Bytes = Bytes.empty, flags : Protocol::CallProcedureFlags = Protocol::CallProcedureFlags::Default, json_args : String | Nil = nil) : UInt32

Calls a server-side procedure with BSATN args bytes.

Source
call_reducer(reducer : String, args : Bytes = Bytes.empty, flags : Protocol::CallReducerFlags = Protocol::CallReducerFlags::FullUpdate, json_args : String | Nil = nil) : UInt32

Calls a server-side reducer with pre-encoded BSATN args bytes (or a block that writes arguments to a BSATN::Encoder).

Source
call_reducer(reducer : String, flags : Protocol::CallReducerFlags = Protocol::CallReducerFlags::FullUpdate, &block : BSATN::Encoder -> ) : UInt32

Calls a server-side reducer by encoding arguments via a BSATN::Encoder block.

Source
close
Source
connect
Source
connected?
Source
connection_id
Source
disconnect
Source
handle_server_message(msg : Protocol::ServerMessage) : Nil

Processes a decoded Protocol::ServerMessage and updates the client cache & callbacks.

Source
http
Source
identity
Source
on_error

Registers a callback invoked on subscription or protocol errors.

Source
on_identity

Registers a callback invoked when the server sends the connection's IdentityToken.

Source
on_reducer(reducer_name : String, &block : Protocol::TransactionUpdate -> Nil) : self

Registers a callback invoked when a specific named reducer finishes executing.

Source
on_subscription_applied

Registers a callback invoked when a subscription (InitialSubscription, SubscribeApplied, or SubscribeMultiApplied) is applied.

Source
on_transaction

Registers a callback invoked on every TransactionUpdate.

Source
one_off_query(query : String | SQL, message_id : Bytes = UUID.random.to_be_bytes) : Bytes

Sends a OneOffQuery over the WebSocket connection and returns the message_id.

Source
options
Source
register_table(type : T.class, custom_name : String | Nil = nil) : TableCache(T) forall T

Registers a table type T with the client's local reactive cache and returns its TableCache(T).

Source
send_message(msg : Protocol::ClientMessage) : Nil

Sends a Protocol::ClientMessage over the active transport.

Source
subscribe(queries : Array(String | SQL)) : UInt32

Sends a legacy Subscribe message replacing the active subscription query set.

Source
subscribe(*queries : String | SQL) : UInt32
Source
subscribe_multi(queries : Array(String | SQL)) : Tuple(UInt32, QueryId)

Sends a SubscribeMulti message for multiple SQL queries under a single QueryId.

Source
subscribe_single(query : String | SQL) : Tuple(UInt32, QueryId)

Sends a SubscribeSingle message and returns {request_id, query_id}.

Source
table(type : T.class, custom_name : String | Nil = nil) : TableCache(T) forall T

Accesses the typed TableCache(T) for table T.

Source
token
Source
transport
Source
unsubscribe(query_id : QueryId) : UInt32

Unsubscribes from a SubscribeSingle subscription by QueryId.

Source
unsubscribe_multi(query_id : QueryId) : UInt32

Unsubscribes from a SubscribeMulti subscription by QueryId.

Source