SelectTables

SelectTables

Perform SQL SELECT operations to retrieve requested data.

Constructor

new SelectTables(ast, tableInfo, bindVariables)

Source:
Parameters:
Name Type Description
ast Object

Abstract Syntax Tree

tableInfo Map.<String, Table>

Map of table info.

bindVariables BindData

List of bind data.

Members

astFields

Source:
Properties:
Type Description
Object

AST of SELECT fields

bindVariables

Source:
Properties:
Type Description
BindData

Bind variable data.

dataJoin

Source:
Properties:
Type Description
JoinTables

Join table object.

masterTable :Table

Source:
Type:

primaryTable

Source:
Properties:
Type Description
String

primary table name.

primaryTableInfo

Source:
Properties:
Type Description
Table

Primary table info.

tableFields

Source:
Properties:
Type Description
TableFields

tableInfo

Source:
Properties:
Name Type Description
tableInfo Map.<String, Table>

Map of table info.

Methods

createGroupByKey(row, astGroupBy) → {String}

Description:
  • Create a composite key that is comprised from all field data in group by clause.

Source:
Parameters:
Name Type Description
row Array.<any>

current row of data.

astGroupBy Array.<any>

group by fields

Returns:
  • group key
Type
String

getColumnTitles(columnTableNameReplacement) → {Array.<String>}

Description:
  • Return a list of column titles for this table.

Source:
Parameters:
Name Type Description
columnTableNameReplacement String
Returns:
  • column titles
Type
Array.<String>

getRecordIDs(condition) → {Array.<Number>}

Description:
  • Find record ID's where condition is TRUE.

Source:
Parameters:
Name Type Description
condition Object

WHERE test condition

Returns:
  • record ID's which are true.
Type
Array.<Number>

getViewData(recordIDs) → {Array.<Array.<any>>}

Description:
  • Retrieve the data for the record ID's specified for ALL SELECT fields.

Source:
Parameters:
Name Type Description
recordIDs Array.<Number>

record ID's which are SELECTed.

Returns:
  • double array of select data. No column title is included here.
Type
Array.<Array.<any>>

groupBy(ast, viewTableData) → {Array.<Array.<any>>}

Description:
  • Compress the table data so there is one record per group (fields in GROUP BY). The other fields MUST be aggregate calculated fields that works on the data in that group.

Source:
Parameters:
Name Type Description
ast Object

Abstract Syntax Tree

viewTableData Array.<Array.<any>>

Table data.

Returns:
  • Aggregated table data.
Type
Array.<Array.<any>>

groupByFields(astGroupBy, selectedData) → {Array.<Array.<any>>}

Description:
  • Group table data by group fields.

Source:
Parameters:
Name Type Description
astGroupBy Array.<any>

AST group by fields.

selectedData Array.<Array.<any>>

table data

Returns:
  • compressed table data
Type
Array.<Array.<any>>

having(astHaving, selectedData) → {Array.<Array.<any>>}

Description:
  • Take the compressed data from GROUP BY and then filter those records using HAVING conditions.

Source:
Parameters:
Name Type Description
astHaving Object

AST HAVING conditons

selectedData Array.<Array.<any>>

compressed table data (from group by)

Returns:
  • filtered data using HAVING conditions.
Type
Array.<Array.<any>>

join(ast) → {void}

Description:
  • Process any JOIN condition.

Source:
Parameters:
Name Type Description
ast Object

Abstract Syntax Tree

Returns:
Type
void

orderBy(ast, selectedData)

Description:
  • Take select data and sort by columns specified in ORDER BY clause.

Source:
Parameters:
Name Type Description
ast Object

Abstract Syntax Tree for SELECT

selectedData Array.<Array.<any>>

Table data to sort. On function return, this array is sorted.

removeTempColumns(viewTableData) → {Array.<Array.<any>>}

Description:
  • Removes temporary fields from return data. These temporary fields were needed to generate the final table data, but are not included in the SELECT fields for final output.

Source:
Parameters:
Name Type Description
viewTableData Array.<Array.<any>>

table data that may contain temporary columns.

Returns:
  • table data with temporary columns removed.
Type
Array.<Array.<any>>

resolveBindData(fieldCondition) → {any}

Description:
  • Get constant bind data

Source:
Parameters:
Name Type Description
fieldCondition String

left or right portion of condition

Returns:
Type
any

resolveCondition(logic, terms) → {Array.<Number>}

Description:
  • Recursively resolve WHERE condition and then apply AND/OR logic to results.

Source:
Parameters:
Name Type Description
logic String

logic condition (AND/OR) between terms

terms Object

terms of WHERE condition (value compared to value)

Returns:
  • record ID's
Type
Array.<Number>

resolveFieldCondition(fieldCondition) → {ResolvedFieldCondition}

Description:
  • Determine what the source of value is for the current field condition.

Source:
Parameters:
Name Type Description
fieldCondition Object

left or right portion of condition

Returns:
Type
ResolvedFieldCondition

resolveSubQuery(fieldCondition) → {Array.<any>}

Description:
  • Handle subquery. If correlated subquery, return object to handle, otherwise resolve and return constant data.

Source:
Parameters:
Name Type Description
fieldCondition Object

left or right portion of condition

Returns:
Type
Array.<any>

updateSelectedFields(ast) → {void}

Description:
  • Update internal FIELDS list to indicate those fields that are in the SELECT fields - that will be returned in data.

Source:
Parameters:
Name Type Description
ast Object
Returns:
Type
void

whereCondition(ast) → {Array.<Number>}

Description:
  • Retrieve filtered record ID's.

Source:
Parameters:
Name Type Description
ast Object

Abstract Syntax Tree

Returns:
  • Records ID's that match WHERE condition.
Type
Array.<Number>

(static) checkIfWithinString(ch, inQuotes) → {String}

Description:
  • Track if current ch(ar) is within quotes.

Source:
Parameters:
Name Type Description
ch String
inQuotes String
Returns:
  • Returns empty string if not within a string constant. If it is within a string, it will return either a single or double quote so we can determine when the string ends (it will match the starting quote.)
Type
String

(static) dateToMs(value) → {Number}

Description:
  • Convert input into milliseconds.

Source:
Parameters:
Name Type Description
value any

date as as Date or String.

Returns:
  • date as ms.
Type
Number

(static) extractStringConstant(value) → {String}

Description:
  • Extract the string literal out of condition. This removes surrounding quotes.

Source:
Parameters:
Name Type Description
value String

String that encloses literal string data.

Returns:
  • String with quotes removed.
Type
String

(static) functionBracketCounter(ch, startBracket, endBracket) → {Number}

Description:
  • Track net brackets encountered in string.

Source:
Parameters:
Name Type Description
ch String
startBracket String
endBracket String
Returns:
Type
Number

(static) getConditionValue(fieldConditions, calcSqlField, masterRecordID) → {any}

Description:
  • Evaulate value on left/right side of condition

Source:
Parameters:
Name Type Description
fieldConditions ResolvedFieldCondition

the value to be found will come from:

  • constant data
  • field data
  • calculated field
  • sub-query
calcSqlField CalculatedField

data to resolve the calculated field.

masterRecordID Number

current record in table to grab field data from

Returns:
  • resolve value.
Type
any

(static) getSubQueryTableSet(ast, tableInfo) → {Map.<String, Table>}

Description:
  • Create a set of tables that are used in sub-query.

Source:
Parameters:
Name Type Description
ast Object

Sub-query AST.

tableInfo Map.<String, Table>

Master set of tables used for entire select.

Returns:
  • table set for sub-query.
Type
Map.<String, Table>

(static) isCorrelatedSubQuery(ast) → {Boolean}

Source:
Parameters:
Name Type Description
ast Object
Returns:
Type
Boolean

(static) isStringConstant(value) → {Boolean}

Description:
  • Is the string a constant in the SELECT condition.

Source:
Parameters:
Name Type Description
value String

condition to test

Returns:
  • Is this string a constant.
Type
Boolean

(static) limit(ast, viewTableData) → {Array.<Array.<any>>}

Source:
Parameters:
Name Type Description
ast Object
viewTableData Array.<Array.<any>>
Returns:
Type
Array.<Array.<any>>

(static) parseForFunctions(functionString, func) → {Array.<String>}

Description:
  • Parse input string for 'func' and then parse if found.

Source:
Parameters:
Name Type Description
functionString String

Select field which may contain a function.

func String

Function name to parse for.

Returns:
  • Parsed function string.
    • null if function not found,
    • string array[0] - original string, e.g. sum(quantity)
    • string array[1] - function parameter, e.g. quantity
Type
Array.<String>

(static) parseForParams(paramString) → {Array.<String>}

Description:
  • Parse the input for a calculated field. String split on comma, EXCEPT if comma is within brackets (i.e. within an inner function) or within a string like ", "

Source:
Parameters:
Name Type Description
paramString String

Search and parse this string for parameters.

Returns:
  • List of function parameters.
Type
Array.<String>

(static) sortByColumnASC(tableData, colIndex) → {Array.<Array.<any>>}

Description:
  • Sort the table data from lowest to highest using the data in colIndex for sorting.

Source:
Parameters:
Name Type Description
tableData Array.<Array.<any>>

table data to sort.

colIndex Number

column index which indicates which column to use for sorting.

Returns:
  • sorted table data.
Type
Array.<Array.<any>>

(static) sortByColumnDESC(tableData, colIndex) → {Array.<Array.<any>>}

Description:
  • Sort the table data from highest to lowest using the data in colIndex for sorting.

Source:
Parameters:
Name Type Description
tableData Array.<Array.<any>>

table data to sort.

colIndex Number

column index which indicates which column to use for sorting.

Returns:
  • sorted table data.
Type
Array.<Array.<any>>

(static) toUpperCaseExceptQuoted(srcString) → {String}

Description:
  • Returns the entire string in UPPER CASE - except for anything between quotes.

Source:
Parameters:
Name Type Description
srcString String

source string to convert.

Returns:
  • converted string.
Type
String