Documentation
¶
Index ¶
- Constants
- Variables
- type BigFloat
- type BigInt
- type Client
- func (c *Client) Close() error
- func (c *Client) Create(ctx context.Context, id RecordID, data any) ([]byte, error)
- func (c *Client) Delete(ctx context.Context, id *ID) ([]byte, error)
- func (c *Client) GraphQL(ctx context.Context, req GraphqlRequest) ([]byte, error)
- func (c *Client) Insert(ctx context.Context, table string, data []any) ([]byte, error)
- func (c *Client) InsertRelation(ctx context.Context, table *string, data any) ([]byte, error)
- func (c *Client) Kill(ctx context.Context, uuid string) ([]byte, error)
- func (c *Client) Let(ctx context.Context, name string, value any) error
- func (c *Client) Live(ctx context.Context, query string, vars map[string]any) (<-chan []byte, error)
- func (c *Client) Marshal(val any) ([]byte, error)
- func (c *Client) Merge(ctx context.Context, thing *ID, data any) ([]byte, error)
- func (c *Client) Patch(ctx context.Context, thing *ID, patches []Patch, diff bool) ([]byte, error)
- func (c *Client) Query(ctx context.Context, query string, vars map[string]any) ([]byte, error)
- func (c *Client) Relate(ctx context.Context, in *ID, relation RecordID, out *ID, data any) ([]byte, error)
- func (c *Client) Run(ctx context.Context, name string, version *string, args []any) ([]byte, error)
- func (c *Client) Select(ctx context.Context, id *ID) ([]byte, error)
- func (c *Client) Unmarshal(data []byte, val any) error
- func (c *Client) Unset(ctx context.Context, name string) error
- func (c *Client) Update(ctx context.Context, id *ID, data any) ([]byte, error)
- func (c *Client) Upsert(ctx context.Context, id RecordID, data any) ([]byte, error)
- func (c *Client) Version(ctx context.Context) (string, error)
- type Config
- type DateTime
- type Decimal
- type Duration
- type GraphqlRequest
- type HTTPClient
- type ID
- type Marshal
- type Operation
- type Option
- type Patch
- type RecordID
- type Unmarshal
- type ZeroAsNone
Constants ¶
const ( // CBORTagNone represents a NONE value. // The value passed to the tagged value is null, as it cannot be empty. CBORTagNone = 6 // CBORTagUUID represents a UUID in binary form. // It is adopted from the IANA specification. // It is preferred by SurrealDB over custom tag 9 (string). // // Please note: This const is exposed and not implemented by this package. // This decision was made to minimize the number of dependencies. // There is no UUID type in the standard library. // As a third-party package, github.com/google/uuid is recommended. CBORTagUUID = 37 )
const ( CborMinNestedLevels = 4 CborMaxNestedLevels = 65535 CborMinArrayElements = 16 CborMaxArrayElements = 2147483647 CborMinMapPairs = 16 CborMaxMapPairs = 2147483647 )
Variables ¶
var ( ErrInvalidNamespaceName = errors.New("invalid namespace name") ErrInvalidDatabaseName = errors.New("invalid database name") ErrContextNil = errors.New("context is nil") )
var ( ErrChannelClosed = errors.New("channel closed") ErrCouldNotGetLiveQueryChannel = errors.New("could not get live query channel") ErrCouldNotSelectDatabase = errors.New("could not select database") ErrEmptyResponse = errors.New("empty response") ErrExpectedTextMessage = fmt.Errorf("expected message of type text (%d)", websocket.MessageBinary) ErrResponseNotOkay = errors.New("response status is not OK") ErrResultWithError = errors.New("result contains error") ErrTimeoutWaitingForGoroutines = errors.New("internal goroutines did not finish in time") )
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) GraphQL ¶ added in v0.8.0
GraphQL executes graphql queries against the database. Note: Requires SurrealDB v2.0.0 or later.
func (*Client) Insert ¶ added in v0.8.0
Insert one or multiple records in a table. TODO: allow for fixed IDs.
func (*Client) InsertRelation ¶ added in v0.8.0
InsertRelation inserts a new relation record into the database. Data needs to specify both the in and out records. If table is nil, the relation table is inferred from the data record ID field.
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) Feature: Live Query WHERE clause should process Params (https://github.com/surrealdb/surrealdb/issues/4026) Docs: https://surrealdb.com/docs/surrealql/statements/live_select (bottom "other notes")
TODO: prevent query from being more than one statement.
func (*Client) Merge ¶ added in v0.8.0
Merge specified data into either all records in a table or a single record. TODO: support "all" records.
func (*Client) Patch ¶ added in v0.8.0
Patch either all records in a table or a single record with specified patches. see: https://jsonpatch.com/
func (*Client) Relate ¶ added in v0.8.0
func (c *Client) Relate(ctx context.Context, in *ID, relation RecordID, out *ID, data any) ([]byte, error)
Relate creates a graph relationship between two records. Data is optional and only submitted if it is not nil.
func (*Client) Run ¶ added in v0.8.0
Run executes built-in functions, custom functions, or machine learning models with optional arguments.
func (*Client) Update ¶
Update modifies either all records in a table or a single record with specified data if the record already exists.
type Config ¶
type Config struct {
// Host is the host address of the database.
// It must not contain a protocol or sub path like /rpc.
Host string
// Secure indicates whether to use a secure connection (https, wss) or not.
Secure bool
// 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
// CborMaxNestedLevels specifies the max nested levels allowed for any combination of CBOR array, maps, and tags.
// Default is 32 levels, minimum is 4, maximum is 65535. Note that higher maximum levels of nesting can
// require larger amounts of stack to deserialize. Don't increase this higher than you require.
CborMaxNestedLevels int
// CborMaxArrayElements specifies the max number of elements for CBOR arrays.
// Default is 128*1024=131072, minimum is 16, maximum is 2147483647.
CborMaxArrayElements int
// CborMaxMapPairs specifies the max number of key-value pairs for CBOR maps.
// Default is 128*1024=131072, minimum is 16, maximum is 2147483647.
CborMaxMapPairs int
}
Config is the configuration for the client.
type DateTime ¶ added in v0.6.0
func (*DateTime) MarshalCBOR ¶ added in v0.6.0
func (*DateTime) UnmarshalCBOR ¶ added in v0.6.0
type Decimal ¶ added in v0.6.0
type Decimal struct {
// contains filtered or unexported fields
}
func (*Decimal) MarshalCBOR ¶ added in v0.6.0
type Duration ¶ added in v0.6.0
func (*Duration) MarshalCBOR ¶ added in v0.6.0
func (*Duration) UnmarshalCBOR ¶ added in v0.6.0
type GraphqlRequest ¶ added in v0.8.0
type GraphqlRequest struct {
// Query contains the query string to execute (required).
Query string `cbor:"query"`
// Vars may contain variables to be used in the query (optional).
Vars map[string]any `cbor:"vars"`
// Operation is the name of the operation to execute (optional).
Operation string `cbor:"operationName"`
}
type HTTPClient ¶ added in v0.9.2
type ID ¶ added in v0.6.0
type ID struct {
// contains filtered or unexported fields
}
func ParseRecord ¶ added in v0.6.0
func (*ID) MarshalCBOR ¶ added in v0.6.0
func (*ID) UnmarshalCBOR ¶ added in v0.6.0
type Option ¶
type Option func(*options)
func WithHTTPClient ¶ added in v0.9.2
func WithHTTPClient(client HTTPClient) Option
WithHTTPClient sets a custom http client. If not set, the default http client is 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.
type RecordID ¶ added in v0.6.0
type RecordID interface {
// contains filtered or unexported methods
}
type ZeroAsNone ¶ added in v0.6.0
type ZeroAsNone[T comparable] struct { Value T }
func (*ZeroAsNone[T]) MarshalCBOR ¶ added in v0.6.0
func (n *ZeroAsNone[T]) MarshalCBOR() ([]byte, error)
func (*ZeroAsNone[T]) UnmarshalCBOR ¶ added in v0.6.0
func (n *ZeroAsNone[T]) UnmarshalCBOR(data []byte) error