Ali Salehi
Ali Salehi

Reputation: 6999

Creating parameterised prepared statements with Slick

In the following code:

val users = TableQuery[Users]
def getUserById(id:Int) = db(users.filter(_.id === id).result)

From what I understand, getUserById would create a prepared statement everytime the getUserById is executed and then discarded. Is there a way to cache the prepared statement so it is created only once and called many times.

Upvotes: 2

Views: 3106

Answers (1)

Mike Curry
Mike Curry

Reputation: 1609

The documentation for Slick indicates that you need to enable prepared statement caching on the connection pool configuration.

Here is quite a good article on it also.

The summary is that Slick seems to cache the strings that are used to prepare the actual statements, but delegates the caching of the actual prepared statements to the underlying connection pool implementation.

Upvotes: 4

Related Questions