自定义光滑生成器

时间:2014-03-08 20:59:59

标签: scala slick

我正在使用Slick生成器根据我的数据库生成我的tabble定义,我想在生成的代码中更改一个东西。 当它生成类时,它不会将我的自动增量键设置为案例类中的Option [Int] = None ...有没有办法做到这一点? 并且可能在表定义中添加一个autoinc方法,它返回生成的id,例如:

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

1 个答案:

答案 0 :(得分:3)

代码生成器已经支持此功能。您必须设置autoIncLastAsOption = true

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

另请参阅http://slick.typesafe.com/doc/2.0.0/code-generation.html以获取有关自定义代码生成器的更多帮助。