@@ -30,27 +30,36 @@ npm install redisgraph.js
3030# Example: Using the JavaScript Client
3131
3232``` javascript
33- const RedisGraph = require (" redisgraph.js" ).RedisGraph ;
34-
35- let graph = new RedisGraph (' social' );
36- graph
37- .query (" CREATE (:person{name:'roi',age:32})" )
38- .then ( () => {
39- return graph .query (" CREATE (:person{name:'amit',age:30})" );
40- })
41- .then ( () => {
42- return graph .query (" MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)" )
43- })
44- .then ( () => {
45- return graph .query (" MATCH (a:person)-[:knows]->(:person) RETURN a" )
46- })
47- .then ( (res ) => {
48- while (res .hasNext ()){
49- let record = res .next ();
50- console .log (record .getString (' a.name' ));
51- }
52- console .log (res .getStatistics ().queryExecutionTime ());
53- });
33+ const RedisGraph = require (" redisgraph.js" ).Graph ;
34+
35+ let graph = new RedisGraph (" social" );
36+
37+ graph .query (" CREATE (:person{name:'roi',age:32})" ).then (() => {
38+ graph .query (" CREATE (:person{name:'amit',age:30})" ).then (()=> {
39+ graph .query (" MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)" ).then (()=> {
40+ graph .query (" MATCH (a:person)-[:knows]->(:person) RETURN a.name" ).then (res => {
41+ while (res .hasNext ()) {
42+ let record = res .next ();
43+ console .log (record .get (" a.name" ));
44+ }
45+ console .log (res .getStatistics ().queryExecutionTime ());
46+ graph .query (" MATCH p = (a:person)-[:knows]->(:person) RETURN p" ).then (res => {
47+ while (res .hasNext ()) {
48+ let record = res .next ();
49+ // See path.js for more path API.
50+ console .log (record .get (" p" ).nodeCount );
51+ graph .deleteGraph ();
52+ process .exit ();
53+ }
54+ })
55+ })
56+ })
57+ })
58+ })
59+ .catch (err => {
60+ console .log (err);
61+ });
62+
5463
5564```
5665
0 commit comments