Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adamw
Created January 7, 2020 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/2614db385d4e27f0e58f4d5348bd01e5 to your computer and use it in GitHub Desktop.
Save adamw/2614db385d4e27f0e58f4d5348bd01e5 to your computer and use it in GitHub Desktop.
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