我正在使用 Scala 并使用 Squeryl 从我的数据库中检索数据。理想情况下,使用调用数据库的方法,我希望返回类型为:
List[Int, Int, List[MyType]]
你需要知道的关于 MyType
的所有信息是它有一个名为 id
的参数和另一个名为 teamId
的参数,当我查询数据库时,我正在寻找所有的数据有 3 个 ID 之一。目前,我的查询返回属于这 3 个 ID 之一的所有数据。但是,我需要主 List
中的每个元素都包含属于该 ID 的数据。
例如,假设 IDs are 1, 2, 3
和 teamId = 10
:
List[(1, 10, List[(1, 10, ...), (1, 10, ...),...]),
(2, 10, List[(2, 10, ...), (2, 10, ...),...]),
(3, 10, List[(3, 10, ...), (3, 10, ...),...])]
我查询数据库的代码是:
inTransaction {
from(Schema.attendanceOnDate)(a =>
where(a.scheduleId in
from(Schema.schedule)(s =>
where(s.id in
from(Schema.attendanceOnDate)(a1 =>
where((a1.teamId === teamId) and (a1.date >= startDate) and (a1.date < endDate)
) select (a1.scheduleId)
)
) select (s.id)
)
) select (a)
).toList
}
正如您可能知道的,这只是返回一个 MyType
列表,而不是我想要的格式。有没有办法在这个查询中以我想要的格式获取数据,或者我是否必须在 Scala 中做一些额外的事情来将列表分成 3 个列表?如果是这样,如果我想根据值 id
拆分此列表,我该怎么做?