@synatic/noql
Advanced tools
Comparing version 2.1.17 to 2.1.18
@@ -40,2 +40,5 @@ const _allowableFunctions = require('../MongoFunctions'); | ||
// todo there are more | ||
const expressionNamesToExcludeFromId = ['count', 'sum', 'min', 'max']; | ||
const expressionsToExpand = [{name: 'round', expressionKey: '$round'}]; | ||
/** | ||
@@ -84,3 +87,4 @@ * @param {import('../types').Column} column The column to parse | ||
); | ||
if (column.expr.name.toLowerCase() === 'count') { | ||
const lowerColumnName = column.expr.name.toLowerCase(); | ||
if (expressionNamesToExcludeFromId.indexOf(lowerColumnName) >= 0) { | ||
result.groupBy.$group[column.as] = parsedExpr; | ||
@@ -93,2 +97,18 @@ return; // count values can't go in the groupBy | ||
} | ||
const expand = expressionsToExpand.find( | ||
(e) => e.name === lowerColumnName | ||
); | ||
if (expand) { | ||
const [colExpression, precision] = parsedExpr[expand.expressionKey]; | ||
if (typeof colExpression !== 'string') { | ||
result.groupBy.$group[column.as] = colExpression; | ||
result.groupByProject = result.groupByProject || {}; | ||
result.groupByProject[column.as] = { | ||
[expand.expressionKey]: precision | ||
? [`$${column.as}`, precision] | ||
: [`$${column.as}`], | ||
}; | ||
return; | ||
} | ||
} | ||
result.groupBy.$group._id[column.as] = parsedExpr; | ||
@@ -95,0 +115,0 @@ return; |
@@ -324,3 +324,6 @@ const groupByColumnParserModule = require('./groupByColumnParser'); | ||
groupByProject[k] = 0; | ||
} else if (!k.startsWith('_tempAggregateCol_')) { | ||
} else if ( | ||
!k.startsWith('_tempAggregateCol_') && | ||
!$check.assigned(groupByProject[k]) | ||
) { | ||
groupByProject[k] = `$${k}`; | ||
@@ -327,0 +330,0 @@ } |
@@ -81,4 +81,3 @@ const getParsedValueFromBinaryExpressionModule = require('./getParsedValueFromBinaryExpression'); | ||
function makeArg(expr, depth, context) { | ||
// todo check all these types | ||
if (expr.type === 'function') { | ||
if (expr.type === 'function' || expr.type === 'aggr_func') { | ||
return makeProjectionExpressionPart(expr, context, depth); | ||
@@ -85,0 +84,0 @@ } |
{ | ||
"name": "@synatic/noql", | ||
"version": "2.1.17", | ||
"version": "2.1.18", | ||
"description": "Convert SQL statements to mongo queries or aggregates", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
297918
7460