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 ¶
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).
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).
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 ¶
NewConnector returns a Connector for cfg. The connector keeps a copy of cfg.
func (*Connector) Close ¶
Close closes the idle connections of the transport. database/sql calls it when the database closes.
type Date ¶
Date is a date with no time and no zone, such as 2026-09-27. Its time.Time is at midnight in UTC.
type Driver ¶
type Driver struct{}
Driver is the database/sql driver for Neo4j.
type Duration ¶
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.
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).
type LocalDateTime ¶
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 ¶
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.
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 ¶
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.
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.