Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#20: count when condition is provided is misleading #30

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading