-
Notifications
You must be signed in to change notification settings - Fork 0
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
#13: QueryResultRow conversion for Product types #36
#13: QueryResultRow conversion for Product types #36
Conversation
* implicit class that adds the ability to convert `QueryResultRow` to a product type * implicit classes that add `getOrThrow` methods to `Option` and `Map` * copied `NamingConvention` classes from Fa-DB * added `sbt testAll` alias * enhanced the README.md to include some basic classes of the library used for DB testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- pull
- code review
- run all test types
balta/src/main/scala/za/co/absa/db/balta/implicits/QueryResultRowImplicits.scala
Outdated
Show resolved
Hide resolved
balta/src/test/resources/db/postgres/08_testing.simple_function.sql
Outdated
Show resolved
Hide resolved
balta/src/test/scala/za/co/absa/db/balta/implicits/MapImplicitsUnitTests.scala
Show resolved
Hide resolved
...a/src/test/scala/za/co/absa/db/balta/implicits/QueryResultRowImplicitsIntegrationTests.scala
Outdated
Show resolved
Hide resolved
...a/src/test/scala/za/co/absa/db/balta/implicits/QueryResultRowImplicitsIntegrationTests.scala
Outdated
Show resolved
Hide resolved
balta/src/test/scala/za/co/absa/db/mag/naming/implementations/AsIsNamingUnitTests.scala
Show resolved
Hide resolved
balta/src/test/scala/za/co/absa/db/mag/naming/implementations/SnakeCaseNamingUnitTests.scala
Show resolved
Hide resolved
Co-authored-by: miroslavpojer <[email protected]>
JaCoCo 'balta' module code coverage report - scala 2.12.18
|
@@ -35,7 +36,10 @@ class QueryResultRow private[classes](val rowNumber: Int, | |||
private val columnNames: FieldNames) { | |||
|
|||
def columnCount: Int = fields.length | |||
def columnNumber(columnLabel: String): Int = columnNames(columnLabel.toLowerCase) | |||
def columnNumber(columnLabel: String): Int = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Label
terminology?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original terminology from JDBC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's column name right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I read here that it's this: https://bugs.mysql.com/bug.php?id=35610
so alias
or column name
. Not sure if in our case it's always only column name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at the ResultSet
class methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I still don't fully know the answer if you think deeper into it (i.e. whether both can be applied to our case or only column name) :D
https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html
E.g.
- columnLabel - the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
- Column names used as input to getter methods are case insensitive. When a getter method is called with a column name and several columns have the same name, the value of the first matching column will be returned. The column name option is designed to be used when column names are used in the SQL query that generated the result set. For columns that are NOT explicitly named in the query, it is best to use column numbers. If column names are used, the programmer should take care to guarantee that they uniquely refer to the intended columns, which can be assured with the SQL AS clause.
Okay, we can follow it. But maybe at least document it super briefly? That this terminology is coming from X with some link perhaps etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Basically, if we are using an underlying technology A that is using special terminology B for something that uses X and Y, and X is known thing - in our case column name - and if we are not using Y, then it makes sense not to follow A's way by using B, just use X; special-ish undocumented terms are never a good thing in my opinion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please suggest the documentation text. I am not sure I follow.
balta/src/test/resources/db/postgres/08_testing.simple_function.sql
Outdated
Show resolved
Hide resolved
Co-authored-by: Ladislav Sulak <[email protected]>
|
||
private def getParamValue[T: TypeTag](columnLabel: String, expectedType: Type): Any = { | ||
val value = row(columnLabel) | ||
if (isOptionType(expectedType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, deciding how to pass in the actual value to the constructor.
… of https://github.com/AbsaOSS/balta into feature/13-queryresultrow-conversion-for-product-types
QueryResultRow
to a product typegetOrThrow
methods toOption
andMap
NamingConvention
classes from Fa-DBsbt testAll
aliasCloses #13