All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.actor.server.persist.SessionInfoRepo.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package im.actor.server.persist

import im.actor.server.model.SessionInfo
import slick.driver.PostgresDriver.api._

final class SessionInfoTable(tag: Tag) extends Table[SessionInfo](tag, "session_infos") {
  def authId = column[Long]("auth_id", O.PrimaryKey)

  def sessionId = column[Long]("session_id", O.PrimaryKey)

  def optUserId = column[Option[Int]]("user_id")

  def * = (authId, sessionId, optUserId) <> (SessionInfo.tupled, SessionInfo.unapply)
}

object SessionInfoRepo {
  val infos = TableQuery[SessionInfoTable]

  def create(authId: Long, sessionId: Long, optUserId: Option[Int]) =
    infos += SessionInfo(authId, sessionId, optUserId)

  def create(info: SessionInfo) =
    infos += info

  def createOrUpdate(info: SessionInfo) =
    infos.insertOrUpdate(info)

  def find(authId: Long, sessionId: Long) =
    infos.filter(i ⇒ i.authId === authId && i.sessionId === sessionId).result.headOption

  def updateUserId(authId: Long, sessionId: Long, optUserId: Option[Int]) =
    infos.filter(i ⇒ i.authId === authId && i.sessionId === sessionId).map(_.optUserId).update(optUserId)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy