Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何将一个光滑查询的结果用于另一个中间有计算的查询_Scala_Slick - Fatal编程技术网

Scala 如何将一个光滑查询的结果用于另一个中间有计算的查询

Scala 如何将一个光滑查询的结果用于另一个中间有计算的查询,scala,slick,Scala,Slick,我有一个数据库表InventoryLotUsage,其中包含id、inventoryLotId和date列。我想删除一个InventoryLot,但在此之前,我需要根据日期和一些其他条件更新具有外键inventoryLotId的InventoryLotUsage行。 我的问题是如何使用一元联接查询数据,对其进行一些计算,并使用这些计算的结果在Slick中运行一个更新所有事务 我试图得到一系列这样的行 for { il <- InventoryLot.filter(_.id ==

我有一个数据库表InventoryLotUsage,其中包含id、inventoryLotId和date列。我想删除一个InventoryLot,但在此之前,我需要根据日期和一些其他条件更新具有外键inventoryLotId的InventoryLotUsage行。
我的问题是如何使用一元联接查询数据,对其进行一些计算,并使用这些计算的结果在Slick中运行一个更新所有事务

我试图得到一系列这样的行

for {
      il <- InventoryLot.filter(_.id === id)
      lotUsage <- InventoryLotUsage.filter(_.inventoryLotId === id).result
      groupedUsage = lotUsage.groupBy(_.date)
      ...
}
用于{
il您需要撰写以归档所需结果。例如:

加载所需的所有数据

val loadStaffAction = (for {
   il <- InventoryLot.filter(_.id === id)
   lotUsage <- InventoryLotUsage.filter(_.inventoryLotId === id)
} yield (il, lotUsage)).result
在此之后,您可以在一个事务中运行所有查询

db.run(updateAction.transactionally)

我想你忘了在
il上的结果了
val updateAction = loadStaffAction.map { result =>
  // creating update statements based on some computations and conditions
  DBIO.seq(
    InventoryLotUsage.filter(_.id === inventory1.id).map(_.name).update("new value"),
    InventoryLotUsage.filter(_.id === inventory2.id).map(_.name).update("another value"),
  );
}
db.run(updateAction.transactionally)