Guest User

Untitled

a guest
Dec 2nd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import slick.jdbc.JdbcProfile
  2. import slick.dbio._
  3.  
  4. import scala.concurrent.ExecutionContext
  5.  
  6. trait AuthDao[F[_]] {
  7.  
  8. def createUser(user: User): F[Int]
  9.  
  10. def findUserByLogin(login: String): F[Option[User]]
  11.  
  12. def createAuthInfo(authInfo: AuthInfo): F[Int]
  13.  
  14. def updateAuthInfo(authInfo: AuthInfo): F[Int]
  15.  
  16.  
  17. }
  18.  
  19. class AuthDaoImpl(val profile: JdbcProfile)(implicit executionContext: ExecutionContext) extends AuthDao[DBIO] {
  20.  
  21. import profile.api._
  22.  
  23. override def createUser(user: User): DBIO[Int] =
  24. sqlu"INSERT INTO users VALUES (${user.id}, ${user.login})"
  25.  
  26. override def updateAuthInfo(authInfo: AuthInfo): DBIO[Int] =
  27. sqlu"UPDATE auth_info SET password = ${authInfo.password} WHERE id = ${authInfo.id}"
  28.  
  29. override def createAuthInfo(authInfo: AuthInfo): DBIO[Int] =
  30. sqlu"INSERT INTO auth_info VALUES (${authInfo.id}, ${authInfo.login}, ${authInfo.password})"
  31.  
  32. override def findUserByLogin(login: String): DBIO[Option[User]] =
  33. sql"SELECT id, login FROM users WHERE login = $login".as[(String, String)].headOption
  34. .map(_.map { case (id, login) => User(id, login) })
  35.  
  36. }
Add Comment
Please, Sign In to add comment