我正在从事喷雾、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())....
}
}
在我的persistencemanager trait 中实例化这些数据库值是正确的吗?它真的很好用。
谢谢!