Search code examples
databasescalaslick

Type mismatch, expected: DBIOAction[NotInferedR, NoStream, Nothing], actual: Future[PortalPostgresProfile.ProfileAction[Int, NoStream, Effect.Write]]


When i try to update some values in the database i get with db.run

Type mismatch, expected: DBIOAction[NotInferedR, NoStream, Nothing], actual: Future[PortalPostgresProfile.ProfileAction[Int, NoStream, Effect.Write]]

  def updateEmployerProductSettings(employer: Employer, 
    newProductSettingsInfo: ProductSettingsInfo, now: LocalDateTime): 
    Future[Int] = {


    val query = for {
      oldProductSettings <- getEmployerProductSettings(employer)
//((returns Future[ProductSettings]
    } yield {
//yield flattens the Future and i get only ProductSettings
//then i filter the TableQuery[ProductSettingsTable] by id
      productSettingsQuery.filter(_.employerId === employer.id)
//then map the productSetting by fields and update
      .map(
        productSettings =>
          (productSettings.enableSC,
            productSettings.enableLCon,
            productSettings.enableLRe,
            productSettings.enableLP,
            productSettings.SC,
            productSettings.enableL,
            productSettings.clearedAt))
        .update((
          newProductSettingsInfo.enableSC,
          newProductSettingsInfo.enableLCon,
          newProductSettingsInfo.enableLRe,
          newProductSettingsInfo.enableLP,
          newProductSettingsInfo.SC,
          newProductSettingsInfo.enableL,
          if (!oldProductSettings.clearedCanLoadSC && 
          newProductSettingsInfo.clearedCanLoadSC) Some(now) 
          else oldProductSettings.clearedAt
        ))
      }
     db.run(query)
   }

db.run is not working how can i change the type to the expected type?

Type mismatch, expected: DBIOAction[NotInferedR, NoStream, Nothing], actual: Future[PortalPostgresProfile.ProfileAction[Int, NoStream, Effect.Write]]


Solution

  • Try

    db.run(DBIO.sequence(query))
    

    or

    db.run(DBIO.from(query).flatten)