Created
March 26, 2022 18:30
-
-
Save supermanue/9e4c7ceddc039f4c8a7c66cc8d5d57c5 to your computer and use it in GitHub Desktop.
testing DB
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
case class TestDB(users: Ref[Vector[User]]) extends StoragePort { | |
def get(id: Int): IO[AppError, User] = | |
users.get.flatMap(users => IO.require(UserNotFound(id))(Task.succeed(users.find(_.id.value == id)))) | |
def create(user: User): IO[AppError, User] = | |
users.update(_ :+ user).map(_ => user) | |
def delete(id: Int): Task[Boolean] = | |
users.modify(users => true -> users.filterNot(_.id.value == id)) | |
} | |
object TestDB { | |
val layer: ZLayer[Any, Nothing, UserPersistence] = | |
ZLayer.fromEffect(Ref.make(Vector.empty[User]).map(TestDB(_))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment