Reverse engineering using Slick 3.2 and Scala

Reading Time: < 1 minute

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.


Written by 

Harmeet Singh is a lead consultant, with experience of more than 5 years. He has expertise in Scala, Java, JVM, and functional programming. On a personal front; he is a food lover.

3 thoughts on “Reverse engineering using Slick 3.2 and Scala1 min read

Comments are closed.

%d bloggers like this: