不需要的反斜杠出现在NodeJS的查询中

时间:2018-12-05 13:31:40

标签: javascript node.js backslash

我已经在NodeJS中编写了一个代码,用于创建数据库查询。我不明白为什么查询中会出现不想要的“ \”反斜杠。我尝试使用.replace(/ \ / g,'')命令显式删除反斜杠,但无济于事。解决的办法是什么?

NodeJS代码

app.controller.js

function createCypherQueries(data,parent,type,parentType){

                var macthQuery;
                var createQuery;
                var relationQuery;
                var completeQuery;
                var lowerCaseParent;
                var lowerCaseParentType;
                var lowerCaseData;
                var lowerCaseType;

                var completeCypherQuery1;


                lowerCaseParent = parent!=null?parent:'yo';

                lowerCaseParent = lowerCaseParent.replace(/[^a-zA-Z0-9_ ]/g, "").toLowerCase();

                lowerCaseData = data.toLowerCase();
                lowerCaseData = lowerCaseData.replace(/[^a-zA-Z0-9_ ]/g, "");
                lowerCaseType = type!=null?type:'';
                lowerCaseType = lowerCaseType.replace(/[^a-zA-Z0-9_ ]/g, "");


                // with ' ;

                matchQuery = "Match (" + lowerCaseParent + ":" + lowerCaseParent +") where "+ lowerCaseParent +".name ='"+  parent +"' ";
                createQuery = "Create  ("+ lowerCaseData  +":"+ lowerCaseData  +"{name:'"+ data +"'})";
                relationQuery = "("+ lowerCaseParent +")-[:"+ type +"]->("+lowerCaseData +")";


                if(parent == null){

                    if(type=="Organization"){



                        createQuery = "Create  (" + organization.toLowerCase() + ":" + organization.toLowerCase() +"{name:'"+organization+"'})";

                        completeQuery = createQuery;
                        completeCypherQuery1 = completeQuery.replace(/\\/g, '');
                        orgTree = completeCypherQuery1;



                    }
                    else{
                        parentType= "System";

                        lowerCaseParent = system!=null?system.toLowerCase():'noData';

                        lowerCaseData = data.toLowerCase();
                        lowerCaseType = type!=null?type.toLowerCase():'';




                        matchQuery = "Match ("+ lowerCaseParent +":"+ lowerCaseParent +") where "+ lowerCaseParent +".name ='"+ system  +"'" ;
                        createQuery = "Create  ("+ lowerCaseData +":"+ lowerCaseData+"{name:'" + data+ "'})";
                        relationQuery = "("+ lowerCaseParent +")-[:"+type+"]->(" + lowerCaseData + ")";     





                        completeQuery = matchQuery + createQuery +"," + relationQuery;

                        completeCypherQuery1  = completeQuery.replace(/\\/g, '');
                        allQueries.push(completeCypherQuery1);


                    }

                }
                else{


                    completeQuery = matchQuery+createQuery+","+relationQuery;

                    completeCypherQuery1 = completeQuery.replace(/\\/g, '');




                }



                allQueries.push(completeCypherQuery1);

                console.log( " zzzzz",allQueries);



            }

        //  CREATES CYPHER QUERIES FROM WSDL FILE ENDS HERE *******************************************
}
});

输出-

zzzzz [ 'Create  (naya:naya{name:\'Naya\'})',

  'Match (naya:naya) where naya.name =\'Naya\' Create  (it:it{name:\'IT\'}),(naya)-[:Department]->(it)',

  'Match (it:it) where it.name =\'IT\' Create  (test:test{name:\'Test\'}),(it)-[:System]->(test)',

  'Match (test:test) where test.name =\'Test\' Create  (ngoconnectionserviceimpl:ngoconnectionserviceimpl{name:\'NGOConnectionServiceImpl\'}),(test)-[:Function]->(ngoconnectionserviceimpl)',

  'Match (ngoconnectionserviceimpl:ngoconnectionserviceimpl) where ngoconnectionserviceimpl.name =\'NGOConnectionServiceImpl\' Create  (ngoconnectionserviceimplhttpsoap11endpoint:ngoconnectionserviceimplhttpsoap11endpoint{name:\'NGOConnectionServiceImplHttpSoap11Endpoint\'}),(ngoconnectionserviceimpl)-[:Port]->(ngoconnectionserviceimplhttpsoap11endpoint)',

  'Match (disconnectcab:disconnectcab) where disconnectcab.name =\'disconnectCab\' Create  (input:input{name:\'input\'}),(disconnectcab)-[:Parameter]

0 个答案:

没有答案