Skip to content

Commit 1b6df2d

Browse files
authored
Improve documentation of SessionConfig#Database
1 parent 576d8e0 commit 1b6df2d

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

neo4j/session_with_context.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,37 @@ type SessionConfig struct {
8282
// within the same session will automatically use the bookmark from the previous command in the
8383
// session.
8484
Bookmarks Bookmarks
85-
// DatabaseName contains the name of the database that the commands in the session will execute on.
85+
// DatabaseName sets the target database name for the queries executed within the session created with this
86+
// configuration.
87+
// Usage of Cypher clauses like USE is not a replacement for this option.
88+
// Drive​r sends Cypher to the server for processing.
89+
// This option has no explicit value by default, but it is recommended to set one if the target database is known
90+
// in advance. This has the benefit of ensuring a consistent target database name throughout the session in a
91+
// straightforward way and potentially simplifies driver logic as well as reduces network communication resulting
92+
// in better performance.
93+
// When no explicit name is set, the driver behavior depends on the connection URI scheme supplied to the driver on
94+
// instantiation and Bolt protocol version.
95+
//
96+
// Specifically, the following applies:
97+
//
98+
// - for bolt schemes
99+
// queries are dispatched to the server for execution without explicit database name supplied,
100+
// meaning that the target database name for query execution is determined by the server.
101+
// It is important to note that the target database may change (even within the same session), for instance if the
102+
// user's home database is changed on the server.
103+
//
104+
// - for neo4j schemes
105+
// providing that Bolt protocol version 4.4, which was introduced with Neo4j server 4.4, or above
106+
// is available, the driver fetches the user's home database name from the server on first query execution
107+
// within the session and uses the fetched database name explicitly for all queries executed within the session.
108+
// This ensures that the database name remains consistent within the given session. For instance, if the user's
109+
// home database name is 'movies' and the server supplies it to the driver upon database name fetching for the
110+
// session, all queries within that session are executed with the explicit database name 'movies' supplied.
111+
// Any change to the user’s home database is reflected only in sessions created after such change takes effect.
112+
// This behavior requires additional network communication.
113+
// In clustered environments, it is strongly recommended to avoid a single point of failure.
114+
// For instance, by ensuring that the connection URI resolves to multiple endpoints.
115+
// For older Bolt protocol versions, the behavior is the same as described for the bolt schemes above.
86116
DatabaseName string
87117
// FetchSize defines how many records to pull from server in each batch.
88118
// From Bolt protocol v4 (Neo4j 4+) records can be fetched in batches as compared to fetching

0 commit comments

Comments
 (0)