You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by hb...@apache.org on 2022/12/29 07:43:34 UTC

[age-viewer] branch main updated: split node queries into individual queries (#86)

This is an automated email from the ASF dual-hosted git repository.

hbshin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/age-viewer.git


The following commit(s) were added to refs/heads/main by this push:
     new 8625b13  split node queries into individual queries (#86)
8625b13 is described below

commit 8625b139ebd1e481a4d29d1575d10bb14fe658be
Author: marodins <67...@users.noreply.github.com>
AuthorDate: Wed Dec 28 23:43:29 2022 -0800

    split node queries into individual queries (#86)
---
 backend/src/controllers/cypherController.js |  2 +-
 backend/src/models/GraphCreator.js          | 13 +++++--------
 backend/src/models/QueryBuilder.js          |  4 ++--
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/backend/src/controllers/cypherController.js b/backend/src/controllers/cypherController.js
index 18cb939..b6f9c6b 100644
--- a/backend/src/controllers/cypherController.js
+++ b/backend/src/controllers/cypherController.js
@@ -70,7 +70,7 @@ class CypherController {
                     return await transaction(q);
                 }));
                 await transaction('COMMIT');
-                res.status(204).end();                
+                res.status(204).end();
             } catch (e){
                 await transaction('ROLLBACK');
                 const details = e.toString();
diff --git a/backend/src/models/GraphCreator.js b/backend/src/models/GraphCreator.js
index 3893879..41c81f3 100644
--- a/backend/src/models/GraphCreator.js
+++ b/backend/src/models/GraphCreator.js
@@ -31,7 +31,8 @@ class GraphCreator {
     }
 
     async createNode(node, type, qbuild = new QueryBuilder({
-        graphName:this.graphName
+        graphName:this.graphName,
+        returnAs:'v'
     })){
         const CREATENODE = 
         `(:${type} ${toAgeProps(node)})`;
@@ -41,6 +42,7 @@ class GraphCreator {
         }
         
         qbuild.insertQuery(CREATENODE);
+        this.query.nodes.push(qbuild.getGeneratedQuery());
     }
     async createEdge(edge, type, qbuild = new QueryBuilder(
         {
@@ -89,10 +91,6 @@ class GraphCreator {
         });
     }
     async parseData(){
-        const nodeQueryBuilder = new QueryBuilder({
-            graphName:this.graphName,
-            returnAs:'v'
-        });
         this.createGraph(this.dropGraph);
 
         this.nodes = await Promise.all(this.nodefiles.map((node) => new Promise((resolve) => {
@@ -101,15 +99,14 @@ class GraphCreator {
         })));
         this.nodes.forEach((nodeFile)=>{
             nodeFile.data.forEach((n)=>{
-                this.createNode(n, nodeFile.type, nodeQueryBuilder);
+                this.createNode(n, nodeFile.type);
             });
         });
-        this.query.nodes.push(nodeQueryBuilder.getGeneratedQuery());
-        
         this.edges = await Promise.all(this.edgefiles.map((edge) => new Promise((resolve) => {
             this.createEdgeLabel(edge.originalname);
             this.readData(edge.buffer.toString('utf8'), edge.originalname, resolve);
         })));
+
         this.edges.forEach((edgeFile)=>{
             edgeFile.data.forEach((e)=>{
                 this.createEdge(e, edgeFile.type);
diff --git a/backend/src/models/QueryBuilder.js b/backend/src/models/QueryBuilder.js
index ce5b7ed..c212579 100644
--- a/backend/src/models/QueryBuilder.js
+++ b/backend/src/models/QueryBuilder.js
@@ -5,8 +5,8 @@ class QueryBuilder {
     constructor({graphName, returnAs='x'}={}){
         this._graphName = graphName;
         this.ends = {
-            start:`SELECT * FROM cypher('${this._graphName}', $$ `,
-            end:` $$) as (${returnAs} agtype)`
+            start:`SELECT * FROM cypher('${this._graphName}', $$`,
+            end:`$$) as (${returnAs} agtype);`
         };
         this.clause = '';
         this.middle = [];