@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.73 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
async function e(e){const{CharStream:r,CommonTokenStream:t,ParseTreeWalker:n}=await import("../../chunks/antlr4.web.js"),{default:s}=await import("./antlr/BindParamsListener.js"),{default:a}=await import("../../chunks/CypherLexer.js"),{default:o}=await import("../../chunks/CypherParser.js"),{default:i}=await import("./antlr/SimpleErrorListener.js"),p=new i,u=new a(new r(e));u.removeErrorListeners(),u.addErrorListener(p);const l=new o(new t(u));l.removeErrorListeners(),l.addErrorListener(p);const m=l.oC_Cypher(),f=new s;return(new n).walk(f,m),{bindParameters:Array.from(new Set(f.bindParams)).map(e=>e.slice(1)),parseErrors:p.errors}}const r=(e,t)=>{if("column-reference"===e.type)return e.column===t.systemOidFieldName?"ID(n)":`n.${e.column}`;if("string"===e.type)return`'${e.value}'`;if("number"===e.type)return`${e.value}`;if("binary-expression"===e.type&&t.supportedSqlTypes.has(e.left.type)&&t.supportedSqlTypes.has(e.right.type)&&t.supportedSqlOperators.has(e.operator))return`${r(e.left,t)} ${e.operator} ${r(e.right,t)}`;if("binary-expression"===e.type&&"LIKE"===e.operator){let r="";if("function"===e.left.type&&"column-reference"===e.left.args.value[0].type)r+=`lower(n.${e.left.args.value[0].column})`;else{if("column-reference"!==e.left.type)return t.unsupportedOperationFound=!0,"";r+=`lower(n.${e.left.column})`}if(r+=" CONTAINS (","string"!==e.right.type)return t.unsupportedOperationFound=!0,"";{let t=e.right.value;t.startsWith("%")&&(t=t.slice(1)),t.endsWith("%")&&(t=t.slice(0,-1)),r+=`'${t.toLowerCase()}')`}return r}return t.unsupportedOperationFound=!0,""};export{e as getBindParametersFromCypherQuery,r as recursiveParseSqlToCypher};