Skip to content

Commit 5026681

Browse files
committed
Add documentation comments
1 parent 404c7e8 commit 5026681

29 files changed

Lines changed: 289 additions & 82 deletions

neo4j/config_resolver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ import (
2525
"github.com/neo4j-drivers/gobolt"
2626
)
2727

28+
// ServerAddress represents a host and port. Host can either be an IP address or a DNS name.
29+
// Both IPv4 and IPv6 hosts are supported.
2830
type ServerAddress interface {
31+
// Hostname returns the host portion of this ServerAddress.
2932
Hostname() string
33+
// Port returns the port portion of this ServerAddress.
3034
Port() string
3135
}
3236

37+
// ServerAddressResolver is an interface that defines a resolver function used by the routing driver to
38+
// resolve the initial address used to create the driver.
3339
type ServerAddressResolver interface {
40+
// Resolve resolves the given address to a set of other addresses. If the returned slice is empty, the driver
41+
// will continue using the original address.
3442
Resolve(address ServerAddress) []ServerAddress
3543
}
3644

@@ -51,6 +59,7 @@ func newServerAddressUrl(hostname string, port string) *url.URL {
5159
return &url.URL{Host: hostAndPort}
5260
}
5361

62+
// A helper function that generates a ServerAddress with provided hostname and port information.
5463
func NewServerAddress(hostname string, port string) ServerAddress {
5564
return newServerAddressUrl(hostname, port)
5665
}

neo4j/driver.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20+
// Package neo4j provides required functionality to connect and execute statements against a Neo4j Database.
2021
package neo4j
2122

2223
import (
@@ -45,7 +46,21 @@ type Driver interface {
4546
Close() error
4647
}
4748

48-
// NewDriver is the entry method to the neo4j driver to create an instance of a Driver
49+
// NewDriver is the entry point to the neo4j driver to create an instance of a Driver. It is the first function to
50+
// be called in order to establish a connection to a neo4j database. It requires a Bolt URI and an authentication
51+
// token as parameters and can also take optional configuration function(s) as variadic parameters.
52+
//
53+
// In order to connect to a single instance database, you need to pass a URI with scheme 'bolt'
54+
// driver, err = NewDriver("bolt://db.server:7687", BasicAuth(username, password))
55+
//
56+
// In order to connect to a causal cluster database, you need to pass a URI with scheme 'bolt+routing' and its host
57+
// part set to be one of the core cluster members.
58+
// driver, err = NewDriver("bolt+routing://core.db.server:7687", BasicAuth(username, password))
59+
//
60+
// You can override default configuration options by providing a configuration function(s)
61+
// driver, err = NewDriver(uri, BasicAuth(username, password), function (config *Config) {
62+
// config.MaxConnectionPoolSize = 10
63+
// })
4964
func NewDriver(target string, auth AuthToken, configurers ...func(*Config)) (Driver, error) {
5065
parsed, err := url.Parse(target)
5166
if err != nil {

neo4j/record.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ package neo4j
2222
// Record contains ordered keys and values that are returned from a statement executed
2323
// on the server
2424
type Record interface {
25+
// Keys returns the keys available
2526
Keys() []string
27+
// Values returns the values
2628
Values() []interface{}
29+
// Get returns the value (if any) corresponding to the given key
2730
Get(key string) (interface{}, bool)
31+
// GetByIndex returns the value at given index
2832
GetByIndex(index int) interface{}
2933
}

neo4j/record_impl.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,19 @@ package neo4j
2121

2222
import "errors"
2323

24-
// Record contains ordered keys and values that are returned from a statement executed
25-
// on the server
2624
type neoRecord struct {
2725
keys []string
2826
values []interface{}
2927
}
3028

31-
// Keys returns the keys available
3229
func (record *neoRecord) Keys() []string {
3330
return record.keys
3431
}
3532

36-
// Values returns the values
3733
func (record *neoRecord) Values() []interface{} {
3834
return record.values
3935
}
4036

41-
// Get returns the value (if any) corresponding to the given key
4237
func (record *neoRecord) Get(key string) (interface{}, bool) {
4338
for i := range record.keys {
4439
if record.keys[i] == key {
@@ -49,7 +44,6 @@ func (record *neoRecord) Get(key string) (interface{}, bool) {
4944
return nil, false
5045
}
5146

52-
// GetByIndex returns the value at given index
5347
func (record *neoRecord) GetByIndex(index int) interface{} {
5448
if len(record.values) <= index {
5549
panic(errors.New("index out of bounds"))

neo4j/result.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919

2020
package neo4j
2121

22+
// Result provides access to the result of the executing statement.
2223
type Result interface {
24+
// Keys returns the keys available on the result set.
2325
Keys() ([]string, error)
26+
// Next returns true only if there is a record to be processed.
2427
Next() bool
28+
// Err returns the latest error that caused this Next to return false.
2529
Err() error
30+
// Record returns the current record.
2631
Record() Record
32+
// Summary returns the summary information about the statement execution.
2733
Summary() (ResultSummary, error)
34+
// Consume consumes the entire result and returns the summary information
35+
// about the statement execution.
2836
Consume() (ResultSummary, error)
2937
}

neo4j/result_impl.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/neo4j-drivers/gobolt"
2626
)
2727

28-
// Result provides access to the result of the executing statement
2928
type neoResult struct {
3029
keys []string
3130
records []Record
@@ -96,7 +95,6 @@ func (result *neoResult) collectRecord(fields []interface{}) {
9695
}
9796
}
9897

99-
// Keys returns the keys available on the result set
10098
func (result *neoResult) Keys() ([]string, error) {
10199
for !result.runCompleted {
102100
if currentResult, err := result.runner.receive(); currentResult == result && err != nil {
@@ -107,7 +105,6 @@ func (result *neoResult) Keys() ([]string, error) {
107105
return result.keys, nil
108106
}
109107

110-
// Next returns true only if there is a record to be processed
111108
func (result *neoResult) Next() bool {
112109
if result.err != nil {
113110
return false
@@ -135,17 +132,14 @@ func (result *neoResult) Next() bool {
135132
return result.current != nil
136133
}
137134

138-
// Err returns the latest error that caused this Next to return false
139135
func (result *neoResult) Err() error {
140136
return result.err
141137
}
142138

143-
// Record returns the current record
144139
func (result *neoResult) Record() Record {
145140
return result.current
146141
}
147142

148-
// Summary returns the summary information about the statement execution
149143
func (result *neoResult) Summary() (ResultSummary, error) {
150144
for result.err == nil && !result.resultCompleted {
151145
if _, err := result.runner.receive(); err != nil {

neo4j/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (runner *statementRunner) runStatement(statement *neoStatement) (Result, er
195195
return nil, err
196196
}
197197

198-
runHandle, err := runner.connection.Run(statement.cypher, &statement.params)
198+
runHandle, err := runner.connection.Run(statement.text, &statement.params)
199199
if err != nil {
200200
defer runner.closeConnection()
201201

neo4j/runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = Describe("Runner", func() {
5757
mockConnection.EXPECT().Server(),
5858
)
5959

60-
_, err := runner.runStatement(&neoStatement{cypher: "RETURN 1"})
60+
_, err := runner.runStatement(&neoStatement{text: "RETURN 1"})
6161

6262
Expect(err).To(BeNil())
6363
})

neo4j/session.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919

2020
package neo4j
2121

22+
// Session represents a logical connection (which is not tied to a physical connection)
23+
// to the server
2224
type Session interface {
25+
// LastBookmark returns the bookmark received following the last successfully completed transaction.
26+
// If no bookmark was received or if this transaction was rolled back, the bookmark value will not be changed.
2327
LastBookmark() string
28+
// BeginTransaction starts a new explicit transaction on this session
2429
BeginTransaction(configurers ...func(*TransactionConfig)) (Transaction, error)
30+
// ReadTransaction executes the given unit of work in a AccessModeRead transaction with
31+
// retry logic in place
2532
ReadTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error)
33+
// WriteTransaction executes the given unit of work in a AccessModeWrite transaction with
34+
// retry logic in place
2635
WriteTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error)
36+
// Run executes an auto-commit statement and returns a result
2737
Run(cypher string, params map[string]interface{}, configurers ...func(*TransactionConfig)) (Result, error)
38+
// Close closes any open resources and marks this session as unusable
2839
Close() error
2940
}

neo4j/session_impl.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"sync/atomic"
2525
)
2626

27-
// Session represents a logical connection (which is not tied to a physical connection)
28-
// to the server
2927
type neoSession struct {
3028
driver *goboltDriver
3129
accessMode AccessMode
@@ -119,29 +117,22 @@ func (session *neoSession) LastBookmark() string {
119117
return session.lastBookmark
120118
}
121119

122-
// BeginTransaction starts a new explicit transaction on this session
123120
func (session *neoSession) BeginTransaction(configurers ...func(*TransactionConfig)) (Transaction, error) {
124121
return beginTransactionInternal(session, session.accessMode, configurers...)
125122
}
126123

127-
// ReadTransaction executes the given unit of work in a AccessModeRead transaction with
128-
// retry logic in place
129124
func (session *neoSession) ReadTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error) {
130125
return runTransaction(session, AccessModeRead, work, configurers...)
131126
}
132127

133-
// WriteTransaction executes the given unit of work in a AccessModeWrite transaction with
134-
// retry logic in place
135128
func (session *neoSession) WriteTransaction(work TransactionWork, configurers ...func(*TransactionConfig)) (interface{}, error) {
136129
return runTransaction(session, AccessModeWrite, work, configurers...)
137130
}
138131

139-
// Run executes an auto-commit statement and returns a result
140132
func (session *neoSession) Run(cypher string, params map[string]interface{}, configurers ...func(*TransactionConfig)) (Result, error) {
141-
return runStatementOnSession(session, &neoStatement{cypher: cypher, params: params}, configurers...)
133+
return runStatementOnSession(session, &neoStatement{text: cypher, params: params}, configurers...)
142134
}
143135

144-
// Close closes any open resources and marks this session as unusable
145136
func (session *neoSession) Close() error {
146137
if atomic.CompareAndSwapInt32(&session.open, 1, 0) {
147138
if err := closeRunner(session); err != nil {

0 commit comments

Comments
 (0)