Scala 2 | Scala 3 |
---|---|
Auto generation for low-level Slick bulk insertion query using shapeless and shapeless-3.
import slick.bulkinsert.*
import AutoDerivedBulkInsertable.*
// or implicit val instance: BulkInsertable[User] = BulkInsertable.semiauto
object UserDAO extends BulkInsert[User] {
class UserTable extends Table[User] {
// ....
}
}
val users: Seq[User] = ???
UserDAO.bulkInsert(users)
It works on both Scala 2 and Scala 3.
libraryDependency += "com.github.y-yu" %% "slick-bulk-insert" % "<<version>>"
You can run the benchmark against Slick ++=
with ./sbt benchmark/Jmh/run
.
- Scala 2
[info] Benchmark Mode Cnt Score Error Units [info] Benchmarks.benchBulkInsertJmh ss 10 303.221 ± 61.063 ms/op [info] Benchmarks.benchSlickInsertAllJmh ss 10 2640.769 ± 74.003 ms/op
- Scala 3
[info] Benchmark Mode Cnt Score Error Units [info] Benchmarks.benchBulkInsertJmh ss 10 298.794 ± 55.171 ms/op [info] Benchmarks.benchSlickInsertAllJmh ss 10 2827.452 ± 142.903 ms/op
This bulk insertion is about 10 times faster than Slick ++=
.
Thanks @xuwei-k about Scala 3 macros, Slick SetParameter
and shapeless-3 information.