From 068725b60c8c02114a772e56251905b9995fce6e Mon Sep 17 00:00:00 2001 From: Ujjwal Gupta Date: Mon, 27 Jul 2020 20:49:18 +0530 Subject: [PATCH] optimize count api --- src/grammar/count.pegjs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/grammar/count.pegjs b/src/grammar/count.pegjs index 5710c0c..0afd84e 100644 --- a/src/grammar/count.pegjs +++ b/src/grammar/count.pegjs @@ -1,14 +1,13 @@ countQuery = COUNT _ ("*"_)? FROM _ table:tableName _* where:whereQry? _* -option:(distinct/groupBy)* { - var distinct = false; - var groupBy = null; - option.forEach(val=>{ +options:(distinct/groupBy)* { + const option = {}; + options.forEach(val=>{ var key = Object.keys(val)[0]; switch(key){ case 'distinct': - distinct = val[key]; break; + option.distinct = val[key]; break; case 'groupBy': - groupBy = val[key]; break; + option.groupBy = val[key]; break; } }); return { @@ -16,8 +15,7 @@ option:(distinct/groupBy)* { data:{ from:table, where:where, - distinct : distinct, - groupBy:groupBy + ...option } } }