Customizing Slick Generator

2019-09-01 05:42发布

问题:

I'm using the Slick generator to generate my tabble definitions based on my database and I would like to change a thing in the generated code. When it generates the classes it does not put my auto increment keys as Option[Int] = None in the case classes... Is there a way to do that? And maybe add an autoinc method in the table definition that returns the generated id like this for example:

def autoInc = id.? ~ name <> (User, User.unapply _) returning id

回答1:

The code generator already supports this. You have to set autoIncLastAsOption = true.

new SourceCodeGenerator(model){
    override def Table = new Table(_){
        override def autoIncLastAsOption = true
    }
}

Also see http://slick.typesafe.com/doc/2.0.0/code-generation.html for more help with customizing the code generator.



标签: scala slick