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/package.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/package.scala')
-rw-r--r-- | core-database/src/main/scala/xyz/driver/core/database/package.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/core-database/src/main/scala/xyz/driver/core/database/package.scala b/core-database/src/main/scala/xyz/driver/core/database/package.scala new file mode 100644 index 0000000..aee14c6 --- /dev/null +++ b/core-database/src/main/scala/xyz/driver/core/database/package.scala @@ -0,0 +1,61 @@ +package xyz.driver.core + +import java.sql.{Date => SqlDate} +import java.util.Calendar + +import date.{Date, Month} +import slick.dbio._ +import slick.jdbc.JdbcProfile +import slick.relational.RelationalProfile + +package object database { + + type Schema = { + def create: DBIOAction[Unit, NoStream, Effect.Schema] + def drop: DBIOAction[Unit, NoStream, Effect.Schema] + } + + @deprecated( + "sbt-slick-codegen 0.11.0+ no longer needs to generate these methods. Please use the new `CodegenTables` trait when upgrading.", + "driver-core 1.8.12") + type GeneratedTables = { + // structure of Slick data model traits generated by sbt-slick-codegen + val profile: JdbcProfile + def schema: profile.SchemaDescription + + def createNamespaceSchema: StreamingDBIO[Vector[Unit], Unit] + def dropNamespaceSchema: StreamingDBIO[Vector[Unit], Unit] + } + + /** A structural type for schema traits generated by sbt-slick-codegen. + * This will compile with codegen versions before 0.11.0, but note + * that methods in [[GeneratedTables]] are no longer generated. + */ + type CodegenTables[Profile <: RelationalProfile] = { + val profile: Profile + def schema: profile.SchemaDescription + } + + private[database] def sqlDateToDate(sqlDate: SqlDate): Date = { + // NOTE: SQL date does not have a time component, so this date + // should only be interpreted in the running JVMs timezone. + val cal = Calendar.getInstance() + cal.setTime(sqlDate) + Date(cal.get(Calendar.YEAR), Month(cal.get(Calendar.MONTH)), cal.get(Calendar.DAY_OF_MONTH)) + } + + private[database] def dateToSqlDate(date: Date): SqlDate = { + val cal = Calendar.getInstance() + cal.set(date.year, date.month, date.day, 0, 0, 0) + new SqlDate(cal.getTime.getTime) + } + + @deprecated("Dal is deprecated. Please use Repository trait instead!", "1.8.26") + type Dal = Repository + + @deprecated("SlickDal is deprecated. Please use SlickRepository class instead!", "1.8.26") + type SlickDal = SlickRepository + + @deprecated("FutureDal is deprecated. Please use FutureRepository class instead!", "1.8.26") + type FutureDal = FutureRepository +} |