scalaslickslick-codegen

Scala Slick codegen custom naming


I'm using slick codegen to generate table definitions for myMySql db. How can I override slick's codegen naming conventions? It generates following code for table query objects:

lazy val User = new TableQuery(tag => new User(tag))

I want it to look like this instead:

lazy val slickUser = new TableQuery(tag => new User(tag))

P.S. I have seen this example: https://github.com/slick/slick-codegen-customization-example, but I wonder if there is an easier way to achieve this ?


Solution

  • There is no "easier" way. At least I'm not aware of one. But you may find this sbt plugin useful: sbt-slick-codegen. Your slickCodegenCodeGenerator in build.sbt would look like this then (untested):

    slickCodegenCodeGenerator := { (model:  m.Model) =>
      new SourceCodeGenerator(model) {
        override def tableName = (dbName: String) => "slick" + dbName.capitalize
      }
    }