Created
July 16, 2019 12:12
-
-
Save adamw/65e0672a01250db6fddb3c1aee2f544b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object UserModel { | |
def findById(id: Id @@ User): ConnectionIO[Option[User]] = { | |
findBy(fr"id = $id") | |
} | |
def findByEmail(email: String @@ LowerCased): ConnectionIO[Option[User]] = { | |
findBy(fr"email_lowercase = $email") | |
} | |
private def findBy(by: Fragment): ConnectionIO[Option[User]] = { | |
(sql"SELECT id, login, login_lowercase, email_lowercase, password, created_on FROM users WHERE " ++ by) | |
.query[User] | |
.option | |
} | |
} | |
case class User( | |
id: Id @@ User, | |
login: String, | |
loginLowerCased: String @@ LowerCased, | |
emailLowerCased: String @@ LowerCased, | |
passwordHash: PasswordHash[SCrypt], | |
createdOn: Instant | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment