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 /core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.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 'core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.scala')
-rw-r--r-- | core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.scala b/core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.scala new file mode 100644 index 0000000..8293371 --- /dev/null +++ b/core-database/src/main/scala/xyz/driver/core/database/SlickGetResultSupport.scala @@ -0,0 +1,30 @@ +package xyz.driver.core.database + +import slick.jdbc.GetResult +import xyz.driver.core.date.Date +import xyz.driver.core.time.Time +import xyz.driver.core.{Id, Name} + +trait SlickGetResultSupport { + implicit def GetId[U]: GetResult[Id[U]] = + GetResult(r => Id[U](r.nextString())) + implicit def GetIdOption[U]: GetResult[Option[Id[U]]] = + GetResult(_.nextStringOption().map(Id.apply[U])) + + implicit def GetName[U]: GetResult[Name[U]] = + GetResult(r => Name[U](r.nextString())) + implicit def GetNameOption[U]: GetResult[Option[Name[U]]] = + GetResult(_.nextStringOption().map(Name.apply[U])) + + implicit val GetTime: GetResult[Time] = + GetResult(r => Time(r.nextTimestamp.getTime)) + implicit val GetTimeOption: GetResult[Option[Time]] = + GetResult(_.nextTimestampOption().map(t => Time(t.getTime))) + + implicit val GetDate: GetResult[Date] = + GetResult(r => sqlDateToDate(r.nextDate())) + implicit val GetDateOption: GetResult[Option[Date]] = + GetResult(_.nextDateOption().map(sqlDateToDate)) +} + +object SlickGetResultSupport extends SlickGetResultSupport |