scala - Slick 3.0 avoid multiple selects -


i have collection of long , each element in collection, have lookup table in database , select. problem approach issues many selects , every time there new connection being opened , when make multiple calls method, connection pool exhausted soon!

val allids = seq(1,2,3,4....) 

for each id in allids, do:

db.run(fetchtablerowfromdb(_)) 

is there better way avoid giving many select statements?

you can use bulk fetch . assuming table class name "sampletable" , table name "sampletable".

val allids = seq(1,2,3,4....) val query = tablequery[sampletable].filter(_.id inset(allids.totraversable)) db.run(query) 

the above query similar

select * sampletable id in (1,2,3....); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -