Documentation
¶
Overview ¶
Package procs defines the procedure registry for the Cypher executor.
A Registry stores ProcEntry values keyed by the fully-qualified procedure name ("namespace.name") and is consulted at plan-build time by [exec.ProcedureCallOp]. Built-in procedures (db.*) are registered via RegisterBuiltins; custom procedures may be added via [Register].
Circular-import avoidance ¶
This package must NOT import github.com/FlavioCFOliveira/GoGraph/cypher/exec. exec imports procs.
Concurrency ¶
Registry is safe for concurrent use.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrProcAlreadyExists = errors.New("procs: procedure already exists")
ErrProcAlreadyExists is returned by Registry.Register when a procedure with the same fully-qualified name is already registered.
var ErrProcNotFound = errors.New("procs: procedure not found")
ErrProcNotFound is returned by Registry.Lookup when no procedure matching the given namespace and name is registered.
Functions ¶
func RegisterBuiltins ¶
RegisterBuiltins registers all built-in db.* procedures into reg.
mgr is the index manager used by db.indexes() and db.labels(); it may be nil (both procedures return empty results).
listConstraints is a callback invoked by db.constraints() to obtain the current constraint rows (each row is [name, type, label, property]). Pass nil to always return an empty set.
Types ¶
type NamedType ¶
type NamedType struct {
// Name is the column name exposed via YIELD.
Name string
// Kind is the expected expr.Kind of values in this column.
Kind expr.Kind
}
NamedType pairs an output column name with its expected value kind.
type ProcImpl ¶
ProcImpl is the runtime function for a procedure. It receives the context and the evaluated argument values and returns all result rows. Each row must have exactly len(Signature.Outputs) columns.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a thread-safe store of registered procedures keyed by their fully-qualified name ("ns1.ns2.name").
Registry is safe for concurrent use.
Example ¶
ExampleRegistry shows the full register → list → lookup → invoke cycle on a fresh registry. List returns signatures sorted by fully-qualified name, so the output is stable across runs.
package main
import (
"context"
"fmt"
"github.com/FlavioCFOliveira/GoGraph/cypher/expr"
"github.com/FlavioCFOliveira/GoGraph/cypher/procs"
)
func main() {
reg := procs.NewRegistry()
sig := procs.Signature{
Namespace: []string{"demo"},
Name: "echo",
Inputs: []expr.Kind{expr.KindString},
Outputs: []procs.NamedType{{Name: "value", Kind: expr.KindString}},
}
impl := func(_ context.Context, args []expr.Value) ([][]expr.Value, error) {
return [][]expr.Value{{args[0]}}, nil
}
if err := reg.Register(sig, impl); err != nil {
fmt.Println("register error:", err)
return
}
// List exposes every registered signature, sorted by "namespace.name".
for _, s := range reg.List() {
fmt.Printf("listed: %s.%s\n", s.Namespace[0], s.Name)
}
// Lookup retrieves the entry so the executor can invoke its implementation.
entry, err := reg.Lookup([]string{"demo"}, "echo")
if err != nil {
fmt.Println("lookup error:", err)
return
}
rows, err := entry.Impl(context.Background(), []expr.Value{expr.StringValue("hi")})
if err != nil {
fmt.Println("invoke error:", err)
return
}
fmt.Printf("invoke result: %s\n", string(rows[0][0].(expr.StringValue)))
}
Output: listed: demo.echo invoke result: hi
func (*Registry) List ¶
List returns all registered signatures in lexicographic order of their fully-qualified names.
func (*Registry) Lookup ¶
Lookup retrieves the ProcEntry for (namespace, name). It returns a wrapped ErrProcNotFound when no such procedure is registered.
Example (NotFound) ¶
ExampleRegistry_Lookup_notFound shows the not-found path: Lookup returns a wrapped ErrProcNotFound for an unknown procedure.
package main
import (
"errors"
"fmt"
"github.com/FlavioCFOliveira/GoGraph/cypher/procs"
)
func main() {
reg := procs.NewRegistry()
_, err := reg.Lookup([]string{"db"}, "missing")
fmt.Println("is ErrProcNotFound:", errors.Is(err, procs.ErrProcNotFound))
}
Output: is ErrProcNotFound: true
type Signature ¶
type Signature struct {
// Namespace is the optional namespace path (e.g. ["db"] for db.labels()).
Namespace []string
// Name is the bare procedure name.
Name string
// Inputs lists the expected kinds for each positional argument.
Inputs []expr.Kind
// InputNames lists the declared name of each positional input, parallel
// to Inputs. When populated (len == len(Inputs)) the engine supports the
// openCypher implicit-argument form: a `CALL ns.name` with no argument
// list binds each declared input from the query parameter whose name
// matches the corresponding entry here. Empty / nil leaves the implicit
// form unsupported for this procedure.
InputNames []string
// Outputs lists the named output columns produced by the procedure.
Outputs []NamedType
}
Signature describes the calling contract of a procedure.