1

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 ?

RB_
  • 1,195
  • 15
  • 35
  • You will need to override `tableName` of `slick.codegen.AbstractGenerator`. – Roman Dec 08 '16 at 07:49
  • Hello. I'm new to this technology, so I would appreciate getting more practical advice. Can it only be done the way as in this example - https://github.com/slick/slick-codegen-customization-example, or are there more straight-forward and simple ways, like overriding it in the config, of in the build.sbt "gen-tables" taks ? – RB_ Dec 08 '16 at 08:07

1 Answers1

1

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
  }
}
Roman
  • 5,651
  • 1
  • 30
  • 41