Customizing Slick Generator

和自甴很熟 提交于 2019-12-25 03:05:30

问题


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.



来源:https://stackoverflow.com/questions/22275022/customizing-slick-generator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!