私はスプレー、akka、scala、reactivemongo プロジェクトで作業しており、この特性を持っています
trait PersistenceManager {
val driver = new MongoDriver
val connection = driver.connection(List("localhost"))
def loan[A](collectionName: String)(f: BSONCollection => Future[A]): Future[A] = {
val db = connection("flujo_caja_db")
val collection = db.collection(collectionName)
f(collection)
}
}
また、次のようにその特性を使用する Dao のオブジェクトがあります。
object Dao extends PersistenceManager {
def find = loan("users"){
collection =>
collection.find(BsonDocument())....
}
}
データベースの val を persistencemanager トレイトでインスタンス化するのは正しいですか? それは本当にうまくいきます。
ありがとうございました!