apoc

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 51 Imported by: 0

README ΒΆ

APOC Functions for NornicDB

NornicDB includes 850+ APOC functions compatible with Neo4j's APOC library.

Documentation

πŸ“š Full Documentation β†’

Quick Reference

Configuration
# Environment variables (Docker/K8s friendly)
NORNICDB_PLUGINS_DIR=/plugins       # Custom plugin directory
NORNICDB_APOC_ALGO_ENABLED=false         # Disable expensive algorithms
NORNICDB_APOC_CREATE_ENABLED=false       # Disable write operations
Available Categories
Category Functions Description
apoc.coll.* 60+ Collection operations
apoc.text.* 50+ Text processing
apoc.math.* 50+ Math operations
apoc.algo.* 15+ Graph algorithms
apoc.create.* 25+ Dynamic creation
apoc.atomic.* 20+ Atomic operations
apoc.bitwise.* 15+ Bitwise operations
apoc.cypher.* 20+ Dynamic Cypher
apoc.export.* 15+ Export data
apoc.import.* 15+ Import data
apoc.hashing.* 20+ Hashing functions
apoc.load.* 30+ Data loading
apoc.lock.* 15+ Locking mechanisms
apoc.log.* 25+ Logging functions
apoc.merge.* 20+ Merge operations
apoc.meta.* 30+ Metadata functions
apoc.nodes.* 30+ Batch node operations
apoc.paths.* 25+ Advanced paths
apoc.periodic.* 10+ Periodic execution
apoc.refactor.* 25+ Graph refactoring
apoc.schema.* 25+ Schema management
apoc.scoring.* 25+ Scoring/ranking
apoc.search.* 30+ Full-text search
apoc.spatial.* 25+ Geographic functions
apoc.stats.* 30+ Statistics
apoc.temporal.* 40+ Date/time operations
apoc.trigger.* 20+ Trigger management
apoc.warmup.* 15+ Database warmup
apoc.xml.* 25+ XML processing
...and 15+ more categories See full docs
Custom Plugins

Drop .so files into NORNICDB_PLUGINS_DIR - they're auto-loaded on startup.

// Your plugin must export:
var Plugin YourPlugin

type YourPlugin struct{}
func (p YourPlugin) Name() string { return "custom" }
func (p YourPlugin) Version() string { return "1.0.0" }
func (p YourPlugin) Functions() map[string]apoc.PluginFunction { ... }

Package Structure

