Getting autoincrement values with Slick library in Scala

前端 未结 4 558
醉酒成梦
醉酒成梦 2021-02-01 21:22

How do I get the auto-incremented values for records inserted with Slick? The following code prints 1111. I would have expected it to print 1234

import scala.sli         


        
4条回答
  •  广开言路
    2021-02-01 21:50

    You can retrieve the generated value like this.

    Add autoInc method to Users object.

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

    Use Users.autoInc.insert instead.

    print(Users.autoInc.insert(User(None, "Jack", "Green" )))

    See also:

    https://github.com/slick/slick/issues/10

    https://github.com/slick/slick/commit/09a65a8e88a0363412e218dc5c06023b69809649

提交回复
热议问题