scala - Slick Database Instantiation And Connection Pool Logic -


i instantiating slick database code similar to

import slick.jdbc.jdbcbackend.database  val db : database =  database forconfig "configpath" 

the query constructed function takes in user id , returns user name database table:

def queryname(userid : string) =   {     row <- tablequery[tables.mytable] if row.userid === userid   } yield row.username 

and running query produce distinct publisher values:

val p1 : publisher[string] = db stream (queryname("foo").result)  val p2 : publisher[string] = db stream (queryname("bar").result) 

finally, question is: do multiple calls db.stream utilize same connection in connection pool?

in other words, once i've instantiated database same locking in on single connection?

the implication true utilization of connections in pool require function create database values before querying:

//is necessary?  val db = () => database forconfig "configpath"  val p1 = db() stream (queryname("foo").result) 

thank in advance consideration , response

according slick documentation database thread pool:

when using database.forconfig, thread pool configured directly in external configuration file connection parameters.

my hypothesis here using connection pool (which recommended in production environments) , have configured in external configuration file (the 1 referred configpath).

you don't have worry database connections since database object (your db) managing you.

each call db.stream() uses (and withdraw) connection pool (eventually opening new 1 according pool size , configuration) , releases afterwards pool.

for further details on how connection pool works , how configure (e.g. size) in slick can found @ connection-pools.

an addictional note adding-slick-to-your-project:

if want use slick’s connection pool support, need add hikaricp dependency.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -