@@ -36,6 +36,7 @@ describe('#integration examples', () => {
3636
3737 let driverGlobal
3838 let version
39+ let edition
3940 let originalTimeout
4041
4142 let consoleOverride
@@ -60,6 +61,7 @@ describe('#integration examples', () => {
6061 consoleOverride = { log : msg => consoleOverridePromiseResolve ( msg ) }
6162
6263 version = await sharedNeo4j . cleanupAndGetVersion ( driverGlobal )
64+ edition = await sharedNeo4j . getEdition ( driverGlobal )
6365 } )
6466
6567 afterAll ( async ( ) => {
@@ -690,6 +692,66 @@ describe('#integration examples', () => {
690692 ] )
691693 } )
692694
695+ it ( 'use another database example' , async ( ) => {
696+ if ( version . compareTo ( VERSION_4_0_0 ) < 0 || edition !== 'enterprise' ) {
697+ return
698+ }
699+
700+ const console = consoleOverride
701+ const consoleLoggedMsg = consoleOverridePromise
702+
703+ const driver = driverGlobal
704+ const systemSession = driver . session ( { database : 'system' } )
705+ try {
706+ await systemSession . run ( 'DROP DATABASE examples' )
707+ } catch ( err ) {
708+ // Database probably didn't exists
709+ }
710+
711+ try {
712+ await systemSession . run ( 'CREATE DATABASE examples' )
713+ } finally {
714+ await systemSession . close ( )
715+ }
716+
717+ // tag::database-selection[]
718+ const session = driver . session ( { database : 'examples' } )
719+ try {
720+ const result = await session . writeTransaction ( tx =>
721+ tx . run (
722+ 'CREATE (a:Greeting {message: "Hello, Example-Database"}) RETURN a.message'
723+ )
724+ )
725+
726+ const singleRecord = result . records [ 0 ]
727+ const greeting = singleRecord . get ( 0 )
728+
729+ console . log ( greeting )
730+ } finally {
731+ await session . close ( )
732+ }
733+
734+ const readSession = driver . session ( {
735+ database : 'examples' ,
736+ defaultAccessMode : neo4j . READ
737+ } )
738+ try {
739+ const result = await readSession . writeTransaction ( tx =>
740+ tx . run ( 'MATCH (a:Greeting) RETURN a.message' )
741+ )
742+
743+ const singleRecord = result . records [ 0 ]
744+ const greeting = singleRecord . get ( 0 )
745+
746+ console . log ( greeting )
747+ } finally {
748+ await readSession . close ( )
749+ }
750+ // end::database-selection[]
751+
752+ expect ( await consoleLoggedMsg ) . toContain ( 'Hello, Example-Database' )
753+ } )
754+
693755 it ( 'pass bookmarks example' , done => {
694756 const driver = driverGlobal
695757
0 commit comments