Sometime, we have requirements for create classes corresponding to the existing database or Sometimes, in our initial phase of project, we are going to design database and tables first, after that, we are going to create classes for mapping our tables.
As we know, Slick is a FRM(Functional Relational Mapping) for scala. Its a kind of ORM but for scala, it supports Functional and Reactive programming supports. Like in my Java experience with Hibernate, we are mostly use Jboss tools for reverse engineering from database tables to Java Pojo classes or Entities, Or While we are using JOOQ , JOOQ also provide some plugins for generate the code corresponding to tables. Like, same as Hibernate, JOOQ and many more, Slick also provide a way for create classes corresponding to database tables by using Schema Code Generation. Below are simple steps for generate scala classes using slick code generator Or we said “Reverse Engineering” using generator. The steps are:
Step I: Create tables in Database.
Step II: Add dependencies and build.sbt settings.
After following these above steps, we are just execute
sbt clean compile command. After that, the source file name
Tables.scala in generated at
target/scala-/src_managed/slick/com/knoldus/github/models directory. The
Tables.scala contains scala classes corresponding to database tables. The generated code as below:
For further customization on slick code generator, please click on this link.