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
Post a Comment