/
connection.go
120 lines (109 loc) · 4.38 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Package db defines generic database functionality.
package db
import (
"github.com/neo4j/neo4j-go-driver/v4/neo4j/log"
"time"
)
// Definitions of these should correspond to public API
type AccessMode int
const (
WriteMode AccessMode = 0
ReadMode AccessMode = 1
)
type (
TxHandle uint64
StreamHandle interface{}
)
type Command struct {
Cypher string
Params map[string]interface{}
FetchSize int
}
type TxConfig struct {
Mode AccessMode
Bookmarks []string
Timeout time.Duration
Meta map[string]interface{}
}
// Connection defines an abstract database server connection.
type Connection interface {
TxBegin(txConfig TxConfig) (TxHandle, error)
TxRollback(tx TxHandle) error
TxCommit(tx TxHandle) error
Run(cmd Command, txConfig TxConfig) (StreamHandle, error)
RunTx(tx TxHandle, cmd Command) (StreamHandle, error)
// Keys for the specified stream.
Keys(streamHandle StreamHandle) ([]string, error)
// Moves to next item in the stream.
// If error is nil, either Record or Summary has a value, if Record is nil there are no more records.
// If error is non nil, neither Record or Summary has a value.
Next(streamHandle StreamHandle) (*Record, *Summary, error)
// Discards all records on the stream and returns the summary otherwise it will return the error.
Consume(streamHandle StreamHandle) (*Summary, error)
// Buffers all records on the stream, records, summary and error will be received through call to Next
// The Connection implementation should preserve/buffer streams automatically if needed when new
// streams are created and the server doesn't support multiple streams. Use Buffer to force
// buffering before calling Reset to get all records and the bookmark.
Buffer(streamHandle StreamHandle) error
// Returns bookmark from last committed transaction or last finished auto-commit transaction.
// Note that if there is an ongoing auto-commit transaction (stream active) the bookmark
// from that is not included, use Buffer or Consume to end the stream with a bookmark.
// Empty string if no bookmark.
Bookmark() string
// Returns name of the remote server
ServerName() string
// Returns server version on pattern Neo4j/1.2.3
ServerVersion() string
// Returns true if the connection is fully functional.
// Implementation of this should be passive, no pinging or similair since it might be
// called rather frequently.
IsAlive() bool
// Returns the point in time when this connection was established.
Birthdate() time.Time
// Resets connection to same state as directly after a connect.
// Active streams will be discarded and the bookmark will be lost.
Reset()
ForceReset() error
// Closes the database connection as well as any underlying connection.
// The instance should not be used after being closed.
Close()
// Gets routing table for specified database name or the default database if
// database equals DefaultDatabase. If the underlying connection does not support
// multiple databases, DefaultDatabase should be used as database.
GetRoutingTable(context map[string]string, bookmarks []string, database string) (*RoutingTable, error)
// Sets Bolt message logger on already initialized connections
SetBoltLogger(boltLogger log.BoltLogger)
}
type RoutingTable struct {
TimeToLive int
Routers []string
Readers []string
Writers []string
}
// Marker for using the default database instance.
const DefaultDatabase = ""
// If database server connection supports selecting which database instance on the server
// to connect to. Prior to Neo4j 4 there was only one database per server.
type DatabaseSelector interface {
// Should be called immediately after Reset. Not allowed to call multiple times with different
// databases without a reset inbetween.
SelectDatabase(database string)
}