Database.forDataSource 如何在 slick 中工作?
how does Database.forDataSource work in slick?
我目前正在建立一个使用 play slick with scala 的项目。从文档中我发现要获得一个会话,我们应该做
val db = Database.forDataSource(数据源:javax.sql.DataSource)
所以我遵循这个模式并在每个 Repository 层中使用它。(模型顶部的一个层类似于 dao)。
我有几个存储库,我复制了这一行。
我的问题是,这是否每次都有一个公共池时连接到数据库并且我们从这个池中获取连接?
来自精巧的文档:
Using a DataSource
You can provide a DataSource object to forDataSource. If you got it from the connection pool of your application framework, this plugs the pool into Slick.
val db = Database.forDataSource(dataSource: javax.sql.DataSource)
When you later create a Session, a connection is acquired from the pool and when the Session is closed it is returned to the pool.
我目前正在建立一个使用 play slick with scala 的项目。从文档中我发现要获得一个会话,我们应该做
val db = Database.forDataSource(数据源:javax.sql.DataSource)
所以我遵循这个模式并在每个 Repository 层中使用它。(模型顶部的一个层类似于 dao)。 我有几个存储库,我复制了这一行。
我的问题是,这是否每次都有一个公共池时连接到数据库并且我们从这个池中获取连接?
来自精巧的文档:
Using a DataSource You can provide a DataSource object to forDataSource. If you got it from the connection pool of your application framework, this plugs the pool into Slick.
val db = Database.forDataSource(dataSource: javax.sql.DataSource)
When you later create a Session, a connection is acquired from the pool and when the Session is closed it is returned to the pool.