Created
January 7, 2020 07:06
-
-
Save adamw/2614db385d4e27f0e58f4d5348bd01e5 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
trait Dao[F[_]] { | |
def currentPoints(userId: UUID): F[Int] | |
def updatePoints(userId: UUID, value: Int): F[Unit] | |
} | |
import doobie._ | |
import doobie.implicits._ | |
import doobie.postgres.implicits._ | |
object DefaultDao extends Dao[ConnectionIO] { | |
override def currentPoints(userId: UUID): doobie.ConnectionIO[Int] = | |
sql"SELECT points FROM user_points WHERE user_id = $userId" | |
.query[Int].unique | |
override def updatePoints(userId: UUID, value: Int): doobie.ConnectionIO[Unit] = | |
sql"UPDATE user_points SET points = $value WHERE user_id = $userId" | |
.update.run.map(_ => ()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment