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 ( // AuthBasic sends the user and the password with basic authentication. // It is the default. AuthBasic = dbimp.AuthBasic // AuthBearer sends the password as a Bearer token, and no user. Neo4j // takes one only from an identity provider of single sign on, and // refuses the scheme without one (measured). AuthBearer = dbimp.AuthBearer )
The values of the key auth, which say how the driver sends the password (D94 and D110).
const ( // CancelTag ends 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 and D95).
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 ¶
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 as Auth says. With no user
// and no password, the driver sends no credentials, for a server that
// runs with authentication off.
User string
Password string
// Auth is AuthBasic or AuthBearer (D94 and D110).
Auth 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 Driver ¶
type Driver struct{}
Driver is the database/sql driver for Neo4j.
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) AuthenticationRefused ¶ added in v0.24.0
AuthenticationRefused reports whether the server refused the credential. It returns what Is reports for dbimp.ErrAuthentication, and a caller that does not import this module reads it through an interface of its own (D227).
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 Option ¶ added in v0.6.0
Option sets an option of one statement or one transaction (D109). An option comes from the DSN, then from the context through WithOptions, then from an argument of the statement, and a later one wins. BeginTx takes no argument, so an option of a transaction comes from the DSN or through WithOptions only.
func WithCancel ¶ added in v0.6.0
WithCancel sets how the driver stops the statement on the server when its context ends: CancelTag, CancelMetadata or CancelNone, as the key cancel of the DSN does (D67).
func WithDatabase ¶ added in v0.6.0
WithDatabase sets the database of the statement or the transaction, which the path of the request names. A statement of a transaction runs in the database of the transaction, so another database there fails with dbimp.ErrNotSupported.
func WithParameter ¶ added in v0.6.0
WithParameter sets any key of the body of the request by its name, such as "includeCounters" or "impersonatedUser". The value is encoded with json/v2. A key named here replaces one that the driver sets itself, as in Couchbase.
func WithReadonly ¶ added in v0.6.0
WithReadonly makes the server refuse a statement that writes, with accessMode READ (measured). In a transaction, it applies to BeginTx.
func WithTimeout ¶ added in v0.6.0
WithTimeout sets the time that the server gives the statement, as maxExecutionTime, which counts whole seconds, so the driver rounds d up to the next second (measured by hand on 2026.09.0). The server stops a statement that runs longer, and the error arrives after its rows (recorded). 5.26.31 ignores maxExecutionTime (recorded), so on a release older than 2026.04 the statement fails with dbimp.ErrNotSupported (D109).
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 or 5xx for a request that the server refused, such as 500 for TransactionStartFailed on 5.26.31. 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.