Skip to content

Commit

Permalink
#20: count when condition is provided is misleading (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedeki authored Aug 19, 2024
1 parent 7971646 commit 8b2b77a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions balta/src/main/scala/za/co/absa/db/balta/classes/DBTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ case class DBTable(tableName: String) extends DBQuerySupport{
* @param connection - a database connection used for the SELECT operation.
* @return - the number of rows
*/
@deprecated("Use countOnCondition instead", "0.2.0")
def count(params: NamedParams)(implicit connection: DBConnection): Long = {
composeCountAndRun(strToOption(paramsToWhereCondition(params)), params.setters)
}
Expand All @@ -166,10 +167,31 @@ case class DBTable(tableName: String) extends DBQuerySupport{
* @param connection - a database connection used for the SELECT operation.
* @return - the number of rows
*/
@deprecated("Use countOnCondition instead", "0.2.0")
def count(condition: String)(implicit connection: DBConnection): Long = {
composeCountAndRun(strToOption(condition))
}

/**
* Counts the rows in the table based on the provided parameters that form a condition.
* @param params - the parameters used for the WHERE clause
* @param connection - a database connection used for the SELECT operation.
* @return - the number of rows
*/
def countOnCondition(params: NamedParams)(implicit connection: DBConnection): Long = {
composeCountAndRun(strToOption(paramsToWhereCondition(params)), params.setters)
}

/**
* Counts the rows in the table based on the provided condition.
* @param condition - the condition used for the WHERE clause
* @param connection - a database connection used for the SELECT operation.
* @return - the number of rows
*/
def countOnCondition(condition: String)(implicit connection: DBConnection): Long = {
composeCountAndRun(strToOption(condition))
}

private def composeSelectAndRun[R](whereCondition: Option[String], orderByExpr: Option[String], setters: List[SetterFnc] = List.empty)
(verify: QueryResult => R)
(implicit connection: DBConnection): R = {
Expand Down

0 comments on commit 8b2b77a

Please sign in to comment.