Add count distinct option to count action

This commit is contained in:
2023-04-24 12:12:41 -05:00
parent 2495989584
commit 1407f3c63c
5 changed files with 112 additions and 1 deletions

View File

@ -788,6 +788,7 @@ public class QJavalinImplementation
}
countInput.setQueryJoins(processQueryJoinsParam(context));
countInput.setIncludeDistinctCount(QJavalinUtils.queryParamIsTrue(context, "includeDistinct"));
CountAction countAction = new CountAction();
CountOutput countOutput = countAction.execute(countInput);
@ -861,6 +862,11 @@ public class QJavalinImplementation
QueryAction queryAction = new QueryAction();
QueryOutput queryOutput = queryAction.execute(queryInput);
int rowIndex = 0;
for(QRecord record : queryOutput.getRecords())
{
record.setValue("__qRowIndex", rowIndex++);
}
QJavalinAccessLogger.logEndSuccess(logPair("recordCount", queryOutput.getRecords().size()), logPairIfSlow("filter", filter, SLOW_LOG_THRESHOLD_MS));
context.result(JsonUtils.toJson(queryOutput));

View File

@ -22,6 +22,7 @@
package com.kingsrook.qqq.backend.javalin;
import java.util.Objects;
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
@ -52,6 +53,23 @@ public class QJavalinUtils
/*******************************************************************************
** Returns true iff context has a valid query parameter by the given name, with
** a value of "true".
*******************************************************************************/
public static boolean queryParamIsTrue(Context context, String name) throws QValueException
{
String value = context.queryParam(name);
if(Objects.equals(value, "true"))
{
return (true);
}
return (false);
}
/*******************************************************************************
** Returns Integer if context has a valid int form parameter by the given name,
** Returns null if no param (or empty value).