My previous love affair with Scala has cooled a little since I discovered Kotlin, which is my language of choice for new projects. However, I did produce a light-weight Scala library at the time to make JDBC queries easy and transparent, with a gentle learning curve and a minimum of boilerplate. Recently I brushed up a little and upgraded the dependencies. You can find it on my gitlab.
In Jartah you define database metadata as Scala objects. Tables and columns become available as objects and their members.
This lets you build queries that take full advantage of type safety and Scala operator notation:
import acme.db.Person._ val employeeIds: List[(Long,String)] = session select(id,name) from Person where department in ("HR","FIN") and salary gt 3200.30 or (department ne "DEV" and salary lt 5000) getListAsTuple2(LongColumn,StringColumn)
IDE auto-completion comes standard without need for a plugin:
(Person.id is of class Column[Long], and requires a Long parameter)
(height and width are of Column[Dimension]. Values are constructed through implicit methods
that take a Double for meters, and an Int for centimeters. Read more.)
Cool, I want it!
There is an older beta release on Sonatype. You can include it by adding it to your managed dependencies in any sbt project, but I suggest you clone it directly from gitlab:
libraryDependencies += "com.jartah" % "jartah" % "0.4.beta6"
The API may change somewhat, hence the beta status. More integration and
performance testing is also needed before it is recommended for production use.
Yet another ORM framework?
Yes, Jartah has (very basic) ORM support, but first and foremost it is a a tool to make SQL more fun in Scala. Coming from an Oracle/PLSQL background, I believe ORM has a limited
set of use cases, yet often I see it implemented in projects for which it is entirely
unsuitable. If you are comfortable with SQL and (more importantly!) your application’s performance is at stake, why not give it a try.
I hope you’ll find it Just Another Reason To Avoid Hibernate.