y-yu / slick-bulk-insert   0.2.0

MIT License GitHub

Auto bulk INSERT query generator for Slick

Scala versions: 3.x 2.13

Auto bulk INSERT query generator for Slick

Test and Benchmark

Scala 2 Scala 3
Maven Maven

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.

Getting started

libraryDependency += "com.github.y-yu" %% "slick-bulk-insert" % "<<version>>"

Benchmark

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 ++=.

Documentation

References

Acknowledgement

Thanks @xuwei-k about Scala 3 macros, Slick SetParameter and shapeless-3 information.