|
|
|
@ -50,14 +50,13 @@ class Xsql {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.iterateToCacheTables(results) |
|
|
|
|
self.iterateToCacheTablePks(results) |
|
|
|
|
self.iterateToCacheTableColumns(results) |
|
|
|
|
self.iterateToCacheTableFks(results) |
|
|
|
|
self.iterateToCacheRoutines(results) |
|
|
|
|
self.iterateToCacheTables(results); |
|
|
|
|
self.iterateToCacheTablePks(results); |
|
|
|
|
self.iterateToCacheTableColumns(results); |
|
|
|
|
self.iterateToCacheTableFks(results); |
|
|
|
|
|
|
|
|
|
// osx mysql server has limitations related to open_tables
|
|
|
|
|
self.pool.query('FLUSH TABLES', [], (err, results) => { |
|
|
|
|
self.pool.query("FLUSH TABLES", [], (err, results) => { |
|
|
|
|
self.pool.query(dataHelp.getRoutines(), [this.sqlConfig.database], (err, results) => { |
|
|
|
|
if (err) { |
|
|
|
|
cbk(err, results) |
|
|
|
@ -66,7 +65,8 @@ class Xsql {
|
|
|
|
|
cbk(null, null) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -374,6 +374,16 @@ class Xsql {
|
|
|
|
|
queryParamsObj.query += ",count(1) as _count "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getColumnsForGroupBy(tableName, reqQueryParams, queryParamsObj) { |
|
|
|
|
const updatedQueryParams = Object.assign({}, reqQueryParams); |
|
|
|
|
if ("_groupbyfields" in updatedQueryParams) { |
|
|
|
|
// allows you to group by different fields than you have in the select
|
|
|
|
|
updatedQueryParams['_fields'] = updatedQueryParams['_groupbyfields']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.getColumnsForSelectStmt(tableName, updatedQueryParams, queryParamsObj) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getColumnsForSelectStmt(tableName, reqQueryParams, queryParamsObj) { |
|
|
|
|
let table = this.metaDb.tables[tableName]; |
|
|
|
|
let cols = []; |
|
|
|
@ -421,6 +431,16 @@ class Xsql {
|
|
|
|
|
return cols.join(","); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getColumnNameWithoutAggregationFunctions(rawColumnName) { |
|
|
|
|
const AGGREGATION_FUNCTION_REGEX = /^(AVG|BIT_AND|BIT_OR|BIT_XOR|COUNT|COUNTDISTINCT|GROUP_CONCAT|JSON_ARRAYAGG|JSON_OBJECTAGG|MAX|MIN|STD|STDDEV|STDDEV_POP|STDDEV_SAMP|SUM|VAR_POP|VAR_SAMP|VARIANCE)\((.*)\)$/; |
|
|
|
|
const aggFuncMatch = rawColumnName.match(AGGREGATION_FUNCTION_REGEX); |
|
|
|
|
if (aggFuncMatch && aggFuncMatch.length === 3) { |
|
|
|
|
// match will look like (3) ["AVG(timestamp)", "AVG", "timestamp", index: 0, input: "AVG(timestamp)", groups: undefined]
|
|
|
|
|
return aggFuncMatch[2]; |
|
|
|
|
} |
|
|
|
|
return rawColumnName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
removeUnknownColumns(inputColumns, tableName) { |
|
|
|
|
let cols = inputColumns; |
|
|
|
|
let unknown_cols_in_input = []; |
|
|
|
@ -430,9 +450,11 @@ class Xsql {
|
|
|
|
|
// find unknown fields if any
|
|
|
|
|
for (var j = 0; j < cols.length; ++j) { |
|
|
|
|
let found = 0; |
|
|
|
|
// Used to allow aggregation functions like AVG(timestamp)
|
|
|
|
|
let columnNameWithoutAggregationClauses = this.getColumnNameWithoutAggregationFunctions(cols[j]); |
|
|
|
|
|
|
|
|
|
for (var i = 0; i < tableColumns.length; ++i) { |
|
|
|
|
if (tableColumns[i]["column_name"] === cols[j]) { |
|
|
|
|
if (tableColumns[i]["column_name"] === columnNameWithoutAggregationClauses) { |
|
|
|
|
found = 1; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -764,7 +786,7 @@ class Xsql {
|
|
|
|
|
|
|
|
|
|
getProcList() { |
|
|
|
|
let procRoutes = [] |
|
|
|
|
for (var procName in this.metaDb.routines) { |
|
|
|
|
for (let procName in this.metaDb.routines) { |
|
|
|
|
procRoutes.push(this.metaDb.routines[procName]) |
|
|
|
|
} |
|
|
|
|
return procRoutes |
|
|
|
|