Members
bindData
Properties:
Type | Description |
---|---|
BindData | List of BIND data linked to '?' in statement. |
columnTableNameReplacement
Properties:
Type | Description |
---|---|
String | derived table name to output in column title replacing source table name. |
columnTitle
Properties:
Type | Description |
---|---|
Boolean | Are column tables to be ouptout? |
tables
Properties:
Type | Description |
---|---|
Map.<String, Table> | Map of referenced tables. |
Methods
addBindNamedRangeParameter(value) → {Sql}
- Description:
The BIND data is a sheet named range that will be read and used for bind data.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
String | Sheets Named Range for SINGLE CELL only. |
Returns:
- Type
- Sql
addBindParameter(value) → {Sql}
- Description:
Add a bind data value. Must be added in order. If bind data is a named range, use addBindNamedRangeParameter().
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
any | literal data. |
Returns:
- Type
- Sql
addColumnTitles(viewTableData, view) → {Array.<Array.<any>>}
Parameters:
Name | Type | Description |
---|---|---|
viewTableData |
Array.<Array.<any>> | |
view |
SelectTables |
Returns:
- Type
- Array.<Array.<any>>
addTableData(tableName, tableData, cacheSeconds, hasColumnTitle) → {Sql}
- Description:
Add data for each referenced table in SELECT, before EXECUTE().
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
tableName |
String | Name of table referenced in SELECT. |
|
tableData |
any | Either double array or a named range. |
|
cacheSeconds |
Number |
0
|
How long should loaded data be cached (default=0) |
hasColumnTitle |
Boolean |
true
|
Is first data row the column title? |
Returns:
- Type
- Sql
areColumnTitlesOutput() → {Boolean}
Returns:
- Type
- Boolean
clearBindParameters() → {Sql}
- Description:
Clears existing BIND data so Sql() instance can be used again with new bind parameters.
- Source:
Returns:
- Type
- Sql
copyTableData(tableMap)
- Description:
Copies the data from an external tableMap to this instance.
It copies a reference to outside array data only.
The schema would need to be re-loaded.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
tableMap |
Map.<String, Table> |
enableColumnTitle(value) → {Sql}
Parameters:
Name | Type | Description |
---|---|---|
value |
Boolean | true will return column names in first row of return data. |
Returns:
- Type
- Sql
execute(statement) → {Array.<Array.<any>>}
- Description:
Parse SQL SELECT statement, performs SQL query and returns data ready for custom function return.
Execute() can be called multiple times for different SELECT statements, provided that all required table data was loaded in the constructor.
Methods that would be used PRIOR to execute are:
enableColumnTitle() - turn on/off column title in output
addBindParameter() - If bind data is needed in select. e.g. "select * from table where id = ?"
addTableData() - At least ONE table needs to be added prior to execute. This tells execute where to find the data.
Example SELECT and RETURN Datalet stmt = "SELECT books.id, books.title, books.author_id " + "FROM books " + "WHERE books.author_id IN ('11','12') " + "ORDER BY books.title"; let data = new Sql() .addTableData("books", this.bookTable()) .enableColumnTitle(true) .execute(stmt); Logger.log(data); [["books.id", "books.title", "books.author_id"], ["4", "Dream Your Life", "11"], ["8", "My Last Book", "11"], ["5", "Oranges", "12"], ["1", "Time to Grow Up!", "11"]]
- Source:
Parameters:
Name | Type | Description |
---|---|---|
statement |
any | SELECT statement as STRING or AST of SELECT statement. |
Returns:
- Double array where first index is ROW and second index is COLUMN.
- Type
- Array.<Array.<any>>
getBindData() → {Array.<any>}
Returns:
- Type
- Array.<any>
getTables() → {Map.<String, Table>}
Returns:
- Map of referenced tables indexed by TABLE name.
- Type
- Map.<String, Table>
replaceColumnTableNameWith(replacementTableName) → {Sql}
- Description:
Derived table data that requires the ALIAS table name in column title.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
replacementTableName |
String | derived table name to replace original table name. To disable, set to null. |
Returns:
- Type
- Sql
select(selectAst) → {Array.<Array.<any>>}
Parameters:
Name | Type | Description |
---|---|---|
selectAst |
Object | Abstract Syntax Tree of SELECT |
Returns:
- double array useable by Google Sheet in custom function return value.
- First row of data will be column name if column title output was requested.
- First Array Index - ROW
- Second Array Index - COLUMN
- Type
- Array.<Array.<any>>
selectFromSubQuery()
- Description:
Modifies AST when FROM is a sub-query rather than a table name.
- Source:
selectJoinSubQuery() → {void}
- Description:
Checks if the JOINed table is a sub-query.
The sub-query is evaluated and assigned the alias name. The AST is adjusted to use the new JOIN TABLE.
- Source:
Returns:
- Type
- void
selectSet(leftTableData, unionAst) → {Array.<Array.<any>>}
Parameters:
Name | Type | Description |
---|---|---|
leftTableData |
Array.<Array.<any>> | |
unionAst |
Object |
Returns:
- Type
- Array.<Array.<any>>
setBindValues(value) → {Sql}
Parameters:
Name | Type | Description |
---|---|---|
value |
BindData | Bind data. |
Returns:
- Type
- Sql
setTables(mapOfTables)
Parameters:
Name | Type | Description |
---|---|---|
mapOfTables |
Map.<String, Table> | Map of referenced tables indexed by TABLE name. |
(static) cleanUp(viewTableData) → {Array.<Array.<any>>}
- Description:
If no data and no titles, create empty double array so sheets function does not have an error.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
viewTableData |
Array.<Array.<any>> |
Returns:
- Type
- Array.<Array.<any>>
(static) distinctField(ast) → {Object}
- Description:
If 'GROUP BY' is not set and 'DISTINCT' column is specified, update AST to add 'GROUP BY'.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object | Abstract Syntax Tree for SELECT. |
Returns:
- Updated AST to include GROUP BY when DISTINCT field used.
- Type
- Object
(static) errorCheckSelectAST(ast)
Parameters:
Name | Type | Description |
---|---|---|
ast |
object |
(static) loadSchema(tables)
Parameters:
Name | Type | Description |
---|---|---|
tables |
Map.<String, Table> |