Count By
Definition
The countBy method allows you to count total records from a table that meet the given conditions.
Available methods
countBy(KCountFunction<KFrom, KQuery> kCountFunction): Receives aKCountFunctionthat allows adding conditions to the base query.countBy(String jdbc, KCountFunction<KFrom, KQuery> kCountFunction): Receives the name of datasource connection to which you need to connect and aKCountFunctionthat allows adding conditions to the base query.countBy(KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn): Receives aKCountFunctionthat allows adding conditions to the base query and aKColumnor aKTableColumnwhich will be supplied to thecountmethod.countBy(String jdbc, KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn): Receives the name of datasource connection to which you need to connect, aKCountFunctionthat allows adding conditions to the base query and aKColumnor aKTableColumnwhich will be supplied to thecountmethod.
Example: KCountFunction
Java code:
final Long totalRecords =
languageRepository.countBy(
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L))
);
SQL generated:
SELECT COUNT(*)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12
Example: String, KCountFunction
Java code:
final Long totalRecords =
languageRepository.countBy(
K.JDBC_LEGACY,
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L))
);
SQL generated:
SELECT COUNT(*)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12
Example: KCountFunction, KColumn
Java code:
final Long totalRecords =
languageRepository.countBy(
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L)),
LANGUAGE.ID
);
SQL generated:
SELECT COUNT(la.id)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12
Example: String, KCountFunction, KColumn
Java code:
final Long totalRecords =
languageRepository.countBy(
K.JDBC_LEGACY,
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L)),
LANGUAGE.ID
);
SQL generated:
SELECT COUNT(la.id)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12