gpt4 book ai didi

scala - 如何正确比较 Slick 中的 Options 成员?

转载 作者:行者123 更新时间:2023-12-04 12:31:43 25 4
gpt4 key购买 nike

我正在处理地址和成员 子前提 (apartment/condo #) 导致检索丢失。我也担心 subpremise 是我的唯一索引约束的一部分,因为它可以为 null。

故障过滤器:

tableQuery.filter(c=> (c.longitude === r.longitude && c.latitude === r.latitude) ||
(c.streetNumber === r.streetNumber && c.route === r.route && c.subpremise === r.subpremise && c.neighborhoodId === r.neighborhoodId))

成功过滤:(通过删除子前提)
tableQuery.filter(c=> (c.longitude === r.longitude && c.latitude === r.latitude) ||
(c.streetNumber === r.streetNumber && c.route === r.route && c.neighborhoodId === r.neighborhoodId))

我已经在 s.t. 下面包含了定义。如果我错过了另一个促成因素,希望它会被注意到。
case class Address(id:Option[Long],streetNumber:Short,route:String,subpremise:Option[String],neighborhoodId:Fk,latitude:Option[Double],longitude:Option[Double])

class Addresses(tag: Tag) extends Table[Address](tag, "addresses") with Logging {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def streetNumber = column[Short]("street_number")
def route = column[String]("route",O.NotNull)
def subpremise = column[Option[String]]("subpremise")
def neighborhoodId = column[Long]("neighborhood",O.NotNull)
def latitude = column[Option[Double]]("latitude")
def longitude = column[Option[Double]]("longitude")

//Constraints
def idx = index("idx_streetnum_route_subpremise_neighborhood", (streetNumber,route,subpremise,neighborhoodId), unique = true)
def gps = index("gps", (latitude,longitude), unique = true)

//Foreign Key
def neighborhood = foreignKey("NEIGHBORHOOD_FK", neighborhoodId, Neighborhoods.tableQuery)(_.id)

def * = (id.?,streetNumber,route,subpremise,neighborhoodId,latitude,longitude) <> (Address.tupled,Address.unapply)
}

最佳答案

答案是使用以下检查。

( //Option Scenario both are defined
(c.subpremise.isDefined && r.subpremise.isDefined && c.subpremise === r.subpremise) ||
//Option Scenario both are empty
(c.subpremise.isEmpty && r.subpremise.isEmpty)
)

关于scala - 如何正确比较 Slick 中的 Options 成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24390868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com