我在喷雾,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是正确的吗?它的效果非常好.
谢谢!