@@ -6,46 +6,58 @@ module.exports = function (RED) {
6
6
//console.log(`url = ${config.url}`);
7
7
const driver = neo4j . driver ( config . url , neo4j . auth . basic ( config . username , config . password ) ) ;
8
8
const session = driver . session ( ) ;
9
-
10
- node . on ( 'input' , function ( msg ) {
11
- //console.log(`decoding QR data from ${msg.payload}`);
12
- var query = config . query || msg . query ;
13
- let params = null ;
14
- if ( typeof ( msg . params ) === 'string' ) {
15
- params = JSON . parse ( msg . params ) ;
16
- } else {
17
- params = msg . params ;
18
- }
19
- //console.log(`params: ${params}`);
20
- var scalar_result = {
21
- payload : null
22
- } ;
23
- const resultPromise = session . run ( query , params ) ;
24
-
25
- var array_result = {
26
- payload : [ ]
27
- }
28
- resultPromise . then ( result => {
29
- session . close ( ) ;
30
- if ( result . records . length > 1 ) {
31
- result . records . forEach ( function ( item , index , array ) {
32
- array_result . payload . push ( item . get ( 0 ) . properties ) ;
33
- } ) ;
34
- //console.log(`array size: ${array_result.payload.length}`)
35
- node . send ( [ null , array_result ] ) ;
9
+ if ( session ) {
10
+ node . status ( {
11
+ fill : "green" ,
12
+ shape : "dot" ,
13
+ text : "node-red:common.status.connected"
14
+ } ) ;
15
+ node . on ( 'input' , function ( msg ) {
16
+ //console.log(`decoding QR data from ${msg.payload}`);
17
+ var query = config . query || msg . query ;
18
+ let params = null ;
19
+ if ( typeof ( msg . params ) === 'string' ) {
20
+ params = JSON . parse ( msg . params ) ;
36
21
} else {
37
- scalar_result . payload = result . records [ 0 ] . get ( 0 ) . properties ;
38
- //msg.payload = result.records;
39
- node . send ( [ scalar_result , null ] ) ;
22
+ params = msg . params ;
23
+ }
24
+ //console.log(`params: ${params}`);
25
+ var scalar_result = {
26
+ payload : null
27
+ } ;
28
+ const resultPromise = session . run ( query , params ) ;
40
29
30
+ var array_result = {
31
+ payload : [ ]
41
32
}
33
+ resultPromise . then ( result => {
34
+ session . close ( ) ;
35
+ if ( result . records . length > 1 ) {
36
+ result . records . forEach ( function ( item , index , array ) {
37
+ array_result . payload . push ( item . get ( 0 ) . properties ) ;
38
+ } ) ;
39
+ //console.log(`array size: ${array_result.payload.length}`)
40
+ node . send ( [ null , array_result ] ) ;
41
+ } else {
42
+ scalar_result . payload = result . records [ 0 ] . get ( 0 ) . properties ;
43
+ //msg.payload = result.records;
44
+ node . send ( [ scalar_result , null ] ) ;
45
+
46
+ }
47
+ } ) ;
42
48
} ) ;
43
- } ) ;
49
+ } else {
50
+ node . status ( {
51
+ fill : "red" ,
52
+ shape : "dot" ,
53
+ text : "node-red:common.status.disconnected"
54
+ } ) ;
55
+ }
44
56
45
- node . on ( 'close' , function ( ) {
57
+ node . on ( 'close' , function ( ) {
46
58
// tidy up any state
47
59
driver . close ( ) ;
48
60
} ) ;
49
61
}
50
- RED . nodes . registerType ( "nulli-neo4j" , NulliNeo4j ) ;
51
- }
62
+ RED . nodes . registerType ( "node-red-contrib- nulli-neo4j" , NulliNeo4j ) ;
63
+ }
0 commit comments