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 aKCountFunction
that 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 aKCountFunction
that allows adding conditions to the base query.countBy(KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn)
: Receives aKCountFunction
that allows adding conditions to the base query and aKColumn
or aKTableColumn
which will be supplied to thecount
method.countBy(String jdbc, KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn)
: Receives the name of datasource connection to which you need to connect, aKCountFunction
that allows adding conditions to the base query and aKColumn
or aKTableColumn
which will be supplied to thecount
method.
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