Skip to content

Commit 5e7fff4

Browse files
committed
Expose database property in result summary
1 parent 3f1fb81 commit 5e7fff4

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/result-summary.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class ResultSummary {
105105
* @public
106106
*/
107107
this.resultAvailableAfter = metadata.result_available_after
108+
109+
/**
110+
* The database name where this summary is obtained from.
111+
* @type {{name: string}}
112+
* @public
113+
*/
114+
this.database = { name: metadata.db || null }
108115
}
109116

110117
_buildNotifications (notifications) {

test/bolt-v4.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ describe('Bolt V4 API', () => {
118118
done()
119119
})
120120
})
121+
122+
it('should return db.name as null in result summary', async () => {
123+
if (databaseSupportsBoltV4()) {
124+
return
125+
}
126+
127+
const session = driver.session()
128+
129+
try {
130+
const result = await session.readTransaction(tx => tx.run('RETURN 1'))
131+
132+
expect(result.summary.database).toBeTruthy()
133+
expect(result.summary.database.name).toBeNull()
134+
} finally {
135+
session.close()
136+
}
137+
})
121138
})
122139

123140
it('should fail if connecting to a non-existing database', async () => {
@@ -138,7 +155,17 @@ describe('Bolt V4 API', () => {
138155
}
139156
})
140157

158+
describe('default database', function () {
159+
it('should return database name in summary', async () => {
160+
await testDatabaseNameInSummary(null)
161+
})
162+
})
163+
141164
describe('neo4j database', () => {
165+
it('should return database name in summary', async () => {
166+
await testDatabaseNameInSummary('neo4j')
167+
})
168+
142169
it('should be able to create a node', async () => {
143170
if (!databaseSupportsBoltV4()) {
144171
return
@@ -186,6 +213,27 @@ describe('Bolt V4 API', () => {
186213
})
187214
})
188215

216+
async function testDatabaseNameInSummary (dbname) {
217+
if (!databaseSupportsBoltV4()) {
218+
return
219+
}
220+
221+
const neoSession = dbname
222+
? driver.session({ db: dbname })
223+
: driver.session()
224+
225+
try {
226+
const result = await neoSession.run('CREATE (n { id: $id }) RETURN n', {
227+
id: 5
228+
})
229+
230+
expect(result.summary.database).toBeTruthy()
231+
expect(result.summary.database.name).toBe(dbname || 'neo4j')
232+
} finally {
233+
neoSession.close()
234+
}
235+
}
236+
189237
function expectBoltV4NotSupportedError (error) {
190238
expect(
191239
error.message.indexOf(

0 commit comments

Comments
 (0)