package neo4j
Import Path
github.com/neo4j/neo4j-go-driver/v4/neo4j (on go.dev)
Dependency Relation
imports 17 packages, and imported by one package
Involved Source Files
aliases.go
auth_tokens.go
config.go
consolelogger.go
directrouter.go
Package neo4j provides required functionality to connect and execute statements against a Neo4j Database.
error.go
result.go
result_helpers.go
resultsummary.go
session.go
transaction.go
transaction_config.go
useragent.go
Package-Level Type Names (total 54, in which 39 are exported)
AccessMode defines modes that routing driver decides to which cluster member
a connection should be opened.
func Driver.Session(accessMode AccessMode, bookmarks ...string) (Session, error)
const AccessModeRead
const AccessModeWrite
AuthToken contains credentials to be sent over to the neo4j server.
tokens map[string]interface{}
func BasicAuth(username string, password string, realm string) AuthToken
func CustomAuth(scheme string, username string, password string, realm string, parameters map[string]interface{}) AuthToken
func KerberosAuth(ticket string) AuthToken
func NoAuth() AuthToken
func NewDriver(target string, auth AuthToken, configurers ...func(*Config)) (Driver, error)
A Config contains options that can be used to customize certain
aspects of the driver
Resolver that would be used to resolve initial router address. This may
be useful if you want to provide more than one URL for initial router.
If not specified, the URL provided to NewDriver is used as the initial
router.
default: nil
Maximum amount of time to either acquire an idle connection from the pool
or create a new connection (when the pool is not full). Negative values
result in an infinite wait time where 0 value results in no timeout which
results in immediate failure when there are no available connections.
default: 1 * time.Minute
Logging target the driver will send its log outputs
Possible to use custom logger (implement log.Logger interface) or
use neo4j.ConsoleLogger.
default: No Op Logger (log.Void)
Maximum connection life time on pooled connections. Values less than
or equal to 0 disables the lifetime check.
default: 1 * time.Hour
Maximum number of connections per URL to allow on this driver. It
cannot be specified as 0 and negative values are interpreted as
math.MaxInt32.
default: 100
Maximum amount of time a retriable operation would continue retrying. It
cannot be specified as a negative value.
default: 30 * time.Second
RootCAs defines the set of certificate authorities that the driver trusts. If set
to nil, the driver uses hosts system certificates.
The trusted certificates are used to validate connections for URI schemes 'bolt+s'
and 'neo4j+s'.
Connect timeout that will be set on underlying sockets. Values less than
or equal to 0 results in no timeout being applied.
default: 5 * time.Second
Whether to enable TCP keep alive on underlying sockets.
default: true
Optionally override the user agent string sent to Neo4j server.
default: neo4j.UserAgent
func defaultConfig() *Config
func newSession(config *Config, router sessionRouter, pool sessionPool, mode db.AccessMode, bookmarks []string, databaseName string, fetchSize int, logger log.Logger, boltLogger log.BoltLogger) *session
func validateAndNormaliseConfig(config *Config) error
ConnectivityError represent errors caused by the driver not being able to connect to Neo4j services,
or lost connections.
inner error
(*T) Error() string
*T : error
Counters contains statistics about the changes made to the database made as part
of the statement execution.
The number of constraints added to the schema.
The number of constraints removed from the schema.
Whether there were any updates at all, eg. any of the counters are greater than 0.
The number of indexes added to the schema.
The number of indexes removed from the schema.
The number of labels added to nodes.
The number of labels removed from nodes.
The number of nodes created.
The number of nodes deleted.
( T) PropertiesSet() int
The number of relationships created.
The number of relationships deleted.
The number of system updates
*resultSummary
func ResultSummary.Counters() Counters
DatabaseInfo contains basic information of the database the query result has been obtained from.
( T) Name() string
internal/reflectlite.Type (interface)
io/fs.DirEntry (interface)
io/fs.FileInfo (interface)
*os.File
reflect.Type (interface)
*runtime.Func
*databaseInfo
*internal/reflectlite.arrayType
*internal/reflectlite.chanType
*internal/reflectlite.funcType
*internal/reflectlite.interfaceType
*internal/reflectlite.mapType
*internal/reflectlite.ptrType
*internal/reflectlite.rtype
*internal/reflectlite.sliceType
*internal/reflectlite.structType
*internal/reflectlite.structTypeUncommon
*io/fs.statDirEntry
*os.fileStat
*os.unixDirent
*reflect.arrayType
*reflect.chanType
*reflect.funcType
*reflect.funcTypeFixed128
*reflect.funcTypeFixed16
*reflect.funcTypeFixed32
*reflect.funcTypeFixed4
*reflect.funcTypeFixed64
*reflect.funcTypeFixed8
*reflect.interfaceType
*reflect.mapType
*reflect.ptrType
*reflect.rtype
*reflect.sliceType
*reflect.structType
*reflect.structTypeUncommon
func ResultSummary.Database() DatabaseInfo
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Driver represents a pool(s) of connections to a neo4j server or cluster. It's
safe for concurrent use.
Close the driver and all underlying connections
Creates a new session based on the specified session configuration.
Deprecated: Use NewSession instead
The url this driver is bootstrapped
Verifies that the driver can connect to a remote server or cluster by
establishing a network connection with the remote. Returns nil if succesful
or error describing the problem.
*driver
T : io.Closer
func NewDriver(target string, auth AuthToken, configurers ...func(*Config)) (Driver, error)
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
InputPosition contains information about a specific position in a statement
Column returns the column number referred to by this position; column numbers start at 1.
Line returns the line number referred to by this position; line numbers start at 1.
Offset returns the character offset referred to by this position; offset numbers start at 0.
*notification
func Notification.Position() InputPosition
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
LogLevel is the type that default logging implementations use for available
log levels
func ConsoleLogger(level LogLevel) *log.Console
const ERROR
Neo4jError represents errors originating from Neo4j service.
Alias for convenience. This error is defined in db package and
used internally.
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Notification represents notifications generated when executing a statement.
A notification can be visualized in a client pinpointing problems or other information about the statement.
Code returns a notification code for the discovered issue of this notification.
Description returns a longer description of this notification.
Position returns the position in the statement where this notification points to.
Not all notifications have a unique position to point to and in that case the position would be set to nil.
Severity returns the severity level of this notification.
Title returns a short summary of this notification.
*notification
func ResultSummary.Notifications() []Notification
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Plan describes the actual plan that the database planner produced and used (or will use) to execute your statement.
This can be extremely helpful in understanding what a statement is doing, and how to optimize it. For more details,
see the Neo4j Manual. The plan for the statement is a tree of plans - each sub-tree containing zero or more child
plans. The statement starts with the root plan. Each sub-plan is of a specific operator, which describes what
that part of the plan does - for instance, perform an index lookup or filter results.
The Neo4j Manual contains a reference of the available operator types, and these may differ across Neo4j versions.
Arguments returns the arguments for the operator used.
Many operators have arguments defining their specific behavior. This map contains those arguments.
Children returns zero or more child plans. A plan is a tree, where each child is another plan.
The children are where this part of the plan gets its input records - unless this is an operator that
introduces new records on its own.
Identifiers returns a list of identifiers used by this plan. Identifiers used by this part of the plan.
These can be both identifiers introduced by you, or automatically generated.
Operator returns the operation this plan is performing.
*plan
func Plan.Children() []Plan
func ResultSummary.Plan() Plan
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
ProfiledPlan is the same as a regular Plan - except this plan has been executed, meaning it also
contains detailed information about how much work each step of the plan incurred on the database.
Arguments returns the arguments for the operator used.
Many operators have arguments defining their specific behavior. This map contains those arguments.
Children returns zero or more child plans. A plan is a tree, where each child is another plan.
The children are where this part of the plan gets its input records - unless this is an operator that
introduces new records on its own.
DbHits returns the number of times this part of the plan touched the underlying data stores/
Identifiers returns a list of identifiers used by this plan. Identifiers used by this part of the plan.
These can be both identifiers introduced by you, or automatically generated.
Operator returns the operation this plan is performing.
Records returns the number of records this part of the plan produced.
*profile
func ProfiledPlan.Children() []ProfiledPlan
func ResultSummary.Profile() ProfiledPlan
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Collect fetches all remaining records and returns them.
Consume discards all remaining records and returns the summary information
about the statement execution.
Err returns the latest error that caused this Next to return false.
Keys returns the keys available on the result set.
Next returns true only if there is a record to be processed.
NextRecord returns true if there is a record to be processed, record parameter is set
to point to current record.
Record returns the current record.
Single returns one and only one record from the stream.
If the result stream contains zero or more than one records, error is returned.
*result
func Session.Run(cypher string, params map[string]interface{}, configurers ...func(*TransactionConfig)) (Result, error)
func Transaction.Run(cypher string, params map[string]interface{}) (Result, error)
func Collect(result Result, err error) ([]*Record, error)
func Single(result Result, err error) (*Record, error)
Counters returns statistics counts for the statement.
Database returns information about the database where the result is obtained from
Returns nil for Neo4j versions prior to v4.
Returns the default "neo4j" database for Community Edition servers.
Notifications returns a slice of notifications produced while executing the statement.
The list will be empty if no notifications produced while executing the statement.
Plan returns statement plan for the executed statement if available, otherwise null.
Profile returns profiled statement plan for the executed statement if available, otherwise null.
ResultAvailableAfter returns the time it took for the server to make the result available for consumption.
ResultConsumedAfter returns the time it took the server to consume the result.
Server returns basic information about the server where the statement is carried out.
Statement returns statement that has been executed.
StatementType returns type of statement that has been executed.
*resultSummary
func Result.Consume() (ResultSummary, error)
ServerAddress represents a host and port. Host can either be an IP address or a DNS name.
Both IPv4 and IPv6 hosts are supported.
Hostname returns the host portion of this ServerAddress.
Port returns the port portion of this ServerAddress.
*net/url.URL
func NewServerAddress(hostname string, port string) ServerAddress
ServerAddressResolver is a function type that defines the resolver function used by the routing driver to
resolve the initial address used to create the driver.
ServerInfo contains basic information of the server.
Address returns the address of the server.
( T) Agent() string
( T) ProtocolVersion() db.ProtocolVersion
Version returns the version of Neo4j running at the server.
Deprecated: since 4.3, this function is deprecated. It will be removed in 5.0. please use Agent, ProtocolVersion, or call the dbms.components procedure instead
*resultSummary
func ResultSummary.Server() ServerInfo
Session represents a logical connection (which is not tied to a physical connection)
to the server
BeginTransaction starts a new explicit transaction on this session
Close closes any open resources and marks this session as unusable
LastBookmark returns the bookmark received following the last successfully completed transaction.
If no bookmark was received or if this transaction was rolled back, the bookmark value will not be changed.
ReadTransaction executes the given unit of work in a AccessModeRead transaction with
retry logic in place
Run executes an auto-commit statement and returns a result
WriteTransaction executes the given unit of work in a AccessModeWrite transaction with
retry logic in place
*session
*sessionWithError
T : io.Closer
func Driver.NewSession(config SessionConfig) Session
func Driver.Session(accessMode AccessMode, bookmarks ...string) (Session, error)
SessionConfig is used to configure a new session, its zero value uses safe defaults.
AccessMode used when using Session.Run and explicit transactions. Used to route query to
to read or write servers when running in a cluster. Session.ReadTransaction and Session.WriteTransaction
does not rely on this mode.
Logging target the session will send its Bolt message traces
Possible to use custom logger (implement log.BoltLogger interface) or
use neo4j.ConsoleBoltLogger.
Bookmarks are the initial bookmarks used to ensure that the executing server is at least up
to date to the point represented by the latest of the provided bookmarks. After running commands
on the session the bookmark can be retrieved with Session.LastBookmark. All commands executing
within the same session will automatically use the bookmark from the previous command in the
session.
DatabaseName contains the name of the database that the commands in the session will execute on.
FetchSize defines how many records to pull from server in each batch.
From Bolt protocol v4 (Neo4j 4+) records can be fetched in batches as compared to fetching
all in previous versions.
If FetchSize is set to FetchDefault, the driver decides the appropriate size. If set to a positive value
that size is used if the underlying protocol supports it otherwise it is ignored.
To turn off fetching in batches and always fetch everything, set FetchSize to FetchAll.
If a single large result is to be retrieved this is the most performant setting.
func Driver.NewSession(config SessionConfig) Session
Params returns the statement's parameters.
Text returns the statement's text.
*resultSummary
func ResultSummary.Statement() Statement
StatementType defines the type of the statement
func ResultSummary.StatementType() StatementType
const StatementTypeReadOnly
const StatementTypeReadWrite
const StatementTypeSchemaWrite
const StatementTypeUnknown
const StatementTypeWriteOnly
Aliases to simplify client usage (fewer imports) and to provide some backwards
compatibility with 1.x driver.
A separate dbtype package is needed to avoid circular package references and to avoid
unnecessary copying/conversions between structs since serializing/deserializing is
handled within bolt package and bolt package is used from this package.
Transaction represents a transaction in the Neo4j database
Close rolls back the actual transaction if it's not already committed/rolled back
and closes all resources associated with this transaction
Commit commits the transaction
Rollback rolls back the transaction
Run executes a statement on this transaction and returns a result
*retryableTransaction
*transaction
T : io.Closer
func Session.BeginTransaction(configurers ...func(*TransactionConfig)) (Transaction, error)
TransactionConfig holds the settings for explicit and auto-commit transactions. Actual configuration is expected
to be done using configuration functions that are predefined, i.e. 'WithTxTimeout' and 'WithTxMetadata', or one
that you could write by your own.
Metadata is the configured transaction metadata that will be attached to the underlying transaction.
Timeout is the configured transaction timeout.
TransactionExecutionLimit error indicates that a retryable transaction has
failed due to reaching a limit like a timeout or maximum number of attempts.
Causes []string
Errors []error
(*T) Error() string
*T : error
func newTransactionExecutionLimit(errors []error, causes []string) *TransactionExecutionLimit
TransactionWork represents a unit of work that will be executed against the provided
transaction
func Session.ReadTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error)
func Session.WriteTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error)
Package-Level Functions (total 32, in which 23 are exported)
AsRecord passes any existing error or casts from to a record.
Use in combination with Single and transactional functions:
record, err := neo4j.AsRecord(session.ReadTransaction(func (tx neo4j.Transaction) {
return neo4j.Single(tx.Run(...))
}))
AsRecords passes any existing error or casts from to a slice of records.
Use in combination with Collect and transactional functions:
records, err := neo4j.AsRecords(session.ReadTransaction(func (tx neo4j.Transaction) {
return neo4j.Collect(tx.Run(...))
}))
BasicAuth generates a basic authentication token with provided username, password and realm
Collect loops through the result stream, collects records into a slice and returns the
resulting slice. Any error passed in or reported while navigating the result stream is
returned without any conversion.
records, err := neo4j.Collect(session.Run(...))
func ConsoleBoltLogger() *log.ConsoleBoltLogger func ConsoleLogger(level LogLevel) *log.Console
CustomAuth generates a custom authentication token with provided parameters
DateOf creates a neo4j.Date from time.Time.
Hour, minute, second and nanoseconds are set to zero and location is set to UTC.
Conversion can also be done by casting a time.Time to neo4j.Date but beware that time
components and location will be left as is but ignored when used as query parameter.
DurationOf creates neo4j.Duration from specified time parts.
IsConnectivityError returns true if the provided error is an instance of ConnectivityError.
IsNeo4jError returns true if the provided error is an instance of Neo4jError.
IsTransactionExecutionLimit returns true if the provided error is an instance of TransactionExecutionLimit.
IsUsageError returns true if the provided error is an instance of UsageError.
KerberosAuth generates a kerberos authentication token with provided base-64 encoded kerberos ticket
LocalDateTimeOf creates a neo4j.Local from time.Time.
Conversion can also be done by casting a time.Time to neo4j.LocalTime but beware that location
will be left as is but interpreted as local when used as query parameter.
LocalTimeOf creates a neo4j.LocalTime from time.Time.
Year, month and day are set to zero and location is set to local.
Conversion can also be done by casting a time.Time to neo4j.LocalTime but beware that date
components and location will be left as is but ignored when used as query parameter.
NewDriver is the entry point to the neo4j driver to create an instance of a Driver. It is the first function to
be called in order to establish a connection to a neo4j database. It requires a Bolt URI and an authentication
token as parameters and can also take optional configuration function(s) as variadic parameters.
In order to connect to a single instance database, you need to pass a URI with scheme 'bolt', 'bolt+s' or 'bolt+ssc'.
driver, err = NewDriver("bolt://db.server:7687", BasicAuth(username, password))
In order to connect to a causal cluster database, you need to pass a URI with scheme 'neo4j', 'neo4j+s' or 'neo4j+ssc'
and its host part set to be one of the core cluster members.
driver, err = NewDriver("neo4j://core.db.server:7687", BasicAuth(username, password))
You can override default configuration options by providing a configuration function(s)
driver, err = NewDriver(uri, BasicAuth(username, password), function (config *Config) {
config.MaxConnectionPoolSize = 10
})
NewServerAddress generates a ServerAddress with provided hostname and port information.
NoAuth generates an empty authentication token
OffsetTimeOf creates a neo4j.OffsetTime from time.Time.
Year, month and day are set to zero and location is set to "Offset" using zone offset from
time.Time.
Conversion can also be done by casting a time.Time to neo4j.OffsetTime but beware that date
components and location will be left as is but ignored when used as query parameter. Since
location will contain the original value, the value "offset" will not be used by the driver
but the actual name of the location in time.Time and that offset.
Single returns one and only one record from the result stream. Any error passed in
or reported while navigating the result stream is returned without any conversion.
If the result stream contains zero or more than one records error is returned.
record, err := neo4j.Single(session.Run(...))
WithTxMetadata returns a transaction configuration function that attaches metadata to a transaction.
To attach a metadata to an explicit transaction:
session.BeginTransaction(WithTxMetadata(map[string)interface{}{"work-id": 1}))
To attach a metadata to an auto-commit transaction:
session.Run("RETURN 1", nil, WithTxMetadata(map[string)interface{}{"work-id": 1}))
To attach a metadata to a read transaction function:
session.ReadTransaction(DoWork, WithTxMetadata(map[string)interface{}{"work-id": 1}))
To attach a metadata to a write transaction function:
session.WriteTransaction(DoWork, WithTxMetadata(map[string)interface{}{"work-id": 1}))
WithTxTimeout returns a transaction configuration function that applies a timeout to a transaction.
To apply a transaction timeout to an explicit transaction:
session.BeginTransaction(WithTxTimeout(5*time.Second))
To apply a transaction timeout to an auto-commit transaction:
session.Run("RETURN 1", nil, WithTxTimeout(5*time.Second))
To apply a transaction timeout to a read transaction function:
session.ReadTransaction(DoWork, WithTxTimeout(5*time.Second))
To apply a transaction timeout to a write transaction function:
session.WriteTransaction(DoWork, WithTxTimeout(5*time.Second))
Package-Level Constants (total 22, in which 14 are exported)
AccessModeRead tells the driver to use a connection to one of the 'Follower' or 'Read Replica'.
AccessModeWrite tells the driver to use a connection to 'Leader'
DEBUG is the level that debug messages are written
ERROR is the level that error messages are written
Turns off fetching records in batches.
Lets the driver decide fetch size
INFO is the level that info messages are written
StatementTypeReadOnly identifies a read-only statement
StatementTypeReadWrite identifies a read-write statement
StatementTypeSchemaWrite identifies a schema-write statement
StatementTypeUnknown identifies an unknown statement type
StatementTypeWriteOnly identifies a write-only statement
const UserAgent = "Go Driver/4.3"
WARNING is the level that warning messages are written
The pages are generated with Golds v0.4.2. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |