Documentation
¶
Index ¶
- type Client
- func (c *Client) Begin() (*CommandResponse, error)
- func (c *Client) Close() error
- func (c *Client) CollectionCreate(name string) (*CommandResponse, error)
- func (c *Client) CollectionDelete(name string) (*CommandResponse, error)
- func (c *Client) CollectionIndexCreate(collectionName, fieldName string) (*CommandResponse, error)
- func (c *Client) CollectionIndexDelete(collectionName, fieldName string) (*CommandResponse, error)
- func (c *Client) CollectionIndexList(collectionName string) ([]string, error)
- func (c *Client) CollectionItemDelete(collectionName, key string) (*CommandResponse, error)
- func (c *Client) CollectionItemDeleteMany(collectionName string, keys []string) (*CommandResponse, error)
- func (c *Client) CollectionItemGet(collectionName, key string) (*GetResult, error)
- func (c *Client) CollectionItemSet(collectionName, key string, value any, ttl time.Duration) (*CommandResponse, error)
- func (c *Client) CollectionItemSetMany(collectionName string, items []any) (*CommandResponse, error)
- func (c *Client) CollectionItemUpdate(collectionName, key string, patchValue any) (*CommandResponse, error)
- func (c *Client) CollectionItemUpdateMany(collectionName string, items []any) (*CommandResponse, error)
- func (c *Client) CollectionList() ([]string, error)
- func (c *Client) CollectionQuery(collectionName string, query Query) (*CommandResponse, error)
- func (c *Client) Commit() (*CommandResponse, error)
- func (c *Client) Connect() error
- func (c *Client) IsAuthenticated() bool
- func (c *Client) Rollback() (*CommandResponse, error)
- type ClientOptions
- type CommandResponse
- type GetResult
- type Query
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
}
Client is an asynchronous client to interact with a Memory Tools server.
func NewClient ¶
func NewClient(opts ClientOptions) *Client
NewClient creates a new instance of the MemoryToolsClient.
func (*Client) Begin ¶
func (c *Client) Begin() (*CommandResponse, error)
Begin starts a new transaction.
func (*Client) CollectionCreate ¶
func (c *Client) CollectionCreate(name string) (*CommandResponse, error)
CollectionCreate creates a new collection.
func (*Client) CollectionDelete ¶
func (c *Client) CollectionDelete(name string) (*CommandResponse, error)
CollectionDelete deletes a collection.
func (*Client) CollectionIndexCreate ¶
func (c *Client) CollectionIndexCreate(collectionName, fieldName string) (*CommandResponse, error)
CollectionIndexCreate creates an index on a collection field.
func (*Client) CollectionIndexDelete ¶
func (c *Client) CollectionIndexDelete(collectionName, fieldName string) (*CommandResponse, error)
CollectionIndexDelete deletes an index from a collection.
func (*Client) CollectionIndexList ¶
CollectionIndexList lists all indexes on a collection.
func (*Client) CollectionItemDelete ¶
func (c *Client) CollectionItemDelete(collectionName, key string) (*CommandResponse, error)
CollectionItemDelete deletes an item from a collection by its key.
func (*Client) CollectionItemDeleteMany ¶
func (c *Client) CollectionItemDeleteMany(collectionName string, keys []string) (*CommandResponse, error)
CollectionItemDeleteMany deletes multiple items from a collection by their keys.
func (*Client) CollectionItemGet ¶
CollectionItemGet gets an item from a collection by its key.
func (*Client) CollectionItemSet ¶
func (c *Client) CollectionItemSet(collectionName, key string, value any, ttl time.Duration) (*CommandResponse, error)
CollectionItemSet sets an item in a collection. If key is empty, the server will generate a unique ID.
func (*Client) CollectionItemSetMany ¶
func (c *Client) CollectionItemSetMany(collectionName string, items []any) (*CommandResponse, error)
CollectionItemSetMany sets multiple items in a collection.
func (*Client) CollectionItemUpdate ¶
func (c *Client) CollectionItemUpdate(collectionName, key string, patchValue any) (*CommandResponse, error)
CollectionItemUpdate updates an item in a collection using a JSON patch.
func (*Client) CollectionItemUpdateMany ¶
func (c *Client) CollectionItemUpdateMany(collectionName string, items []any) (*CommandResponse, error)
CollectionItemUpdateMany updates multiple items. Expects a slice of structs/maps, each with "_id" and "patch".
func (*Client) CollectionList ¶
CollectionList lists all accessible collections.
func (*Client) CollectionQuery ¶
func (c *Client) CollectionQuery(collectionName string, query Query) (*CommandResponse, error)
CollectionQuery performs a complex query on a collection.
func (*Client) Commit ¶
func (c *Client) Commit() (*CommandResponse, error)
Commit commits the current transaction.
func (*Client) IsAuthenticated ¶
IsAuthenticated checks if the client has successfully authenticated.
func (*Client) Rollback ¶
func (c *Client) Rollback() (*CommandResponse, error)
Rollback rolls back the current transaction.
type ClientOptions ¶
type ClientOptions struct { Host string Port int Username string Password string ServerCertPath string // Path to the server's public certificate (.crt) InsecureSkipVerify bool // Set to true to disable server certificate validation (not recommended for production) }
ClientOptions holds the configuration for creating a new client.
type CommandResponse ¶
CommandResponse represents a generic response from the server.
func (*CommandResponse) JSON ¶
func (r *CommandResponse) JSON(v any) error
JSON decodes the raw response data into the provided interface. 'v' must be a pointer.
func (*CommandResponse) OK ¶
func (r *CommandResponse) OK() bool
OK returns true if the command was successful.
type GetResult ¶
type GetResult struct {
*CommandResponse
}
GetResult is a specialized response for 'get' operations for a more intuitive API.
type Query ¶
type Query struct { Filter map[string]any `json:"filter,omitempty"` OrderBy []any `json:"order_by,omitempty"` Limit *int `json:"limit,omitempty"` Offset int `json:"offset,omitempty"` Count bool `json:"count,omitempty"` Aggregations map[string]any `json:"aggregations,omitempty"` GroupBy []string `json:"group_by,omitempty"` Having map[string]any `json:"having,omitempty"` Distinct string `json:"distinct,omitempty"` Projection []string `json:"projection,omitempty"` Lookups []any `json:"lookups,omitempty"` }
Query is a helper struct to build complex queries for the server.