使用Slick独立存储数据库连接的位置



我在网上找到了很多例子,这些例子在特征中调用了Database.forConfig,每个存储库都扩展了这个特征。一些例子:https://github.com/BBartosz/akkaRestApi/blob/master/src/main/scala/utils/DatabaseConfig.scala

https://github.com/Platoonhead/SlickWithScala/blob/master/src/main/scala/com/edu/knoldus/connection/ConnectedDbMysql.scala

https://github.com/cdiniz/slick-akka-http/blob/master/src/main/scala/utils/PersistenceModule.scala

当拥有许多存储库时,它是否会导致创建太多的数据库客户端对象实例、内存开销、任何其他性能问题?

拥有一个将调用 Database.forConfig 并具有指向数据库的链接的对象不是更好吗?

这里的最佳实践是什么?

以下是我如何做到这一点的示例:

https://github.com/joesan/plant-simulator/blob/master/app/com/inland24/plantsim/config/AppConfig.scala

所以我基本上要做的是,我创建一个将调用 Slick API 的变量副本,然后指定我在连接池中想要的线程数(实际上是连接数(。

http://slick.lightbend.com/doc/3.0.0/database.html

最新更新