我已定义存储库:
trait Repo[F[_]] {
def findAll: Stream[F, Stop]
}
及其实现:
class DoobieRepo[F[_]: Sync](xa: Transactor[F]) extends Repo[F] {
override def findAll: Stream[F, Stop] =
readAllStopsQ.stream.transact(xa).map{
case (id, names, direction, lat, lon, typ) => Stop(id, names.split('|').toList, direction, lat, lon, typ)
}
def readAllStopsQ =
sql"select * from stop".query[(String, String, String, Float, Float, String)]
}
在应用程序中,我正在执行以下操作:
val transactor = Transactor.fromDriverManager[Task](
"org.postgresql.Driver",
"jdbc:postgresql:test",
"me",
""
)
val repo = new DoobieRepo[Task](transactor)
repo.findAll // Stream[Task, Stop]
问题是我如何例如将其打印到控制台? (通常对提取的数据执行一些操作)
我尝试过:
repo.findAll.map { x =>
println(x)
}
但未成功