Question

  1. How can I output the generated raw SQL that my slick query will send to mysql? (for debug purposes)

  2. Can someone suggest a pattern where I could, on a per request basis, pass a dataSource (jdbc pool) to my data layer?

The idea is I might have 10 different database pools, each connecting to a different database. I would like to pass in this dataSource dynamically on a per request basis to my data layer based on the currently logged in user.

Was it helpful?

Solution

1 `someQuery.selectStatement``

2 How about

  // somewhere central
  def getDataSourceForUser(user: User) = /* <- your user to DS mapping here */
  def db(user: User) = Database.fromDataSource(getDataSourceForUser(user))

  // in your query code:
  db(currentUser).withSession{ implicit session =>
    // <- your queries here
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top