slick/slick — pull request #573 by rfranco (2013-12-14 17:08:03+00:00)
Title: Nested Session

It's possible to use a same session without have to pass session in the argument across methods.
But it only works in same thread, because it uses ThreadLocal.

It checks if exists a session in DynamicVariable and give back or if not it creates a new one.

Example

```scala
case class User(id:Long, email:Option[Email]=None)
case class Email(email:String)
object UserService {

def getUser(id:Long):Option[User] = Repository.findUserById(id)

def getEmail(id:Long):Option[Email] = Repository.findEmailByUserId(id)

def getUserWithEmail(id:Long):Option[User] = {
val user = Repository.findUserById(id)
user.map{u =>
val email = Repository.findEmailByUserId(u.id)
u.copy(email = email)
}

}

object Repository {

def findUserById(id:Long):Option[User] = {
db.withNestedSession{ implicit s=>
Users.filter(_.id === id).firstOption
}
}

def findEmailByUserId(userId:Long):Option[Email] = {
db.withNestedSession{ implicit s=>
Emails.filter(_.userId === userId).firstOption
}
}
}
```