scala - Connection pooling in slick? -


Is there an easy way to use DB connection pool with Scala?

I use Apache Commons DBCP for this, in fact, you Only create a DataSource , which encompasses the pooling details, and pass DataSource to Slick:

  import org. Apache Commons.dbcp.BasicDataSource val datasource: datasource = {val ds = new basic data source ds.setDriverClassName ("org.hsqldb.jdbc.JDBCDriver") ds.setUsername ("SA") ds.setPassword ("") ds.setMaxActive (20); Ds.setMaxIdle (10); Ds.setInitialSize (10); Ds.setValidationQuery ("Information from SCHAMA CEETEM_USERS" by selection 1) New java.io.file ("target"). Mkdirs // Make sure that the folder exists for ds.setUrl ("jdbc: hsqldb: file: target / db / db") ds} // test data source validity data source .getConnection (). Get the close database () // Get a database that combines the pooled connection val database = Database.forDataSource (dataSource)   

This example uses HSQLda, but it is easy to use Can also be customized in other databases.

is a complete example (you can clone the project, and run sbt run in the elevator / directory it is working).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -