Skip to content

Commit

Permalink
Add lenientString to SqlRow
Browse files Browse the repository at this point in the history
And use it for ColReader to restore previous behaviour
  • Loading branch information
tmccombs committed Sep 26, 2023
1 parent fd73b7a commit a30000f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object ColReader {
implicit val intReader: ColReader[Int] = ColReader { (col, row) => row.intOption(col)}
implicit val longReader: ColReader[Long] = ColReader { (col, row) => row.longOption(col)}
implicit val shortReader: ColReader[Short] = ColReader { (col, row) => row.shortOption(col)}
implicit val stringReader: ColReader[String] = ColReader { (col, row) => row.stringOption(col)}
implicit val stringReader: ColReader[String] = ColReader { (col, row) => row.lenientStringOption(col)}
implicit val uuidReader: ColReader[UUID] = ColReader[UUID] { (col, row) => row.uuidOption(col)}

def enumReader[A <: Enumeration](e: A): ColReader[e.Value] = {
Expand Down
9 changes: 9 additions & 0 deletions relate/src/main/scala/com/lucidchart/relate/SqlRow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class SqlRow(val resultSet: java.sql.ResultSet) extends ResultSetWrapper {
}
}

def lenientString(column: String): String = lenientStringOption(column).get
/**
* Like [[stringOption]], but calls `getString` instead of `getObject`, so may
* convert other types into Strings, depending on the driver.
*/
def lenientStringOption(column: String): Option[String] = getResultSetOption(resultSet.getString(column))

def int(column: String): Int = intOption(column).get
def intOption(column: String): Option[Int] = getResultSetOption(resultSet.getInt(column))

Expand Down Expand Up @@ -319,6 +326,8 @@ object SqlResultTypes {

def string(column: String)(implicit sr: SqlRow) = sr.string(column)
def stringOption(column: String)(implicit sr: SqlRow) = sr.stringOption(column)
def lenientString(column: String)(implicit sr: SqlRow) = sr.lenientString(column)
def lenientStringOption(column: String)(implicit sr: SqlRow) = sr.lenientStringOption(column)
def int(column: String)(implicit sr: SqlRow) = sr.int(column)
def intOption(column: String)(implicit sr: SqlRow) = sr.intOption(column)
def double(column: String)(implicit sr: SqlRow) = sr.double(column)
Expand Down

0 comments on commit a30000f

Please sign in to comment.