@@ -36,6 +36,7 @@ describe('#integration examples', () => {
36
36
37
37
let driverGlobal
38
38
let version
39
+ let edition
39
40
let originalTimeout
40
41
41
42
let consoleOverride
@@ -60,6 +61,7 @@ describe('#integration examples', () => {
60
61
consoleOverride = { log : msg => consoleOverridePromiseResolve ( msg ) }
61
62
62
63
version = await sharedNeo4j . cleanupAndGetVersion ( driverGlobal )
64
+ edition = await sharedNeo4j . getEdition ( driverGlobal )
63
65
} )
64
66
65
67
afterAll ( async ( ) => {
@@ -690,6 +692,66 @@ describe('#integration examples', () => {
690
692
] )
691
693
} )
692
694
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
+
693
755
it ( 'pass bookmarks example' , done => {
694
756
const driver = driverGlobal
695
757
0 commit comments