File tree Expand file tree Collapse file tree 7 files changed +24
-12
lines changed
neo4j-driver-deno/lib/core Expand file tree Collapse file tree 7 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -880,7 +880,10 @@ class Driver {
880
880
database : database ?? '' ,
881
881
connectionProvider,
882
882
bookmarks,
883
- config : this . _config ,
883
+ config : {
884
+ ...this . _config ,
885
+ homeDatabase
886
+ } ,
884
887
reactive,
885
888
impersonatedUser,
886
889
fetchSize,
Original file line number Diff line number Diff line change @@ -161,9 +161,9 @@ class ConnectionHolder implements ConnectionHolderInterface {
161
161
return this . _referenceCount
162
162
}
163
163
164
- initializeConnection ( ) : boolean {
164
+ initializeConnection ( homeDatabase ?: string ) : boolean {
165
165
if ( this . _referenceCount === 0 && ( this . _connectionProvider != null ) ) {
166
- this . _connectionPromise = this . _createConnectionPromise ( this . _connectionProvider )
166
+ this . _connectionPromise = this . _createConnectionPromise ( this . _connectionProvider , homeDatabase )
167
167
} else {
168
168
this . _referenceCount ++
169
169
return false
@@ -172,10 +172,10 @@ class ConnectionHolder implements ConnectionHolderInterface {
172
172
return true
173
173
}
174
174
175
- private async _createConnectionPromise ( connectionProvider : ConnectionProvider ) : Promise < Connection & Releasable | null > {
175
+ private async _createConnectionPromise ( connectionProvider : ConnectionProvider , homeDatabase ?: string ) : Promise < Connection & Releasable | null > {
176
176
return await connectionProvider . acquireConnection ( {
177
177
accessMode : this . _mode ,
178
- database : this . _database ,
178
+ database : ( this . _database === '' && homeDatabase !== undefined ) ? homeDatabase : this . _database ,
179
179
bookmarks : await this . _getBookmarks ( ) ,
180
180
impersonatedUser : this . _impersonatedUser ,
181
181
onDatabaseNameResolved : this . _onDatabaseNameResolved ,
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ class Session {
76
76
private readonly _log : Logger
77
77
private readonly _homeDatabaseCallback : Function | undefined
78
78
private readonly _auth : AuthToken | undefined
79
+ private readonly _homeDatabaseBestGuess
79
80
/**
80
81
* @constructor
81
82
* @protected
@@ -126,6 +127,7 @@ class Session {
126
127
this . _fetchSize = fetchSize
127
128
this . _onDatabaseNameResolved = this . _onDatabaseNameResolved . bind ( this )
128
129
this . _homeDatabaseCallback = homeDatabaseCallback
130
+ this . _homeDatabaseBestGuess = config ?. homeDatabase
129
131
this . _auth = auth
130
132
this . _getConnectionAcquistionBookmarks = this . _getConnectionAcquistionBookmarks . bind ( this )
131
133
this . _readConnectionHolder = new ConnectionHolder ( {
@@ -260,7 +262,7 @@ class Session {
260
262
resultPromise = Promise . reject (
261
263
newError ( 'Cannot run query in a closed session.' )
262
264
)
263
- } else if ( ! this . _hasTx && connectionHolder . initializeConnection ( ) ) {
265
+ } else if ( ! this . _hasTx && connectionHolder . initializeConnection ( this . _homeDatabaseBestGuess ) ) {
264
266
resultPromise = connectionHolder
265
267
. getConnection ( )
266
268
// Connection won't be null at this point since the initialize method
Original file line number Diff line number Diff line change @@ -880,7 +880,9 @@ class Driver {
880
880
database : database ?? '' ,
881
881
connectionProvider,
882
882
bookmarks,
883
- config : this . _config ,
883
+ config : { ...this . _config ,
884
+ homeDatabase
885
+ } ,
884
886
reactive,
885
887
impersonatedUser,
886
888
fetchSize,
Original file line number Diff line number Diff line change @@ -161,9 +161,9 @@ class ConnectionHolder implements ConnectionHolderInterface {
161
161
return this . _referenceCount
162
162
}
163
163
164
- initializeConnection ( ) : boolean {
164
+ initializeConnection ( homeDatabase ?: string ) : boolean {
165
165
if ( this . _referenceCount === 0 && ( this . _connectionProvider != null ) ) {
166
- this . _connectionPromise = this . _createConnectionPromise ( this . _connectionProvider )
166
+ this . _connectionPromise = this . _createConnectionPromise ( this . _connectionProvider , homeDatabase )
167
167
} else {
168
168
this . _referenceCount ++
169
169
return false
@@ -172,10 +172,10 @@ class ConnectionHolder implements ConnectionHolderInterface {
172
172
return true
173
173
}
174
174
175
- private async _createConnectionPromise ( connectionProvider : ConnectionProvider ) : Promise < Connection & Releasable | null > {
175
+ private async _createConnectionPromise ( connectionProvider : ConnectionProvider , homeDatabase ?: string ) : Promise < Connection & Releasable | null > {
176
176
return await connectionProvider . acquireConnection ( {
177
177
accessMode : this . _mode ,
178
- database : this . _database ,
178
+ database : ( this . _database === "" && homeDatabase !== undefined ) ? homeDatabase : this . _database ,
179
179
bookmarks : await this . _getBookmarks ( ) ,
180
180
impersonatedUser : this . _impersonatedUser ,
181
181
onDatabaseNameResolved : this . _onDatabaseNameResolved ,
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ class Session {
76
76
private readonly _log : Logger
77
77
private readonly _homeDatabaseCallback : Function | undefined
78
78
private readonly _auth : AuthToken | undefined
79
+ private readonly _homeDatabaseBestGuess
79
80
/**
80
81
* @constructor
81
82
* @protected
@@ -126,6 +127,7 @@ class Session {
126
127
this . _fetchSize = fetchSize
127
128
this . _onDatabaseNameResolved = this . _onDatabaseNameResolved . bind ( this )
128
129
this . _homeDatabaseCallback = homeDatabaseCallback
130
+ this . _homeDatabaseBestGuess = config ?. homeDatabase
129
131
this . _auth = auth
130
132
this . _getConnectionAcquistionBookmarks = this . _getConnectionAcquistionBookmarks . bind ( this )
131
133
this . _readConnectionHolder = new ConnectionHolder ( {
@@ -260,7 +262,7 @@ class Session {
260
262
resultPromise = Promise . reject (
261
263
newError ( 'Cannot run query in a closed session.' )
262
264
)
263
- } else if ( ! this . _hasTx && connectionHolder . initializeConnection ( ) ) {
265
+ } else if ( ! this . _hasTx && connectionHolder . initializeConnection ( this . _homeDatabaseBestGuess ) ) {
264
266
resultPromise = connectionHolder
265
267
. getConnection ( )
266
268
// Connection won't be null at this point since the initialize method
Original file line number Diff line number Diff line change @@ -551,6 +551,9 @@ describe('#integration driver', () => {
551
551
552
552
expect ( driver . homeDatabaseCache . get ( sharedNeo4j . authToken . principal ) ) . toBe ( 'neo4j' )
553
553
expect ( session1 . _database ) . toBe ( 'neo4j' )
554
+ const session2 = driver . session ( { auth : sharedNeo4j . authToken } )
555
+ expect ( session2 . _homeDatabaseBestGuess ) . toBe ( 'neo4j' )
556
+ await session2 . run ( 'CREATE () RETURN 43' )
554
557
} )
555
558
556
559
it ( 'should discard old connections' , async ( ) => {
You can’t perform that action at this time.
0 commit comments