schema

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package schema provides APOC schema management functions.

This package implements all apoc.schema.* functions for managing database schema, constraints, and indexes.

Index

Constants

This section is empty.

Variables

Storage is the interface for database operations.

Functions

func Analyze

func Analyze() map[string]interface{}

Analyze analyzes schema usage.

Example:

apoc.schema.analyze() => analysis results

func Assert

func Assert(indexes, constraints map[string]interface{}) map[string]interface{}

Assert creates or validates schema constraints.

Example:

apoc.schema.assert({Person: ['name']}, {Person: [['email']]})

func Compare

func Compare(schema1, schema2 map[string]interface{}) map[string]interface{}

Compare compares two schemas.

Example:

apoc.schema.compare(schema1, schema2) => differences

func CreateConstraint

func CreateConstraint(label string, properties []string, constraintType string) error

CreateConstraint creates a constraint.

Example:

apoc.schema.constraint.create('Person', ['email'], 'UNIQUE') => constraint created

func CreateExistsConstraint

func CreateExistsConstraint(label string, properties []string) error

CreateExistsConstraint creates an exists constraint.

Example:

apoc.schema.constraint.exists('Person', ['name']) => constraint created

func CreateIndex

func CreateIndex(label string, properties []string) error

CreateIndex creates an index.

Example:

apoc.schema.index.create('Person', ['name']) => index created

func CreateNodeKeyConstraint

func CreateNodeKeyConstraint(label string, properties []string) error

CreateNodeKeyConstraint creates a node key constraint.

Example:

apoc.schema.constraint.nodeKey('Person', ['id']) => constraint created

func CreateUniqueConstraint

func CreateUniqueConstraint(label string, properties []string) error

CreateUniqueConstraint creates a unique constraint.

Example:

apoc.schema.constraint.unique('Person', ['email']) => constraint created

func DropConstraint

func DropConstraint(label string, properties []string) error

DropConstraint drops a constraint.

Example:

apoc.schema.constraint.drop('Person', ['email']) => constraint dropped

func DropIndex

func DropIndex(label string, properties []string) error

DropIndex drops an index.

Example:

apoc.schema.index.drop('Person', ['name']) => index dropped

func Export

func Export() map[string]interface{}

Export exports schema definition.

Example:

apoc.schema.export() => schema definition

func Import

func Import(schemaDef map[string]interface{}) error

Import imports schema definition.

Example:

apoc.schema.import(schemaDef) => imported

func Info

func Info() map[string]interface{}

Info returns comprehensive schema information.

Example:

apoc.schema.info() => {labels: [...], types: [...], constraints: [...], indexes: [...]}

func Labels

func Labels() []string

Labels returns all node labels.

Example:

apoc.schema.labels() => ['Person', 'Company', 'Product']

func NodeConstraintExists

func NodeConstraintExists(label string, properties []string) bool

NodeConstraintExists checks if a constraint exists.

Example:

apoc.schema.node.constraintExists('Person', ['email']) => true/false

func NodeIndexExists

func NodeIndexExists(label string, properties []string) bool

NodeIndexExists checks if an index exists.

Example:

apoc.schema.node.indexExists('Person', ['name']) => true/false

func Nodes

func Nodes() []map[string]interface{}

Nodes returns schema information for node labels.

Example:

apoc.schema.nodes() => [{label: 'Person', properties: [...]}]

func Optimize

func Optimize() map[string]interface{}

Optimize optimizes schema.

Example:

apoc.schema.optimize() => optimization results

func Properties

func Properties() []string

Properties returns all property keys in the database.

Example:

apoc.schema.properties.distinct() => ['name', 'age', 'email']

func PropertiesDistinct

func PropertiesDistinct(label string) []string

PropertiesDistinct returns distinct property keys.

Example:

apoc.schema.properties.distinct('Person') => ['name', 'age']

func Relationships

func Relationships() []map[string]interface{}

Relationships returns schema information for relationship types.

Example:

apoc.schema.relationships() => [{type: 'KNOWS', properties: [...]}]

func Restore

func Restore(snapshot map[string]interface{}) error

Restore restores from a schema snapshot.

Example:

apoc.schema.restore(snapshot) => restored

func Snapshot

func Snapshot() map[string]interface{}

Snapshot creates a schema snapshot.

Example:

apoc.schema.snapshot() => snapshot

func Stats

func Stats() map[string]interface{}

Stats returns schema statistics.

Example:

apoc.schema.stats() => {labelCount: 5, typeCount: 10, ...}

func Types

func Types() []string

Types returns all relationship types.

Example:

apoc.schema.types() => ['KNOWS', 'WORKS_AT', 'BOUGHT']

func Validate

func Validate() map[string]interface{}

Validate validates schema against data.

Example:

apoc.schema.validate() => {valid: true, errors: []}

Types

type ConstraintInfo

type ConstraintInfo struct {
	Name       string
	Label      string
	Properties []string
	Type       string
}

ConstraintInfo represents constraint information.

func NodeConstraints

func NodeConstraints() []*ConstraintInfo

NodeConstraints returns all node constraints.

Example:

apoc.schema.node.constraints() => constraint list

func RelationshipConstraints

func RelationshipConstraints() []*ConstraintInfo

RelationshipConstraints returns all relationship constraints.

Example:

apoc.schema.relationship.constraints() => constraint list

type IndexInfo

type IndexInfo struct {
	Name       string
	Label      string
	Properties []string
	Type       string
	State      string
	Unique     bool
}

IndexInfo represents index information.

func NodeIndexes

func NodeIndexes() []*IndexInfo

NodeIndexes returns all node indexes.

Example:

apoc.schema.node.indexes() => index list

func RelationshipIndexes

func RelationshipIndexes() []*IndexInfo

RelationshipIndexes returns all relationship indexes.

Example:

apoc.schema.relationship.indexes() => index list

type Node

type Node = storage.Node

Node represents a graph node.

Jump to

Keyboard shortcuts

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