Documentation
¶
Index ¶
- func DocumentToNeuron(doc map[string]any, dim int) (*core.Neuron, error)
- func MarshalResult(r *Result) ([]byte, error)
- func NeuronToDocument(n *core.Neuron, projection map[string]int) map[string]any
- type Command
- type CommandHandler
- type CommandOptions
- type CommandType
- type Executor
- type FilterMatcher
- type Query
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DocumentToNeuron ¶
DocumentToNeuron creates a neuron from a document (for inserts)
func MarshalResult ¶
MarshalResult serializes a result
Types ¶
type Command ¶
type Command struct {
Type CommandType `json:"type"`
Collection string `json:"collection"`
Document map[string]any `json:"document,omitempty"`
Filter map[string]any `json:"filter,omitempty"`
Update map[string]any `json:"update,omitempty"`
Pipeline []any `json:"pipeline,omitempty"`
Options CommandOptions `json:"options,omitempty"`
}
Command represents a database command
func ParseCommand ¶
ParseCommand parses a JSON command string
type CommandHandler ¶
type CommandHandler func(worker *concurrency.BrainWorker, cmd *Command) *Result
CommandHandler is a function that handles a specific command type. Implementations receive the worker and parsed command, returning a result.
type CommandOptions ¶
type CommandOptions struct {
Limit int `json:"limit,omitempty"`
Skip int `json:"skip,omitempty"`
Sort map[string]int `json:"sort,omitempty"`
Projection map[string]int `json:"projection,omitempty"`
Depth int `json:"depth,omitempty"` // For search spread
Upsert bool `json:"upsert,omitempty"`
}
CommandOptions for queries
type CommandType ¶
type CommandType string
Command types
const ( CmdInsert CommandType = "insert" CmdFind CommandType = "find" CmdFindOne CommandType = "findOne" CmdUpdate CommandType = "update" CmdUpdateOne CommandType = "updateOne" CmdDelete CommandType = "delete" CmdDeleteOne CommandType = "deleteOne" CmdAggregate CommandType = "aggregate" CmdCount CommandType = "count" CmdActivate CommandType = "activate" // Fire a neuron CmdSearch CommandType = "search" // Semantic-like search with spread CmdStats CommandType = "stats" )
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes commands against a brain worker using a pluggable command registry. Handlers are looked up by CommandType at dispatch time, so new command types can be registered without modifying Execute.
func NewExecutor ¶
func NewExecutor() *Executor
NewExecutor creates a new command executor with the built-in command set.
func (*Executor) Execute ¶
func (e *Executor) Execute(worker *concurrency.BrainWorker, cmd *Command) *Result
Execute dispatches a command to the appropriate registered handler.
func (*Executor) ListCommands ¶
func (e *Executor) ListCommands() []CommandType
ListCommands returns all registered command types.
func (*Executor) Register ¶
func (e *Executor) Register(ct CommandType, h CommandHandler)
Register adds or replaces a handler for the given command type.
func (*Executor) Unregister ¶
func (e *Executor) Unregister(ct CommandType)
Unregister removes a handler for the given command type.
type FilterMatcher ¶
type FilterMatcher struct{}
FilterMatcher evaluates filters against neurons
func NewFilterMatcher ¶
func NewFilterMatcher() *FilterMatcher
NewFilterMatcher creates a new filter matcher
func (*FilterMatcher) MatchNeuron ¶
MatchNeuron checks if a neuron matches the filter
type Query ¶
type Query struct {
Collection string `json:"collection"` // "neurons" or "synapses"
Filter map[string]any `json:"filter"`
Projection map[string]int `json:"projection,omitempty"`
Sort map[string]int `json:"sort,omitempty"`
Limit int `json:"limit,omitempty"`
Skip int `json:"skip,omitempty"`
}
Query represents a MongoDB-like query
type Result ¶
type Result struct {
Success bool `json:"success"`
Data any `json:"data,omitempty"`
Count int `json:"count,omitempty"`
InsertedID string `json:"insertedId,omitempty"`
ModifiedCnt int `json:"modifiedCount,omitempty"`
DeletedCnt int `json:"deletedCount,omitempty"`
Error string `json:"error,omitempty"`
}
Result represents a command result