diff options
author | Jakob Odersky <jakob@driver.xyz> | 2018-09-12 17:30:33 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-10-09 16:19:39 -0700 |
commit | eb6f97b4cac548999cbf192ee83d9ba9a253b7c8 (patch) | |
tree | 6d75a23efc841a6f51e780913387000206d1fe94 /src/main/scala/xyz/driver/core/database/Converters.scala | |
parent | 4d1197099ce4e721c18bf4cacbb2e1980e4210b5 (diff) | |
download | driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.tar.gz driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.tar.bz2 driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.zip |
Move database-related functionality to separate project
This committ includes a breaking change. The database-specific utility
"Converters" trait threw an exception "DatabaseException" defined in
the rest package, thus breaking the dependency graph. The solution was
to move the DatabaseException class from rest to database and not
inherit ServiceExceptio any more.
Unfortunately, the rest classes also require the database exception in
propagating errors so this funtionality has been removed. The
rationale is:
1. Database exceptions are rare and result in 500 errors anyway
making the status code opaque to what actual error caused it.
2. In core 2.0, an improved tracing framework will make diagnosing
and following database errors easier, thereby attenuating the need
to forward details on service exceptions in responses.
Diffstat (limited to 'src/main/scala/xyz/driver/core/database/Converters.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/database/Converters.scala | 26 |
1 files changed, 0 insertions, 26 deletions
diff --git a/src/main/scala/xyz/driver/core/database/Converters.scala b/src/main/scala/xyz/driver/core/database/Converters.scala deleted file mode 100644 index ad79abf..0000000 --- a/src/main/scala/xyz/driver/core/database/Converters.scala +++ /dev/null @@ -1,26 +0,0 @@ -package xyz.driver.core.database - -import xyz.driver.core.rest.errors.DatabaseException - -import scala.reflect.ClassTag - -/** - * Helper methods for converting between table rows and Scala objects - */ -trait Converters { - def fromStringOrThrow[ADT](entityStr: String, mapper: (String => Option[ADT]), entityName: String): ADT = - mapper(entityStr).getOrElse(throw DatabaseException(s"Invalid $entityName in database: $entityStr")) - - def expectValid[ADT](mapper: String => Option[ADT], query: String)(implicit ct: ClassTag[ADT]): ADT = - fromStringOrThrow[ADT](query, mapper, ct.toString()) - - def expectExistsAndValid[ADT](mapper: String => Option[ADT], query: Option[String], contextMsg: String = "")( - implicit ct: ClassTag[ADT]): ADT = { - expectValid[ADT](mapper, query.getOrElse(throw DatabaseException(contextMsg))) - } - - def expectValidOrEmpty[ADT](mapper: String => Option[ADT], query: Option[String], contextMsg: String = "")( - implicit ct: ClassTag[ADT]): Option[ADT] = { - query.map(expectValid[ADT](mapper, _)) - } -} |