apoc/
β”œβ”€β”€ apoc.go          # Main entry point, function registration
β”œβ”€β”€ config.go        # Configuration (env vars, YAML)
β”œβ”€β”€ plugins.go       # Plugin loading (.so files)
β”œβ”€β”€ storage/         # Storage interface
β”œβ”€β”€ registry/        # Function registry
β”œβ”€β”€ plugin/          # Plugin system
β”‚
β”œβ”€β”€ Core Functions (45+ packages):
β”œβ”€β”€ agg/             # Aggregation functions
β”œβ”€β”€ algo/            # Graph algorithms
β”œβ”€β”€ atomic/          # Atomic operations
β”œβ”€β”€ bitwise/         # Bitwise operations
β”œβ”€β”€ coll/            # Collection functions
β”œβ”€β”€ convert/         # Type conversions
β”œβ”€β”€ create/          # Dynamic creation
β”œβ”€β”€ cypher/          # Dynamic Cypher
β”œβ”€β”€ date/            # Date/time functions
β”œβ”€β”€ diff/            # Diff operations
β”œβ”€β”€ export/          # Export data
β”œβ”€β”€ graph/           # Virtual graphs
β”œβ”€β”€ hashing/         # Hashing functions
β”œβ”€β”€ imports/         # Import data
β”œβ”€β”€ json/            # JSON operations
β”œβ”€β”€ label/           # Label operations
β”œβ”€β”€ load/            # Data loading
β”œβ”€β”€ lock/            # Locking mechanisms
β”œβ”€β”€ log/             # Logging functions
β”œβ”€β”€ map/             # Map operations
β”œβ”€β”€ math/            # Math operations
β”œβ”€β”€ merge/           # Merge operations
β”œβ”€β”€ meta/            # Metadata functions
β”œβ”€β”€ neighbors/       # Neighbor traversal
β”œβ”€β”€ node/            # Node operations
β”œβ”€β”€ nodes/           # Batch node operations
β”œβ”€β”€ number/          # Number formatting
β”œβ”€β”€ path/            # Path finding
β”œβ”€β”€ paths/           # Advanced paths
β”œβ”€β”€ periodic/        # Periodic execution
β”œβ”€β”€ refactor/        # Graph refactoring
β”œβ”€β”€ rel/             # Relationship operations
β”œβ”€β”€ schema/          # Schema management
β”œβ”€β”€ scoring/         # Scoring/ranking
β”œβ”€β”€ search/          # Full-text search
β”œβ”€β”€ spatial/         # Geographic functions
β”œβ”€β”€ stats/           # Statistics
β”œβ”€β”€ temporal/        # Advanced date/time
β”œβ”€β”€ text/            # Text processing
β”œβ”€β”€ trigger/         # Trigger management
β”œβ”€β”€ util/            # Utility functions
β”œβ”€β”€ warmup/          # Database warmup
β”œβ”€β”€ xml/             # XML processing
β”‚
β”œβ”€β”€ plugins/         # Built-in plugins
β”‚   β”œβ”€β”€ coll_plugin.go
β”‚   └── text_plugin.go
└── examples/        # Plugin examples

See Also

Documentation ΒΆ

Overview ΒΆ

Package apoc provides APOC (Awesome Procedures On Cypher) functions for NornicDB.

All functions are compiled into the binary and controlled via configuration, following Neo4j's APOC architecture.

Package apoc configuration provides APOC function configuration for NornicDB.

Configuration can be loaded from:

  • Environment variables (recommended for Docker/K8s)
  • YAML configuration file
  • Programmatic defaults

Environment Variables:

NORNICDB_PLUGINS_DIR       - Directory to auto-load .so plugins from
NORNICDB_APOC_COLL_ENABLED      - Enable collection functions (default: true)
NORNICDB_APOC_TEXT_ENABLED      - Enable text functions (default: true)
NORNICDB_APOC_MATH_ENABLED      - Enable math functions (default: true)
NORNICDB_APOC_ALGO_ENABLED      - Enable graph algorithms (default: true)
NORNICDB_APOC_CREATE_ENABLED    - Enable dynamic creation (default: true)
NORNICDB_APOC_SECURITY_ALLOW_FILE_ACCESS - Legacy shorthand enabling both import and export file operations
NORNICDB_APOC_SECURITY_ALLOW_IMPORT_FILE_ACCESS - Allow APOC import/load local file operations (default: false)
NORNICDB_APOC_SECURITY_ALLOW_EXPORT_FILE_ACCESS - Allow APOC export local file operations (default: false)
NORNICDB_APOC_SECURITY_ALLOW_REMOTE_URL_ACCESS - Allow APOC load/import HTTP(S) fetches (default: false)
NORNICDB_APOC_SECURITY_FILE_ACCESS_ROOT - Rebase local APOC file URLs under this directory when set
NORNICDB_APOC_SECURITY_MAX_COLLECTION_SIZE - Max collection size (default: 100000)

Example Docker Usage:

docker run -e NORNICDB_PLUGINS_DIR=/plugins \
           -e NORNICDB_APOC_ALGO_ENABLED=false \
           -v ./my-plugins:/plugins \
           nornicdb/nornicdb

Index ΒΆ

Constants ΒΆ

View Source
const ExampleConfigYAML = `` /* 1269-byte string literal not displayed */

Example configuration file content

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Call ΒΆ

func Call(name string, args []interface{}) (interface{}, error)

Call executes an APOC function by name.

Example:

result, err := apoc.Call("apoc.coll.sum", []interface{}{[]interface{}{1, 2, 3}})

func Categories ΒΆ

func Categories() []string

Categories returns all registered categories.

func GetStorage ΒΆ

func GetStorage() storage.Storage

GetStorage returns the current storage backend for use by APOC functions. This allows subpackages to access the database without tight coupling.

func Initialize ΒΆ

func Initialize(storage storage.Storage, cfg *Config) error

Initialize sets up APOC with storage and configuration. This should be called once at application startup.

func IsAvailable ΒΆ

func IsAvailable(name string) bool

IsAvailable checks if a function is registered and enabled.

func List ΒΆ

func List() []string

List returns all registered function names.

func ListByCategory ΒΆ

func ListByCategory(category string) []string

ListByCategory returns all function names in a category.

func SetStorage ΒΆ

func SetStorage(s storage.Storage)

SetStorage updates the storage backend (for testing or reconfiguration).

Types ΒΆ

type Config ΒΆ

type Config struct {
	// Categories controls entire function categories
	// Keys: coll, text, math, convert, map, date, json, util, agg, node, path, algo, create
	Categories map[string]bool `yaml:"categories"`

	// Functions controls specific functions (overrides category settings)
	// Supports wildcards: "apoc.export.*": false
	Functions map[string]bool `yaml:"functions"`

	// Security settings
	Security SecurityConfig `yaml:"security"`

	// PluginsDir is the directory to auto-load .so plugins from (optional)
	// If set, all .so files in this directory are loaded on Initialize()
	// Can be set via NORNICDB_PLUGINS_DIR environment variable
	PluginsDir string `yaml:"plugins_dir"`
}

Config controls which APOC functions are enabled.

Example:

// Load from environment (Docker/K8s friendly)
cfg := apoc.LoadFromEnv()

// Or load from YAML file
cfg, err := apoc.LoadConfig("./apoc.yaml")

// Or use defaults
cfg := apoc.DefaultConfig()

func DefaultConfig ΒΆ

func DefaultConfig() *Config

DefaultConfig returns a configuration with all functions enabled.

func LoadConfig ΒΆ

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a YAML file.

func LoadConfigOrDefault ΒΆ

func LoadConfigOrDefault(path string) *Config

LoadConfigOrDefault loads config from file, or returns default if file doesn't exist.

func LoadFromEnv ΒΆ

func LoadFromEnv() *Config

LoadFromEnv loads APOC configuration from environment variables.

This is the recommended approach for Docker/Kubernetes deployments.

Environment Variables:

NORNICDB_PLUGINS_DIR           - Plugin directory path
NORNICDB_APOC_COLL_ENABLED          - Enable apoc.coll.* (default: true)
NORNICDB_APOC_TEXT_ENABLED          - Enable apoc.text.* (default: true)
NORNICDB_APOC_MATH_ENABLED          - Enable apoc.math.* (default: true)
NORNICDB_APOC_CONVERT_ENABLED       - Enable apoc.convert.* (default: true)
NORNICDB_APOC_MAP_ENABLED           - Enable apoc.map.* (default: true)
NORNICDB_APOC_DATE_ENABLED          - Enable apoc.date.* (default: true)
NORNICDB_APOC_JSON_ENABLED          - Enable apoc.json.* (default: true)
NORNICDB_APOC_UTIL_ENABLED          - Enable apoc.util.* (default: true)
NORNICDB_APOC_AGG_ENABLED           - Enable apoc.agg.* (default: true)
NORNICDB_APOC_NODE_ENABLED          - Enable apoc.node.* (default: true)
NORNICDB_APOC_PATH_ENABLED          - Enable apoc.path.* (default: true)
NORNICDB_APOC_ALGO_ENABLED          - Enable apoc.algo.* (default: true)
NORNICDB_APOC_CREATE_ENABLED        - Enable apoc.create.* (default: true)
NORNICDB_APOC_SECURITY_ALLOW_DYNAMIC_CREATION - Allow dynamic creation (default: true)
NORNICDB_APOC_SECURITY_ALLOW_FILE_ACCESS      - Legacy shorthand enabling both import and export file access
NORNICDB_APOC_SECURITY_ALLOW_IMPORT_FILE_ACCESS - Allow APOC import/load local file access (default: false)
NORNICDB_APOC_SECURITY_ALLOW_EXPORT_FILE_ACCESS - Allow APOC export local file access (default: false)
NORNICDB_APOC_SECURITY_ALLOW_REMOTE_URL_ACCESS - Allow APOC load/import HTTP(S) fetches (default: false)
NORNICDB_APOC_SECURITY_FILE_ACCESS_ROOT       - Restrict local APOC file URLs to this root when set
NORNICDB_APOC_SECURITY_MAX_COLLECTION_SIZE    - Max collection size (default: 100000)

