Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import slick.jdbc.JdbcProfile
- import slick.dbio._
- import scala.concurrent.ExecutionContext
- trait AuthDao[F[_]] {
- def createUser(user: User): F[Int]
- def findUserByLogin(login: String): F[Option[User]]
- def createAuthInfo(authInfo: AuthInfo): F[Int]
- def updateAuthInfo(authInfo: AuthInfo): F[Int]
- }
- class AuthDaoImpl(val profile: JdbcProfile)(implicit executionContext: ExecutionContext) extends AuthDao[DBIO] {
- import profile.api._
- override def createUser(user: User): DBIO[Int] =
- sqlu"INSERT INTO users VALUES (${user.id}, ${user.login})"
- override def updateAuthInfo(authInfo: AuthInfo): DBIO[Int] =
- sqlu"UPDATE auth_info SET password = ${authInfo.password} WHERE id = ${authInfo.id}"
- override def createAuthInfo(authInfo: AuthInfo): DBIO[Int] =
- sqlu"INSERT INTO auth_info VALUES (${authInfo.id}, ${authInfo.login}, ${authInfo.password})"
- override def findUserByLogin(login: String): DBIO[Option[User]] =
- sql"SELECT id, login FROM users WHERE login = $login".as[(String, String)].headOption
- .map(_.map { case (id, login) => User(id, login) })
- }
Add Comment
Please, Sign In to add comment