aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/database/package.scala
blob: aee14c6622959b1492963650397dc7d592f9109d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}