client

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 12 Imported by: 0

README

memory-tools-client-go

Memory tools client Go Repository

Documentation

Index

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) Close

func (c *Client) Close() error

Close terminates the connection to the server.

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

func (c *Client) CollectionIndexList(collectionName string) ([]string, error)

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

func (c *Client) CollectionItemGet(collectionName, key string) (*GetResult, error)

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

func (c *Client) CollectionList() ([]string, error)

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) Connect

func (c *Client) Connect() error

Connect establishes a secure connection to the server and authenticates.

func (*Client) IsAuthenticated

func (c *Client) IsAuthenticated() bool

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

type CommandResponse struct {
	StatusCode byte
	Status     string
	Message    string
	RawData    []byte
}

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.

func (*GetResult) Found

func (r *GetResult) Found() bool

Found returns true if the item was found.

func (*GetResult) Value

func (r *GetResult) Value(v any) error

Value decodes the item's value from JSON into the provided interface. 'v' must be a pointer.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL