Documentation
¶
Overview ¶
Package bolt implements a driver for Neo4J's Bolt Protocol.
This package provides one standard driver and one "recording" driver. The standard driver is simply
bolt
It should be used in most circumstances.
The Recorder type implements driver.Driver and can be used to read from or create a recorded session. See Recorder's documentation for more information.
There are three main ways to query the database, checked in the following order:
1.) The first argument to any Query, Exec., etc is of the type Map and no other arguments are passed. This is the easiest and cleanest option. 2.) Every argument is of the type sql.NamedArg. Each argument will be interpreted as a a key-value pair. If the key == "", an error will be returned. 3.) An even number of arguments in key-value order, meaning the even-indexed values must be of the type string.
The connection URI format is:
bolt://[user[:password]]@[host][:port][?param1=value1&...]
Parameters are as follows:
- dial_timeout: Timeout for dialing a new connection in seconds.
- timeout: Read and write timeout in seconds.
- tls: Should the connection use TLS? 1 or 0.
- tls_ca_cert_file: Path to CA certificate file.
- tls_cert_file: Path to certificate file.
- tls_key_file: Path to key file.
- tls_no_verify: Should the connection _not_ verify TLS? 1 or 0.
Eenvironment variables can be used, although URI parameters will take precedence over envirnment variables. In the same order as above:
- BOLT_DRIVER_HOST
- BOLT_DRIVER_PORT
- BOLT_DRIVER_USER
- BOLT_DRIVER_PASS
- BOLT_DRIVER_TLS
- BOLT_DRIVER_TLS_CA_CERT_FILE
- BOLT_DRIVER_TLS_CERT_FILE
- BOLT_DRIVER_TLS_KEY_FILE
- BOLT_DRIVER_NO_VERIFY
Index ¶
- Constants
- Variables
- func DialOpen(d Dialer, name string) (driver.Conn, error)
- func Open(name string) (driver.Conn, error)
- func WithSummary(ctx context.Context) (context.Context, func() *Summary)
- type Array
- type Counters
- type Dialer
- type Event
- type Map
- type Notification
- type Plan
- type Position
- type Profile
- type Recorder
- type ServerInfo
- type Summary
- type Type
- type UnrecognizedResponseErr
Constants ¶
const ( // Version is the current version of this driver Version = "3.3" // ClientID is the id of this client ClientID = "SermoDigitalBolt/" + Version DefaultPort = "7687" // default port for regular socket connections DefaultHost = "localhost" // default host for regular socket connections Scheme = "bolt://" // Bolt protocol's URI scheme )
const ( // HostEnv is the environment variable read to gather the host information. HostEnv = "BOLT_DRIVER_HOST" // PortEnv is the environment variable read to gather the port information. PortEnv = "BOLT_DRIVER_PORT" // UserEnv is the environment variable read to gather the username. UserEnv = "BOLT_DRIVER_USER" // PassEnv is the environment variable read to gather the password. PassEnv = "BOLT_DRIVER_PASS" // TLSEnv is the environment variable read to determine whether the Open // and OpenNeo methods should attempt to connect with TLS. TLSEnv = "BOLT_DRIVER_TLS" // TLSNoVerifyEnv is the environment variable read to determine whether // the TLS certificate's verification should be skipped. TLSNoVerifyEnv = "BOLT_DRIVER_NO_VERIFY" // TLSCACertFileEnv is the environment variable read that should contain // the CA certificate's path. TLSCACertFileEnv = "BOLT_DRIVER_TLS_CA_CERT_FILE" // TLSCertFileEnv is the environment variable read that should contain the // public key path. TLSCertFileEnv = "BOLT_TLS_CERT_FILE" // TLSKeyFileEnv is the environment variable read that should contain the // private key path. TLSKeyFileEnv = "BOLT_TLS_KEY_FILE" )
const ( DefaultDriver = "bolt" RecordingDriver = "bolt-recorder" )
Variables ¶
var ErrInFailedTransaction = errors.New("bolt: operation inside failed transaction")
ErrInFailedTransaction is returned when an operation is attempted inside a failed transaction.
var ErrNotMap = errors.New("bolt: if one argument is passed it must of type Map")
ErrNotMap is returned when one argument is passed to a Query, Exec, etc. method and its type isn't Map.
var ErrRowsClosed = errors.New("bolt: rows have been closed")
ErrRowsClosed is returned when the Rows have already been closed.
var ErrStatementClosed = errors.New("bolt: statement is closed")
ErrStatementClosed is returned when an operation is attempted on a closed statement.
Functions ¶
func WithSummary ¶
WithSummary returns a context.Context that facilitates passing the summary of a Cypher query. The returned function is only valid after Rows.Close has been called or after Exec/ExecContext has returned. The function is idempotent.
Types ¶
type Array ¶
type Array []interface{}
Array implements sql.Scanner and should be used to retrieve, e.g., a list from sql.Rows.
type Counters ¶
type Counters struct { NodesCreated int64 NodesDeleted int64 RelationshipsCreated int64 RelationshipsDeleted int64 PropertiesSet int64 LabelsAdded int64 LabelsRemoved int64 IndicesAdded int64 IndicesRemoved int64 ConstraintsAdded int64 ConstraintsRemoved int64 }
Counters counts the number of different operations the query performed.
func (Counters) RowsAffected ¶
RowsAffected returns the number of nodes and relationships created and deleted during the query. It partially implements driver.Result.
type Dialer ¶
type Dialer interface { // Dial connects to the address on the named network. Dial(network, address string) (net.Conn, error) // DialTimeout acts like Dial but takes a timeout. The timeout should // included name resolution, if required. DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) }
Dialer is a generic interface for types that can dial network addresses.
func TLSDialer ¶
TLSDialer returns a Dialer that is compatible with Neo4j. It can be passed to DialOpen and DialOpenNeo. It reads configuration information from environment variables, although the function parameters take precedence. noVerify will only be read from an environment variable if noVerify is false.
type Event ¶
type Event struct { Timestamp int64 `json:"-"` Event []byte IsWrite bool Completed bool Error error }
Event represents a single recording (read or write) event in the recorder
type Map ¶
type Map map[string]interface{}
Map is a utility type. See the package docs for its use in Query, Exec, etc. calls. It also implements sql.Scanner and should be used to retrieve, e.g., properties from sql.Rows.
type Notification ¶
type Notification struct { // Code is the notification code. Code string // Title is a short summary of the notification. Title string // Description is a longer description of the notification. Description string // Position is the position in a query this notificaiton points to. Position Position // Severity is the severity level of the notification. Severity string }
Notification represents a notification that might occur during the exectution of a query.
type Plan ¶
type Plan struct { // Operation is the type of operation the plan is performing. Operation string // Args contains the arguments the planner uses to during its execution. Args map[string]interface{} // Identifiers are identifiers used by the plan and can be generated by // either the user or planner. Identifiers []string // Profile is the executed plan. Profile *Profile // Children returns the next level of the planning tree. Children []Plan }
Plan describes the plan the database planner used when executing the query.
type Position ¶
type Position struct { // Offset is the character offset this position points to, starting at 0. Offset int64 // Line is the line number this position points to, starting at 1. Line int64 // Column is the column number this position points to, starting at 1. Column int64 }
Position is the position in a query a notification points to.
type Profile ¶
type Profile struct { // Hits is the number of time the plan touched the underlying data stores. Hits int64 // Records is the number of records the plan produced. Records int64 }
Profile describes an executed plan.
type Recorder ¶
Recorder allows for recording and playback of a session. The Name field can be set and when closed the Recorder will write out the session to a gzipped JSON file with the specified name. For example
const name = "TestRecordedSession" sql.Register(name, &Recorder{Name: name}) db, err := sql.Open(name) if err != nil { ... } // Lots of code // The recording will be saved as "TestRecordedSession.json.gzip" if err := db.Close(); err != nil { ... }
Do note: a Recorder where Name == "" has already been registered using the name
bolt-recorder
and will create a random, timestamped file name.
func (*Recorder) Open ¶
Open opens a simulated Neo4j connection using pre-recorded data if name is an empty string. Otherwise, it opens up an actual connection using that to create a new recording.
type ServerInfo ¶
type ServerInfo struct { // Address is the remote address of the server where the query was executed. Address string // Version is a string indicating which version of the server executed the // query. Version string }
ServerInfo describes basic information on the server that ran the query.
type Summary ¶
type Summary struct { Query string Counters Counters Type Type Plan Plan Notifications []Notification AvailableAfter time.Duration ConsumedAfter time.Duration ServerInfo ServerInfo }
Summary lists details of the query, like profiling information and what type of statement was run.
type UnrecognizedResponseErr ¶
type UnrecognizedResponseErr struct {
// contains filtered or unexported fields
}
UnrecognizedResponseErr is an error used when the server sends a reply this library cannot recognize. It might indicate a version mismatch or a library bug.
func (UnrecognizedResponseErr) Error ¶
func (u UnrecognizedResponseErr) Error() string
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package encoding is used to encode/decode data going to/from the bolt protocol.
|
Package encoding is used to encode/decode data going to/from the bolt protocol. |
Package structures contains various structures which are used by the Bolt protocol
|
Package structures contains various structures which are used by the Bolt protocol |
graph
Package graph contains structs that can be returned from the Neo4j Graph
|
Package graph contains structs that can be returned from the Neo4j Graph |
messages
Package messages contains structs that represent the messages that get sent using the Bolt protocol
|
Package messages contains structs that represent the messages that get sent using the Bolt protocol |