【发布时间】:2018-07-13 10:10:31
【问题描述】:
大家好,我是 slick 的新手,我怎样才能使这个序列变平?这样就可以返回注释代码
def insertIfNotExists(mapCountryStates: Map[String, Iterable[StateUtil]]): Future[Seq[Seq[StateTable]]] /*: Future[Seq[StateTable]]*/ = {
val interaction = DBIO.sequence(mapCountryStates.toSeq.map { case (alpha2Country, statesUtil) =>
val codes = statesUtil.map(_.alpha3Code)
for {
countryId <- Countries.filter(_.alpha2Code === alpha2Country).map(_.id).result.head
existing <- States.filter(s => (s.alpha3Code inSet codes) && s.countryId === countryId).result
stateTables = statesUtil.map(x => StateTable(0L, x.name, x.alpha3Code, countryId))
statesInserted <- StatesInsertQuery ++= stateTables.filter(s => !existing.exists(x => x.alpha3Code == s.alpha3Code && x.countryId == s.countryId))
} yield existing ++ statesInserted
})
db.run(interaction.transactionally)
}
如果我在这里写:
val 交互 = DBIO.sequence(...).扁平化
或这里:
db.run(interaction.flatten.transactionally)
[错误] 无法证明 Seq[Seq[StateRepository.this.StateTableMapping#TableElementType]] <: slick.dbio.dbioaction>
我用 DBIO.fold:
更新了我的定义【问题讨论】: