The Modus Neo4j API allows you to run queries and mutations against a Neo4j database.

Import

To begin, import the neo4j namespace from the SDK:

Neo4j APIs

The APIs in the neo4j namespace are below, organized by category.

We’re constantly introducing new APIs through ongoing development with early users. Open an issue if you have ideas on what would make Modus even more powerful for your next app!

Functions

executeQuery

Execute a Neo4j query or mutation using a Neo4j query and parameters.

func ExecuteQuery(connectionName, query string, parameters map[string]any, opts ...Neo4jOption) (*EagerResult, error)
connectionName
string
required

Name of the connection, as defined in the manifest.

query
string
required

A Neo4j query to execute.

parameters
map[string]any
required

A map of parameters to pass to the query.

opts
Neo4jOption
required

Optional arguments to pass to the query. Specify the database name using the WithDbName option.

GetRecordValue

Get the value of a record at a given key, and cast as a type.

func GetRecordValue[T RecordValue](record *Record, key string) (T, error)
record
Record
required

The record to get the value from.

key
string
required

The key of the value to get.

T
RecordValue
required

The type to cast the value as.

Get

Get the value of a record object at a given key as a string.

func (r *Record) Get(key string) (string, error)
key
string
required

The key of the value to get.

AsMap

Convert a record object to a map.

func (r *Record) AsMap() map[string]string

GetProperty

Get the value of an Entity (Node, Path, or Relationship) property, and cast as a type.

func GetProperty[T PropertyValue](e Entity, key string) (T, error)
e
Entity
required

The entity to get the property from.

key
string
required

The key of the property to get.

T
PropertyValue
required

The type to cast the property as.

Types

EagerResult

The result of a Neo4j query or mutation.

type EagerResult struct {
  Keys    []string
  Records []*Record
}
Keys
string[]
required

The keys of the result.

Records
Record[]
required

The records of the result.

Record

A record in a Neo4j query result.

type Record struct {
  Values []string
  Keys   []string
}
Values
string[]
required

The values of the record.

Keys
string[]
required

The keys of the record.

RecordValue

A value of a record in a Neo4j query result.

type RecordValue interface {
  bool | int64 | float64 | string |
    time.Time |
    []byte | []any | map[string]any |
    Node | Relationship | Path | Point2D | Point3D
}

Entity

An interface representing possible entities in a Neo4j query result. Node, Relationship, and Path implement this interface.

type Entity interface {
  GetElementId() string
  GetProperties() map[string]any
}

Node

A node in a Neo4j query result.

type Node struct {
  ElementId string         `json:"ElementId"`
  Labels    []string       `json:"Labels"`
  Props     map[string]any `json:"Props"`
}
ElementId
string
required

The ID of the node.

Labels
string[]
required

The labels of the node.

Props
map[string]any
required

The properties of the node.

Relationship

A relationship in a Neo4j query result.

type Relationship struct {
  ElementId      string         `json:"ElementId"`
  StartElementId string         `json:"StartElementId"`
  EndElementId   string         `json:"EndElementId"`
  Type           string         `json:"Type"`
  Props          map[string]any `json:"Props"`
}
ElementId
string
required

The ID of the relationship.

StartElementId
string
required

The ID of the start node.

EndElementId
string
required

The ID of the end node.

Type
string
required

The type of the relationship.

Props
map[string]any
required

The properties of the relationship.

Path

A path in a Neo4j query result.

type Path struct {
  Nodes         []Node         `json:"Nodes"`
  Relationships []Relationship `json:"Relationships"`
}
Nodes
Node[]
required

The nodes in the path.

Relationships
Relationship[]
required

The relationships in the path.

PropertyValue

A value of a property in a Neo4j query result.

type PropertyValue interface {
  bool | int64 | float64 | string |
    time.Time | []byte | []any | Point2D | Point3D
}

Point2D

A 2D point in a Neo4j query result.

type Point2D struct {
  X            float64
  Y            float64
  SpatialRefId uint32
}
X
float64
required

The X coordinate of the point.

Y
float64
required

The Y coordinate of the point.

SpatialRefId
uint32
required

The spatial reference ID of the point.

Point3D

A 3D point in a Neo4j query result.

type Point3D struct {
  X            float64
  Y            float64
  Z            float64
  SpatialRefId uint32
}
X
float64
required

The X coordinate of the point.

Y
float64
required

The Y coordinate of the point.

Z
float64
required

The Z coordinate of the point.

SpatialRefId
uint32
required

The spatial reference ID of the point.