The questions have already been answered, but I came here looking for a different solution, so maybe this will be useful for other people.
As @Aldo says, we want to work at the DBIO level as much as possible, but I would go further and say that you should work at the Query level as much as possible, since this is compiled into a single sql statement that can be sent to the database data.
For example, an insert from select should compile into an INSERT INTO table1 SELECT... If you use multiple DBIOS using flatMap , as suggested, this will be compiled into SELECT , the values ββwill be transferred to memory, and then the INSERT will be compiled, interpolating the values ββin the string, and this new query will be sent to the database. In fact, it can be much slower if your choice returns a lot of results, and it can drain your memory in the worst case.
So, to compile something like this into a single query, you can write:
val bar: TableQuery[MySchema.Bar] val foo: Query[MySchema.Bar, Bar, Seq] val insert: DBIO[Int] = bar.forceInsertAll(foo)
simao source share