Created
March 31, 2017 16:21
-
-
Save kryton/423d5d680eb7cb7dafec6c1a2d8d890b to your computer and use it in GitHub Desktop.
bill of parts/heirarchial queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Slick 2.x / play 2.4 | |
final def managementTree()(implicit session:Session):Set[String] = { | |
managerTreeIter(Set(this.login.toLowerCase)) | |
} | |
@tailrec | |
private def managerTreeIter(acc:Set[String])(implicit session:Session):Set[String] = { | |
this.manager match { | |
case None => acc | |
case Some(mgr) => mgr.managerTreeIter( acc ++Set( mgr.login.toLowerCase)) | |
} | |
} | |
// ** Slick 3.2.X / play 2.6 ** | |
def managementTreeUp(login:String):Future[Set[EmprelationsRow]] = { | |
def managementTreeUpI(login: String, acc: Future[Set[EmprelationsRow]]): Future[Set[EmprelationsRow]] = { | |
manager(login.toLowerCase).map { | |
case Some(m) => managementTreeUpI(m.login, acc.map { setMgr => setMgr ++ Set(m) }) | |
case None => acc | |
}.flatMap(identity) | |
} | |
managementTreeUpI(login, Future(Set.empty)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
manager function is
def manager(login:String): Future[Option[EmprelationsRow]] = {
val qry = (for {
emp <- Emprelations if emp.login === login.toLowerCase
mgr <- Emprelations if mgr.login === emp.managerid
} yield mgr).result.headOption
db.run(qry)
}