Skip to content

Commit

Permalink
#33: Make execution of function without verification easier (#34)
Browse files Browse the repository at this point in the history
* new function `DBFunction.execute` renamed to `perform`
* new function `DBFunction.getResult` which returns the list of function outputs
* improved documentation

---------

Co-authored-by: miroslavpojer <miroslav.pojer@absa.africa>
  • Loading branch information
benedeki and miroslavpojer authored Oct 8, 2024
1 parent 1c580ca commit 9f96889
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions balta/src/main/scala/za/co/absa/db/balta/classes/DBFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ sealed abstract class DBFunction private(functionName: String,
s"SELECT * FROM $functionName($paramsLine) $orderBy"
}

/**
* Executes the function without caring about the result. The goal is the side-effect of the function.
* @param connection - the database connection
*/
def perform()(implicit connection: DBConnection): Unit = {
execute("")(_ => ())
}

/**
* Executes the function without any verification procedure. It instantiates the function result(s) and returns them in
* a list.
* @param orderBy - the clause how to order the function result, if empty, default ordering is preserved
* examples:
* * "product_id DESC"
* * "product_name, import_date DESC"
* @param connection - the database connection
*/
def getResult(orderBy: String = "")(implicit connection: DBConnection): List[QueryResultRow] = {
execute(orderBy)(_.toList)
}

/**
* Executes the function and verifies the result via the verify function.
*
Expand All @@ -61,6 +82,9 @@ sealed abstract class DBFunction private(functionName: String,
* Executes the function and verifies the result via the verify function.
*
* @param orderBy - the clause how to order the function result
* examples:
* * "product_id DESC"
* * "product_name, import_date DESC"
* @param verify - the function that verifies the result
* @param connection - the database connection
* @tparam R - the type of the result that is returned by the verify function
Expand Down

0 comments on commit 9f96889

Please sign in to comment.