@@ -33,8 +33,8 @@ describe('examples', function() {
33
33
34
34
beforeEach ( function ( done ) {
35
35
var neo4j = neo4jv1 ;
36
- // tag::construct-driver[]
37
- driverGlobal = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) ) ;
36
+ //tag::construct-driver[]
37
+ driverGlobal = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) ) ;
38
38
//end::construct-driver[]
39
39
sessionGlobal = driverGlobal . session ( ) ;
40
40
@@ -61,25 +61,28 @@ describe('examples', function() {
61
61
// tag::minimal-example[]
62
62
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) ) ;
63
63
var session = driver . session ( ) ;
64
- session . run ( "CREATE (neo:Person {name:'Neo', age:23})" ) ;
65
64
session
66
- . run ( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
65
+ . run ( "CREATE (a:Person {name:'Arthur', title:'King'})" )
66
+ . then ( function ( )
67
+ {
68
+ return session . run ( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
69
+ } )
67
70
. then ( function ( result ) {
68
- console . log ( "Neo is " + result . records [ 0 ] . get ( "p.age" ) . toInt ( ) + " years old." ) ;
71
+ console . log ( result . records [ 0 ] . get ( "title" ) + " " + result . records [ 0 ] . get ( "name" ) ) ;
69
72
session . close ( ) ;
70
73
driver . close ( ) ;
71
- } ) ;
74
+ } )
72
75
// end::minimal-example[]
73
- setTimeout ( function ( ) {
74
- expect ( out [ 0 ] ) . toBe ( "Neo is 23 years old. " ) ;
75
- done ( ) ;
76
- } , 500 ) ;
76
+ . then ( function ( ) {
77
+ expect ( out [ 0 ] ) . toBe ( "King Arthur " ) ;
78
+ done ( ) ;
79
+ } ) ;
77
80
} ) ;
78
81
79
82
it ( 'should be able to configure session pool size' , function ( done ) {
80
83
var neo4j = neo4jv1 ;
81
84
// tag::configuration[]
82
- var driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) , { connectionPoolSize : 50 } ) ;
85
+ var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , { connectionPoolSize : 50 } ) ;
83
86
//end::configuration[]
84
87
85
88
var s = driver . session ( ) ;
@@ -89,123 +92,175 @@ describe('examples', function() {
89
92
console . log ( theOnesCreated ) ;
90
93
s . close ( ) ;
91
94
driver . close ( ) ;
92
- } ) ;
93
-
94
- setTimeout ( function ( ) {
95
- expect ( out [ 0 ] ) . toBe ( 1 ) ;
96
- done ( ) ;
97
- } , 500 ) ;
95
+ } )
96
+ . then ( function ( ) {
97
+ expect ( out [ 0 ] ) . toBe ( 1 ) ;
98
+ done ( ) ;
99
+ } ) ;
98
100
} ) ;
99
101
100
102
it ( 'should document a statement' , function ( done ) {
101
103
var session = sessionGlobal ;
102
- var resultPromise =
103
104
// tag::statement[]
104
105
session
105
- . run ( "CREATE (p:Person { name: {name} })" , { name : "The One" } )
106
+ . run ( "CREATE (person:Person {name: {name}})" , { name : "Arthur" } )
107
+ // end::statement[]
106
108
. then ( function ( result ) {
107
109
var theOnesCreated = result . summary . updateStatistics . nodesCreated ( ) ;
108
110
console . log ( "There were " + theOnesCreated + " the ones created." )
111
+ } )
112
+ . then ( function ( ) {
113
+ expect ( out [ 0 ] ) . toBe ( "There were 1 the ones created." ) ;
114
+ done ( ) ;
109
115
} ) ;
110
- // end::statement[]
111
-
112
- // Then
113
- resultPromise . then ( function ( ) {
114
- expect ( out [ 0 ] ) . toBe ( "There were 1 the ones created." ) ;
115
- done ( ) ;
116
- } ) ;
117
116
} ) ;
118
117
119
118
it ( 'should document a statement without parameters' , function ( done ) {
120
119
var session = sessionGlobal ;
121
- var resultPromise =
122
120
// tag::statement-without-parameters[]
123
121
session
124
- . run ( "CREATE (p:Person { name: 'The One ' })" )
125
-
122
+ . run ( "CREATE (p:Person { name: 'Arthur ' })" )
123
+ // end::statement-without-parameters[]
126
124
. then ( function ( result ) {
127
125
var theOnesCreated = result . summary . updateStatistics . nodesCreated ( ) ;
128
126
console . log ( "There were " + theOnesCreated + " the ones created." ) ;
129
127
} ) ;
130
- // end::statement-without-parameters[]
131
128
132
129
// Then
133
- resultPromise . then ( function ( ) {
130
+ setTimeout ( function ( ) {
134
131
expect ( out [ 0 ] ) . toBe ( "There were 1 the ones created." ) ;
135
132
done ( ) ;
136
- } )
133
+ } , 500 )
137
134
} ) ;
138
135
139
136
it ( 'should be able to iterate results' , function ( done ) {
140
137
var session = sessionGlobal ;
141
- // tag::retain-result-query[]
138
+ session
139
+ . run ( "CREATE (weapon:Weapon { name: 'Sword in the stone' })" )
140
+ . then ( function ( ) {
141
+ // tag::result-traversal[]
142
+ var searchTerm = "Sword" ;
142
143
session
143
- . run ( "MATCH (p:Person { name: {name} }) RETURN p.age " , { name : "The One" } )
144
+ . run ( "MATCH (weapon:Weapon) WHERE weapon. name CONTAINS {term} RETURN weapon.name " , { term : searchTerm } )
144
145
. subscribe ( {
145
146
onNext : function ( record ) {
146
- console . log ( record ) ;
147
+ console . log ( "" + record . get ( "weapon.name" ) ) ;
147
148
} ,
148
149
onCompleted : function ( ) {
149
- // Completed!
150
150
session . close ( ) ;
151
151
} ,
152
152
onError : function ( error ) {
153
153
console . log ( error ) ;
154
154
}
155
155
} ) ;
156
- // end::retain-result-query[]
156
+ // end::result-traversal[]
157
+ } ) ;
157
158
// Then
158
- done ( ) ;
159
+ setTimeout ( function ( ) {
160
+ expect ( out [ 0 ] ) . toBe ( "Sword in the stone" ) ;
161
+ done ( ) ;
162
+ } , 500 ) ;
159
163
} ) ;
160
164
161
- it ( 'should be able to do nested queries ' , function ( done ) {
165
+ it ( 'should be able to access records ' , function ( done ) {
162
166
var session = sessionGlobal ;
163
-
164
- session . run ( "CREATE (:Person {name:'The One'})" ) . then ( function ( ) {
165
- // tag::result-cursor[]
167
+ session
168
+ . run ( "CREATE (weapon:Weapon { name: 'Sword in the stone', owner: 'Arthur', material: 'Stone', size: 'Huge' })" )
169
+ . then ( function ( ) {
170
+ // tag::access-record[]
171
+ var searchTerm = "Arthur" ;
166
172
session
167
- . run ( "MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One" } )
168
- . then ( function ( result ) {
169
- var id = result . records [ 0 ] . get ( 'id(p)' ) ;
170
- session . run ( "MATCH (p) WHERE id(p) = {id} CREATE (p)-[:HAS_TRAIT]->(:Trait {type:'Immortal'})" , { id : id } )
171
- . then ( function ( neoRecord ) {
172
- var immortalsCreated = neoRecord . summary . updateStatistics . nodesCreated ( ) ;
173
- var relationshipCreated = neoRecord . summary . updateStatistics . relationshipsCreated ( ) ;
174
- console . log ( "There were " + immortalsCreated + " immortal and " + relationshipCreated +
175
- " relationships created" ) ;
173
+ . run ( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} RETURN weapon.name, weapon.material, weapon.size" , { term : searchTerm } )
174
+ . subscribe ( {
175
+ onNext : function ( record ) {
176
+ var sword = [ ] ;
177
+ record . forEach ( function ( value , key )
178
+ {
179
+ sword . push ( key + ": " + value ) ;
176
180
} ) ;
181
+ console . log ( sword ) ;
182
+ } ,
183
+ onCompleted : function ( ) {
184
+ session . close ( ) ;
185
+ } ,
186
+ onError : function ( error ) {
187
+ console . log ( error ) ;
188
+ }
177
189
} ) ;
178
- // tag::result-cursor []
179
- } ) ;
190
+ // end::access-record []
191
+ } ) ;
180
192
181
- //await the result
193
+ // Then
182
194
setTimeout ( function ( ) {
183
- expect ( out [ 0 ] ) . toBe ( "There were 1 immortal and 1 relationships created" ) ;
195
+ expect ( out [ 0 ] . length ) . toBe ( 3 ) ;
184
196
done ( ) ;
185
- } , 500 ) ;
197
+ } , 500 )
186
198
} ) ;
187
199
188
200
it ( 'should be able to retain for later processing' , function ( done ) {
189
201
var session = sessionGlobal ;
190
202
191
- session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
192
- // tag::retain-result-process[]
203
+ session
204
+ . run ( "CREATE (knight:Person:Knight { name: 'Lancelot', castle: 'Camelot' })" )
205
+ . then ( function ( ) {
206
+ // tag::retain-result[]
193
207
session
194
- . run ( "MATCH (p :Person { name: {name} }) RETURN p.age " , { name : "The One " } )
208
+ . run ( "MATCH (knight :Person:Knight) WHERE knight.castle = {castle} RETURN knight.name AS name " , { castle : "Camelot " } )
195
209
. then ( function ( result ) {
210
+ var records = [ ] ;
196
211
for ( i = 0 ; i < result . records . length ; i ++ ) {
197
- result . records [ i ] . forEach ( function ( value , key , record ) {
198
- console . log ( "Value for key " + key + " has value " + value ) ;
199
- } ) ;
212
+ records . push ( result . records [ i ] ) ;
213
+ }
214
+ return records ;
215
+ } )
216
+ . then ( function ( records ) {
217
+ for ( i = 0 ; i < records . length ; i ++ )
218
+ {
219
+ console . log ( records [ i ] . get ( "name" ) + " is a knight of Camelot" ) ;
200
220
}
201
-
202
221
} ) ;
203
- // end::retain-result-process []
222
+ // end::retain-result[]
204
223
} ) ;
205
224
206
225
//await the result
207
226
setTimeout ( function ( ) {
208
- expect ( out [ 0 ] ) . toBe ( "Value for key p.age has value 23" ) ;
227
+ expect ( out [ 0 ] ) . toBe ( "Lancelot is a knight of Camelot" ) ;
228
+ done ( ) ;
229
+ } , 500 ) ;
230
+ } ) ;
231
+
232
+ it ( 'should be able to do nested queries' , function ( done ) {
233
+ var session = sessionGlobal ;
234
+ session
235
+ . run ( "CREATE (knight:Person:Knight { name: 'Lancelot', castle: 'Camelot' })" +
236
+ "CREATE (king:Person { name: 'Arthur', title: 'King' })" )
237
+ . then ( function ( ) {
238
+ // tag::nested-statements[]
239
+ session
240
+ . run ( "MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id" , { "castle" : "Camelot" } )
241
+ . subscribe ( {
242
+ onNext : function ( record ) {
243
+ session
244
+ . run ( "MATCH (knight) WHERE id(knight) = {id} MATCH (king:Person) WHERE king.name = {king} CREATE (knight)-[:DEFENDS]->(king)" ,
245
+ { "id" : record . get ( "knight_id" ) , "king" : "Arthur" } ) ;
246
+ } ,
247
+ onCompleted : function ( ) {
248
+ session
249
+ . run ( "MATCH (:Knight)-[:DEFENDS]->() RETURN count(*)" )
250
+ . then ( function ( result ) {
251
+ console . log ( "Count is " + result . records [ 0 ] . get ( 0 ) . toInt ( ) ) ;
252
+ } ) ;
253
+ } ,
254
+ onError : function ( error ) {
255
+ console . log ( error ) ;
256
+ }
257
+ } ) ;
258
+ // tag::nested-statements[]
259
+ } ) ;
260
+
261
+ //await the result
262
+ setTimeout ( function ( ) {
263
+ expect ( out [ 0 ] ) . toBe ( "Count is 1" ) ;
209
264
done ( ) ;
210
265
} , 500 ) ;
211
266
} ) ;
@@ -226,10 +281,10 @@ describe('examples', function() {
226
281
it ( 'should be able to profile' , function ( done ) {
227
282
var session = sessionGlobal ;
228
283
229
- session . run ( "CREATE (:Person {name:'The One', age: 23 })" ) . then ( function ( ) {
284
+ session . run ( "CREATE (:Person {name:'Arthur' })" ) . then ( function ( ) {
230
285
// tag::result-summary-query-profile[]
231
286
session
232
- . run ( "PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One " } )
287
+ . run ( "PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)" , { name : "Arthur " } )
233
288
. then ( function ( result ) {
234
289
console . log ( result . summary . profile ) ;
235
290
} ) ;
@@ -248,7 +303,7 @@ describe('examples', function() {
248
303
249
304
// tag::result-summary-notifications[]
250
305
session
251
- . run ( "EXPLAIN MATCH (a ), (b ) RETURN a,b " )
306
+ . run ( "EXPLAIN MATCH (king ), (queen ) RETURN king, queen " )
252
307
. then ( function ( result ) {
253
308
var notifications = result . summary . notifications , i ;
254
309
for ( i = 0 ; i < notifications . length ; i ++ ) {
@@ -268,7 +323,7 @@ describe('examples', function() {
268
323
269
324
// tag::transaction-commit[]
270
325
var tx = session . beginTransaction ( ) ;
271
- tx . run ( "CREATE (p :Person { name: 'The One' })" ) ;
326
+ tx . run ( "CREATE (:Person {name: 'Guinevere' })" ) ;
272
327
tx . commit ( ) ;
273
328
// end::transaction-commit[]
274
329
} ) ;
@@ -278,7 +333,7 @@ describe('examples', function() {
278
333
279
334
// tag::transaction-rollback[]
280
335
var tx = session . beginTransaction ( ) ;
281
- tx . run ( "CREATE (p :Person { name: 'The One' })" ) ;
336
+ tx . run ( "CREATE (:Person {name: 'Merlin' })" ) ;
282
337
tx . rollback ( ) ;
283
338
// end::transaction-rollback[]
284
339
} ) ;
@@ -308,7 +363,7 @@ describe('examples', function() {
308
363
} ) ;
309
364
// end::tls-trust-on-first-use[]
310
365
driver . close ( ) ;
311
- } ) ;
366
+ } ) ;
312
367
313
368
it ( 'should document how to configure a trusted signing certificate' , function ( ) {
314
369
var neo4j = neo4jv1 ;
@@ -325,4 +380,15 @@ describe('examples', function() {
325
380
driver . close ( ) ;
326
381
} ) ;
327
382
383
+ it ( 'should document how to disable auth' , function ( ) {
384
+ var neo4j = neo4jv1 ;
385
+ // tag::connect-with-auth-disabled[]
386
+ var driver = neo4j . driver ( "bolt://localhost" , {
387
+ // In NodeJS, encryption is on by default. In the web bundle, it is off.
388
+ encrypted :true
389
+ } ) ;
390
+ // end::connect-with-auth-disabled[]
391
+ driver . close ( ) ;
392
+ } ) ;
393
+
328
394
} ) ;
0 commit comments