aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/byspel/Tables.scala
blob: c86b785158910a0d63c78ad54ad1663a509ba140 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package byspel
// AUTO-GENERATED Slick data model
/** Stand-alone Slick data model for immediate use */
object Tables extends {
  val profile = slick.jdbc.SQLiteProfile
} with Tables

/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */
trait Tables {
  val profile: slick.jdbc.JdbcProfile
  import profile.api._
  import slick.model.ForeignKeyAction
  // NOTE: GetResult mappers for plain SQL are only generated for tables where Slick knows how to map the types of all columns.
  import slick.jdbc.{GetResult => GR}

  /** DDL for all tables. Call .create to execute. */
  lazy val schema
    : profile.SchemaDescription = Sessions.schema ++ Shadow.schema ++ Users.schema
  @deprecated("Use .schema instead of .ddl", "3.0")
  def ddl = schema

  /** Entity class storing rows of table Sessions
    *  @param sessionId Database column session_id SqlType(UUID), PrimaryKey
    *  @param userId Database column user_id SqlType(UUID)
    *  @param expires Database column expires SqlType(TIMESTAMP) */
  case class SessionsRow(sessionId: String,
                         userId: String,
                         expires: java.sql.Timestamp)

  /** GetResult implicit for fetching SessionsRow objects using plain SQL queries */
  implicit def GetResultSessionsRow(
      implicit e0: GR[String],
      e1: GR[java.sql.Timestamp]): GR[SessionsRow] = GR { prs =>
    import prs._
    SessionsRow.tupled((<<[String], <<[String], <<[java.sql.Timestamp]))
  }

  /** Table description of table sessions. Objects of this class serve as prototypes for rows in queries. */
  class Sessions(_tableTag: Tag)
      extends profile.api.Table[SessionsRow](_tableTag, "sessions") {
    def * =
      (sessionId, userId, expires) <> (SessionsRow.tupled, SessionsRow.unapply)

    /** Maps whole row to an option. Useful for outer joins. */
    def ? =
      (Rep.Some(sessionId), Rep.Some(userId), Rep.Some(expires)).shaped.<>(
        { r =>
          import r._; _1.map(_ => SessionsRow.tupled((_1.get, _2.get, _3.get)))
        },
        (_: Any) =>
          throw new Exception("Inserting into ? projection not supported."))

    /** Database column session_id SqlType(UUID), PrimaryKey */
    val sessionId: Rep[String] = column[String]("session_id", O.PrimaryKey)

    /** Database column user_id SqlType(UUID) */
    val userId: Rep[String] = column[String]("user_id")

    /** Database column expires SqlType(TIMESTAMP) */
    val expires: Rep[java.sql.Timestamp] = column[java.sql.Timestamp]("expires")

    /** Foreign key referencing Users (database name users_FK_1) */
    lazy val usersFk = foreignKey("users_FK_1", userId, Users)(
      r => r.id,
      onUpdate = ForeignKeyAction.NoAction,
      onDelete = ForeignKeyAction.Cascade)
  }

  /** Collection-like TableQuery object for table Sessions */
  lazy val Sessions = new TableQuery(tag => new Sessions(tag))

  /** Entity class storing rows of table Shadow
    *  @param userId Database column user_id SqlType(UUID), PrimaryKey
    *  @param hash Database column hash SqlType(STRING) */
  case class ShadowRow(userId: String, hash: String)

  /** GetResult implicit for fetching ShadowRow objects using plain SQL queries */
  implicit def GetResultShadowRow(implicit e0: GR[String]): GR[ShadowRow] = GR {
    prs =>
      import prs._
      ShadowRow.tupled((<<[String], <<[String]))
  }

  /** Table description of table shadow. Objects of this class serve as prototypes for rows in queries. */
  class Shadow(_tableTag: Tag)
      extends profile.api.Table[ShadowRow](_tableTag, "shadow") {
    def * = (userId, hash) <> (ShadowRow.tupled, ShadowRow.unapply)

    /** Maps whole row to an option. Useful for outer joins. */
    def ? =
      (Rep.Some(userId), Rep.Some(hash)).shaped.<>(
        { r =>
          import r._; _1.map(_ => ShadowRow.tupled((_1.get, _2.get)))
        },
        (_: Any) =>
          throw new Exception("Inserting into ? projection not supported."))

    /** Database column user_id SqlType(UUID), PrimaryKey */
    val userId: Rep[String] = column[String]("user_id", O.PrimaryKey)

    /** Database column hash SqlType(STRING) */
    val hash: Rep[String] = column[String]("hash")

    /** Foreign key referencing Users (database name users_FK_1) */
    lazy val usersFk = foreignKey("users_FK_1", userId, Users)(
      r => r.id,
      onUpdate = ForeignKeyAction.NoAction,
      onDelete = ForeignKeyAction.NoAction)
  }

  /** Collection-like TableQuery object for table Shadow */
  lazy val Shadow = new TableQuery(tag => new Shadow(tag))

  /** Entity class storing rows of table Users
    *  @param id Database column id SqlType(UUID), PrimaryKey
    *  @param primaryEmail Database column primary_email SqlType(STRING)
    *  @param fullName Database column full_name SqlType(STRING)
    *  @param avatar Database column avatar SqlType(STRING)
    *  @param lastLogin Database column last_login SqlType(TIMESTAMP) */
  case class UsersRow(id: String,
                      primaryEmail: String,
                      fullName: Option[String],
                      avatar: String,
                      lastLogin: Option[java.sql.Timestamp])

  /** GetResult implicit for fetching UsersRow objects using plain SQL queries */
  implicit def GetResultUsersRow(
      implicit e0: GR[String],
      e1: GR[Option[String]],
      e2: GR[Option[java.sql.Timestamp]]): GR[UsersRow] = GR { prs =>
    import prs._
    UsersRow.tupled(
      (<<[String],
       <<[String],
       <<?[String],
       <<[String],
       <<?[java.sql.Timestamp]))
  }

  /** Table description of table users. Objects of this class serve as prototypes for rows in queries. */
  class Users(_tableTag: Tag)
      extends profile.api.Table[UsersRow](_tableTag, "users") {
    def * =
      (id, primaryEmail, fullName, avatar, lastLogin) <> (UsersRow.tupled, UsersRow.unapply)

    /** Maps whole row to an option. Useful for outer joins. */
    def ? =
      (Rep.Some(id),
       Rep.Some(primaryEmail),
       fullName,
       Rep.Some(avatar),
       lastLogin).shaped.<>(
        { r =>
          import r._;
          _1.map(_ => UsersRow.tupled((_1.get, _2.get, _3, _4.get, _5)))
        },
        (_: Any) =>
          throw new Exception("Inserting into ? projection not supported."))

    /** Database column id SqlType(UUID), PrimaryKey */
    val id: Rep[String] = column[String]("id", O.PrimaryKey)

    /** Database column primary_email SqlType(STRING) */
    val primaryEmail: Rep[String] = column[String]("primary_email")

    /** Database column full_name SqlType(STRING) */
    val fullName: Rep[Option[String]] = column[Option[String]]("full_name")

    /** Database column avatar SqlType(STRING) */
    val avatar: Rep[String] = column[String]("avatar")

    /** Database column last_login SqlType(TIMESTAMP) */
    val lastLogin: Rep[Option[java.sql.Timestamp]] =
      column[Option[java.sql.Timestamp]]("last_login")
  }

  /** Collection-like TableQuery object for table Users */
  lazy val Users = new TableQuery(tag => new Users(tag))
}