Scala 如何在滑溜中加入?

Scala 如何在滑溜中加入?,scala,slick,Scala,Slick,我有两个查询,想做一个像sql这样的连接 例如我有这些桌子 object Family extends Table[Long]("Family") { def id = column[Long]("id") def * = id }## Heading ## object Person extends Table[(Long, Long)]("Person") { def id = column[Long]("id") def FamilyId = column[Long]("F

我有两个查询,想做一个像sql这样的连接

例如我有这些桌子

object Family extends Table[Long]("Family") {
  def id = column[Long]("id")
  def * = id
}## Heading ##
object Person extends Table[(Long, Long)]("Person") {
  def id = column[Long]("id")
  def FamilyId = column[Long]("FamilyId")
  def * = id ~ FamilyId ~ size
}
val implicitInnerJoin=for{

c从Slick文档:,下面是Slick中一些可能的连接以及与之相关的一些粗糙SQL

val implicitCrossJoin = for {
  c <- Coffees
  s <- Suppliers
} yield (c.name, s.name)

//SELECT c.name, s.name FROM Coffees c, Suppliers s


val implicitInnerJoin = for {
  c <- Coffees
  s <- Suppliers if c.supID === s.id
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c, Suppliers s where c.supID = s.id    

val explicitCrossJoin = for {
  (c, s) <- Coffees innerJoin Suppliers
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c CROSS JOIN Suppliers s    

val explicitInnerJoin = for {
  (c, s) <- Coffees innerJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c INNER JOIN Suppliers s ON (c.supID = s.id)   

val explicitLeftOuterJoin = for {
  (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name.?)
//SELECT c.name, s.name FROM Coffees c LEFT OUTER JOIN Suppliers s ON (c.supID = s.id)

val explicitRightOuterJoin = for {
  (c, s) <- Coffees rightJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name)
//SELECT c.name, s.name FROM Coffees c RIGHT OUTER JOIN Suppliers s ON (c.supID = s.id)

val explicitFullOuterJoin = for {
  (c, s) <- Coffees outerJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name.?)
//SELECT c.name, s.name FROM Coffees c FULL OUTER JOIN Suppliers s ON (c.supID = s.id)
val implicitCrossJoin=for{

重点是在理解中使用Family和Person作为两个生成器,并添加一个过滤器作为连接条件。您也可以使用查询作为生成器。
val implicitCrossJoin = for {
  c <- Coffees
  s <- Suppliers
} yield (c.name, s.name)

//SELECT c.name, s.name FROM Coffees c, Suppliers s


val implicitInnerJoin = for {
  c <- Coffees
  s <- Suppliers if c.supID === s.id
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c, Suppliers s where c.supID = s.id    

val explicitCrossJoin = for {
  (c, s) <- Coffees innerJoin Suppliers
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c CROSS JOIN Suppliers s    

val explicitInnerJoin = for {
  (c, s) <- Coffees innerJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c INNER JOIN Suppliers s ON (c.supID = s.id)   

val explicitLeftOuterJoin = for {
  (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name.?)
//SELECT c.name, s.name FROM Coffees c LEFT OUTER JOIN Suppliers s ON (c.supID = s.id)

val explicitRightOuterJoin = for {
  (c, s) <- Coffees rightJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name)
//SELECT c.name, s.name FROM Coffees c RIGHT OUTER JOIN Suppliers s ON (c.supID = s.id)

val explicitFullOuterJoin = for {
  (c, s) <- Coffees outerJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name.?)
//SELECT c.name, s.name FROM Coffees c FULL OUTER JOIN Suppliers s ON (c.supID = s.id)