Documentation ¶
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Create(ctx context.Context, thing string, data any) ([]byte, error)
- func (c *Client) Delete(ctx context.Context, thing string) ([]byte, error)
- func (c *Client) Kill(ctx context.Context, uuid string) ([]byte, error)
- func (c *Client) Live(ctx context.Context, query string, vars map[string]any) (<-chan []byte, error)
- func (c *Client) Query(ctx context.Context, query string, vars map[string]any) ([]byte, error)
- func (c *Client) Select(ctx context.Context, thing string) ([]byte, error)
- func (c *Client) Update(ctx context.Context, thing string, data any) ([]byte, error)
- type Config
- type JsonMarshal
- type JsonUnmarshal
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient creates a new client and connects to the database using a websocket connection.
func (*Client) Close ¶
Close closes the client and the websocket connection. Furthermore, it cleans up all idle goroutines.
func (*Client) Live ¶
func (c *Client) Live(ctx context.Context, query string, vars map[string]any) (<-chan []byte, error)
Live executes a live query request and returns a channel to receive the results.
NOTE: SurrealDB does not yet support proper variable handling for live queries. To circumvent this limitation, params are registered in the database before issuing the actual live query. Those params are given the values of the variables passed to this method. This way, the live query can be filtered by said params. Please note that this is a workaround and may not work as expected in all cases.
References: Bug: Using variables in filters does not emit live messages (https://github.com/surrealdb/surrealdb/issues/2623) Bug: LQ params should be evaluated before registering (https://github.com/surrealdb/surrealdb/issues/2641) Bug: parameters do not work with live queries (https://github.com/surrealdb/surrealdb/issues/3602)
TODO: prevent query from being more than one statement
type Config ¶
type Config struct { // Address is the address of the database. Address string // Username is the username to use for authentication. Username string // Password is the password to use for authentication. Password string // Namespace is the namespace to use. // It will automatically be created if it does not exist. Namespace string // Database is the database to use. // It will automatically be created if it does not exist. Database string }
Config is the configuration for the client.
type JsonMarshal ¶
type JsonUnmarshal ¶
type Option ¶
type Option func(*options)
func WithJsonHandlers ¶
func WithJsonHandlers(marshal JsonMarshal, unmarshal JsonUnmarshal) Option
WithJsonHandlers sets custom json marshal and unmarshal functions. If not set, the default json marshal and unmarshal functions are used.
func WithLogger ¶
WithLogger sets the logger. If not set, no log output is created.
func WithReadLimit ¶
WithReadLimit sets a custom read limit (in bytes) for the websocket connection. If not set, the default read limit is 1 MB.
func WithTimeout ¶
WithTimeout sets a custom timeout for requests. If not set, the default timeout is 1 minute.