To accomplish this in a transaction, you will need to create one action containing your queries and logic. Then run this action with the transaction.
Change your example:
import scala.concurrent.ExecutionContext.Implicits.global val action = tableQuery.filter(blah).result.flatMap { x => if (someLogicNotInSql(x)) tableQuery.insert(someFoo) else tableQuery.insert(someBah) }
flatMap requires an argument from x to a DBIO[T] . He will consistently group the two actions, allowing the second to use the result of the first.
To complete this collaborative action, you will need an execution context. (Because your calculation, if (someLogicNotInSql ... , will have to run in some thread somewhere, and not in the context of the internal context).
You can combine this combined action into a transaction and just call run once:
val future = database.run(action.transactionally)
source share