Example:

os.Setenv("NORNICDB_PLUGINS_DIR", "/opt/nornicdb/plugins")
os.Setenv("NORNICDB_APOC_ALGO_ENABLED", "false")
cfg := apoc.LoadFromEnv()

func LoadFromEnvOrFile ΒΆ

func LoadFromEnvOrFile(filePath string) *Config

LoadFromEnvOrFile loads config from environment variables first, then falls back to file. Environment variables take precedence over file settings.

func (*Config) IsCategoryEnabled ΒΆ

func (c *Config) IsCategoryEnabled(category string) bool

IsCategoryEnabled checks if a category is enabled.

func (*Config) IsEnabled ΒΆ

func (c *Config) IsEnabled(functionName string) bool

IsEnabled checks if a specific function is enabled.

type Function ΒΆ

type Function struct {
	Name        string
	Category    string
	Handler     interface{}
	Description string
	Examples    []string
}

Function represents a registered APOC function.

func GetInfo ΒΆ

func GetInfo(name string) (*Function, bool)

GetInfo returns information about a function.

type SecurityConfig ΒΆ

type SecurityConfig struct {
	// AllowDynamicCreation permits apoc.create.* functions
	AllowDynamicCreation bool `yaml:"allow_dynamic_creation"`
	// AllowFileAccess is a legacy shorthand that enables both import and export
	// local file operations when true.
	AllowFileAccess bool `yaml:"allow_file_access"`
	// AllowImportFileAccess permits APOC import/load file system operations.
	AllowImportFileAccess bool `yaml:"allow_import_file_access"`
	// AllowExportFileAccess permits APOC export file system operations.
	AllowExportFileAccess bool `yaml:"allow_export_file_access"`
	// AllowRemoteURLAccess permits APOC load/import HTTP(S) fetches.
	AllowRemoteURLAccess bool `yaml:"allow_remote_url_access"`
	// RemoteURLAllowlist restricts APOC HTTP(S) fetches to explicitly approved
	// hosts. Entries are matched against URL hostnames and may be exact names
	// or wildcard suffixes like "*.example.com".
	RemoteURLAllowlist []string `yaml:"remote_url_allowlist"`
	// FileAccessRoot is the local import root used for APOC file URLs.
	// Empty means local file access, when enabled, is unrestricted.
	// When set, local file-like inputs are normalized and rebased under that
	// root, mirroring Neo4j's import-directory behavior.
	FileAccessRoot string `yaml:"file_access_root"`
	// MaxCollectionSize limits collection function input sizes
	MaxCollectionSize int `yaml:"max_collection_size"`
}

SecurityConfig contains security-related settings.

Directories ΒΆ

Path Synopsis
Package agg provides APOC aggregation functions.
Package agg provides APOC aggregation functions.
Package algo provides APOC graph algorithm functions.
Package algo provides APOC graph algorithm functions.
Package atomic provides APOC atomic operations.
Package atomic provides APOC atomic operations.
Package bitwise provides APOC bitwise operations.
Package bitwise provides APOC bitwise operations.
Package coll provides APOC collection manipulation functions.
Package coll provides APOC collection manipulation functions.
Package community provides APOC community detection functions.
Package community provides APOC community detection functions.
Package convert provides APOC type conversion functions.
Package convert provides APOC type conversion functions.
Package create provides APOC dynamic creation functions.
Package create provides APOC dynamic creation functions.
Package cypher provides APOC Cypher execution utilities.
Package cypher provides APOC Cypher execution utilities.
Package date provides APOC date/time functions.
Package date provides APOC date/time functions.
Package diff provides APOC diff operations.
Package diff provides APOC diff operations.
Package export provides APOC export functions.
Package export provides APOC export functions.
Package graph provides APOC graph manipulation functions.
Package graph provides APOC graph manipulation functions.
Package hashing provides APOC hashing functions.
Package hashing provides APOC hashing functions.
Package import provides APOC import functions.
Package import provides APOC import functions.
Package json provides APOC JSON functions.
Package json provides APOC JSON functions.
Package label provides functions for working with node labels.
Package label provides functions for working with node labels.
Package load provides APOC data loading functions.
Package load provides APOC data loading functions.
Package lock provides APOC locking functions.
Package lock provides APOC locking functions.
Package log provides APOC logging functions.
Package log provides APOC logging functions.
Package map provides APOC map manipulation functions.
Package map provides APOC map manipulation functions.
Package math provides APOC mathematical functions.
Package math provides APOC mathematical functions.
Package merge provides APOC merge operations.
Package merge provides APOC merge operations.
Package meta provides APOC metadata functions.
Package meta provides APOC metadata functions.
Package neighbors provides APOC neighbor traversal functions.
Package neighbors provides APOC neighbor traversal functions.
Package node provides APOC node operations.
Package node provides APOC node operations.
Package nodes provides APOC batch node operations.
Package nodes provides APOC batch node operations.
Package number provides APOC number formatting and parsing functions.
Package number provides APOC number formatting and parsing functions.
Package path provides APOC path finding functions.
Package path provides APOC path finding functions.
Package paths provides APOC advanced path operations.
Package paths provides APOC advanced path operations.
Package periodic provides APOC periodic execution functions.
Package periodic provides APOC periodic execution functions.
Package plugin provides a plugin system for loading APOC function packages.
Package plugin provides a plugin system for loading APOC function packages.
Package refactor provides APOC graph refactoring functions.
Package refactor provides APOC graph refactoring functions.
Package registry provides a plugin system for APOC functions.
Package registry provides a plugin system for APOC functions.
Package rel provides APOC relationship operations.
Package rel provides APOC relationship operations.
Package schema provides APOC schema management functions.
Package schema provides APOC schema management functions.
Package scoring provides APOC scoring and ranking functions.
Package scoring provides APOC scoring and ranking functions.
Package search provides APOC search functions.
Package search provides APOC search functions.
Package spatial provides APOC spatial/geographic functions.
Package spatial provides APOC spatial/geographic functions.
Package stats provides APOC statistics functions.
Package stats provides APOC statistics functions.
Package storage provides the storage interface for APOC functions.
Package storage provides the storage interface for APOC functions.
Package temporal provides APOC temporal/datetime functions.
Package temporal provides APOC temporal/datetime functions.
Package text provides APOC text processing functions.
Package text provides APOC text processing functions.
Package trigger provides APOC trigger functions.
Package trigger provides APOC trigger functions.
Package util provides APOC utility functions.
Package util provides APOC utility functions.
Package warmup provides APOC database warmup functions.
Package warmup provides APOC database warmup functions.
Package xml provides APOC XML processing functions.
Package xml provides APOC XML processing functions.

Jump to

Keyboard shortcuts

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