neo4j

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package neo4j is a database/sql driver for Neo4j, which runs Cypher over the Query API of HTTP. It registers the one name "neo4j" (D60), and takes a DSN of the form neo4j://user:pass@host:7474/database?key=value (D61).

db, err := sql.Open("neo4j", "neo4j://neo4j:pass@localhost:7474/neo4j")

The driver speaks HTTP to port 7474, or HTTPS to port 7473 with tls=true. A URL that the tools of Neo4j write, such as neo4j://host:7687, names the port of Bolt, which this driver does not speak.

The server binds each argument: sql.Named("k", v) fills $k, and a positional argument n fills $n, such as $1 (D64). Each value keeps its type in typed JSON (D62 and D63). A transaction is an explicit transaction of the Query API (D65). The server does not stop a query when the client disconnects, so the key cancel says how the driver stops one when its context ends (D67). docs/NEO4J.md holds what the driver knows about the server.

Index

Constants

View Source
const (
	// CancelTag starts each statement with a comment that names the
	// connection, and stops the statement with TERMINATE TRANSACTION. It is
	// the default.
	CancelTag = "tag"
	// CancelMetadata names the connection in txMetadata, and uses the tag on
	// a release older than 2026.04, which refuses txMetadata.
	CancelMetadata = "metadata"
	// CancelNone sends nothing, and the query runs on until it ends.
	CancelNone = "none"
)

The values of the key cancel, which say how the driver stops a query on the server when its context ends (D67).

View Source
const Name = "neo4j"

Name is the name that the driver registers with database/sql, and the scheme of its DSN.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Host is the host of the HTTP interface.
	Host string
	// Port is the port of the HTTP interface, 7474 by default, or 7473 with
	// TLS.
	Port int
	// TLS is true to speak HTTPS.
	TLS bool
	// User and Password are the credentials, sent with basic authentication.
	// With no user, the driver sends no credentials, for a server that runs
	// with authentication off.
	User     string
	Password string
	// Database is the database that each statement runs in, "neo4j" by
	// default.
	Database string
	// Cancel says how the driver stops a query when its context ends:
	// CancelTag, CancelMetadata or CancelNone (D67).
	Cancel string
}

Config is the configuration of a connector, which the DSN holds. The caller owns it (D7).

func ParseDSN

func ParseDSN(dsn string) (*Config, error)

ParseDSN parses a DSN of the form neo4j://user:pass@host:port/database?key=value (D27, D35 and D61).

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

FormatDSN returns the DSN of cfg, which ParseDSN reads back as cfg.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector opens connections to one server. It owns its transport, and every connection shares it. A caller can build one from a Config and open it with sql.OpenDB.

func NewConnector

func NewConnector(cfg Config) *Connector

NewConnector returns a Connector for cfg. The connector keeps a copy of cfg.

func (*Connector) Close

func (c *Connector) Close() error

Close closes the idle connections of the transport. database/sql calls it when the database closes.

func (*Connector) Connect

func (c *Connector) Connect(context.Context) (driver.Conn, error)

Connect satisfies driver.Connector. A connection holds no state on the server, except a transaction while one is open. Each connection has a random id, which names its statements for cancel (D67).

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver satisfies driver.Connector.

type Date

type Date time.Time

Date is a date with no time and no zone, such as 2026-09-27. Its time.Time is at midnight in UTC.

func (Date) String

func (d Date) String() string

String returns the date in the form of Neo4j.

type Driver

type Driver struct{}

Driver is the database/sql driver for Neo4j.

func (Driver) Open

func (Driver) Open(string) (driver.Conn, error)

Open satisfies driver.Driver. database/sql opens a connection through OpenConnector, and Open returns an error, because opening a connection needs a context.

func (Driver) OpenConnector

func (Driver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector satisfies driver.DriverContext. It parses the DSN.

type Duration

type Duration struct {
	Months  int64
	Days    int64
	Seconds int64
	Nanos   int64
}

Duration is a duration of Neo4j (D63). It keeps months and days apart from the seconds, because a month and a day have no fixed length, so a time.Duration cannot hold it. Nanos is from 0 to 999999999, and Seconds holds the sign of the time, as the server keeps them.

func (Duration) String

func (d Duration) String() string

String returns the duration in the form of Neo4j, such as P1Y2M3DT4H5M6.007S, or PT0S for no time.

type Error

type Error struct {
	// Code is the code of the error.
	Code string `json:"code"`
	// Message is the message of the error.
	Message string `json:"message"`
}

Error is one error that Neo4j reported, such as Neo.ClientError.Statement.SyntaxError (D66).

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type LocalDateTime

type LocalDateTime time.Time

LocalDateTime is a date and a time with no zone, such as 2026-09-27T10:00:00.123456789. Its time.Time is in UTC.

func (LocalDateTime) String

func (t LocalDateTime) String() string

String returns the date and the time in the form of Neo4j.

type LocalTime

type LocalTime time.Time

LocalTime is a time of day with no zone, such as 12:50:35.556123456. Its time.Time is on 0000-01-01 in UTC.

func (LocalTime) String

func (t LocalTime) String() string

String returns the time in the form of Neo4j.

type Node

type Node struct {
	// ElementID is the element id of the node.
	ElementID string
	// Labels are the labels of the node.
	Labels []string
	// Props are the properties of the node, each a Go value of D63.
	Props map[string]any
}

Node is a node of the graph (D63).

type Path

type Path struct {
	Nodes         []Node
	Relationships []Relationship
}

Path is a path of the graph (D63): its nodes, and the relationship between each node and the next.

type Point

type Point struct {
	SRID    int
	X, Y, Z float64
	Dims    int
}

Point is a point of Neo4j (D63), in the coordinate system that SRID names, such as 7203 for a cartesian point or 4326 for WGS 84. Dims is 2 or 3, and Z is zero for a point of two dimensions.

func (Point) String

func (p Point) String() string

String returns the point in the form of Neo4j, such as SRID=7203;POINT (1.5 2.5).

type Relationship

type Relationship struct {
	// ElementID is the element id of the relationship.
	ElementID string
	// StartElementID and EndElementID are the element ids of its nodes.
	StartElementID string
	EndElementID   string
	// Type is the type of the relationship.
	Type string
	// Props are the properties of the relationship, each a Go value of D63.
	Props map[string]any
}

Relationship is a relationship of the graph (D63).

type ResponseError

type ResponseError struct {
	// HTTPStatus is the status code of the response.
	HTTPStatus int
	// Errs are the errors, in the order that the server sent them.
	Errs []Error
}

ResponseError holds the errors of one response, with its HTTP status. The status is 202 for an error that follows some rows, and 4xx for a request that the server refused. Use errors.As to read an Error of it.

func (*ResponseError) Error

func (err *ResponseError) Error() string

Error satisfies the error interface.

func (*ResponseError) Unwrap

func (err *ResponseError) Unwrap() []error

Unwrap returns each Error, for errors.As and errors.Is.

type Time

type Time time.Time

Time is a time of day with an offset, such as 12:50:35.556+01:00. Its time.Time is on 0000-01-01, in a fixed zone of the offset.

func (Time) String

func (t Time) String() string

String returns the time and its offset in the form of Neo4j.

type Vector

type Vector struct {
	Coordinates any
}

Vector is a vector of Neo4j (D63). Coordinates is a []int8, an []int16, an []int32, an []int64, a []float32 or a []float64, by the type of the coordinates on the server. As an argument, a Vector is a vector, and a slice by itself is a list.

Jump to

Keyboard shortcuts

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