SqlParse

SqlParse

Parse SQL SELECT statement and convert into Abstract Syntax Tree

Constructor

new SqlParse()

Source:

Methods

(static) analyzeParts(partsOrder, parts) → {Object}

Source:
Parameters:
Name Type Description
partsOrder Array.<String>
parts Array.<String>
Returns:
Type
Object

(static) assignDerivedTableNameForSubqueries(result)

Description:
  • Modifies AST for subqueries in FROM clause. Creates an ALIAS name, which is then used as FROM table name.

Source:
Parameters:
Name Type Description
result Object

(static) filterCommentsFromStatement(statement) → {String}

Description:
  • Remove comments from SQL statement.

Source:
Parameters:
Name Type Description
statement String
Returns:
Type
String

(static) generateSqlSeparatorWords(keywords) → {Array.<Array.<String>>}

Source:
Parameters:
Name Type Description
keywords Array.<String>
Returns:
Type
Array.<Array.<String>>

(static) generateUsedKeywordList(query) → {Array.<String>}

Description:
  • Returns a list of all keywords used in their original CASE.

Source:
Parameters:
Name Type Description
query String
Returns:
Type
Array.<String>

(static) getPositionsOfSqlParts(sqlQuery, sqlKeywords) → {Array.<any>}

Source:
Parameters:
Name Type Description
sqlQuery String
sqlKeywords Array.<String>
Returns:
Type
Array.<any>

(static) hideInnerSql(str, parts_name_escaped, replaceFunction)

Source:
Parameters:
Name Type Description
str String
parts_name_escaped Array.<String>
replaceFunction function

(static) hideSqlParts(query, parts_name_escaped) → {String}

Source:
Parameters:
Name Type Description
query String
parts_name_escaped Array.<String>
Returns:
Type
String

(static) protect(str) → {String}

Description:
  • Add some # inside a string to avoid it to match a regex/split

Source:
Parameters:
Name Type Description
str String
Returns:
Type
String

(static) realNameCallback(_match, name) → {String}

Source:
Parameters:
Name Type Description
_match String
name String
Returns:
Type
String

(static) removeDuplicateEntries(partsOrder)

Description:
  • Delete duplicates (caused, for example, by JOIN and INNER JOIN)

Source:
Parameters:
Name Type Description
partsOrder Array.<String>

(static) reorganizeJoins(result)

Source:
Parameters:
Name Type Description
result Object

(static) reorganizeSpecificJoin(result, joinName, joinType)

Source:
Parameters:
Name Type Description
result Object
joinName String
joinType String

(static) resolveSqlCondition(logic, terms) → {String}

Source:
Parameters:
Name Type Description
logic String
terms Object
Returns:
Type
String

(static) sql2ast(sqlStatement) → {Object}

Description:
  • Parse a query

Source:
Parameters:
Name Type Description
sqlStatement String
Returns:
Type
Object

(static) sqlCondition2JsCondition(cond) → {String}

Source:
Parameters:
Name Type Description
cond String
Returns:
Type
String

(static) toBlank(str) → {String}

Source:
Parameters:
Name Type Description
str String
Returns:
Type
String

(static) unhideSqlParts(modifiedQuery, parts_name_escaped, words)

Description:
  • Modifies split parts to unhide constants and inner SQL that were protected before splitting.

Source:
Parameters:
Name Type Description
modifiedQuery String
parts_name_escaped Array.<String>

List of protected keywords used for splitting the query.

words Array.<String>

List of protected keywords to reverse the protection in the split parts.

(static) unprotect(str) → {String}

Description:
  • Restore a string output by protect() to its original state

Source:
Parameters:
Name Type Description
str String
Returns:
Type
String