Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Database Mapping Library Similar to iBATIS

I've been using iBATIS for years and have been very happy with it. iBATIS is very good about letting one write their own SQL while handling the mundane work of mapping data to/from the objects/database. I would love a Scala specific library that does the same type of mappings that iBATIS does. I figure a Scala specific tool would

  • not require the objects to be Java Beans (i.e. getters and setters)
  • use Option instead of null values
  • I think that's it, but there may be more

I've seen a bunch of stuff on the web talking about ORMs for Java and Scala, but I haven't seen anything like iBATIS for Scala.

Does anybody know of a tool like this in Scala?

like image 863
three-cups Avatar asked Dec 17 '22 17:12

three-cups


2 Answers

Times have changed. There is now a MyBatis Scala project which is much more idiomatic to Scala.

http://mybatis.github.io/scala/

I've evaluated it, and it looked like a lot less hassle than any of the other ORM or Scala oriented persistence libraries.

The links on their project page are currently broken, but you can get to the GitHub page here: https://github.com/mybatis/scala

They have various samples under "mybatis-scala-samples". This DAO / CRUD example is a particularly nice example: ItemDAO.scala

like image 165
Bryan Hunt Avatar answered Jan 09 '23 12:01

Bryan Hunt


Why not just carry on using iBatis? It's Java, after all (and hence can be used from Scala). I still use Spring JDBC as my DAO layer.

As for the scala-specifics; you could add the @BeanProperty annotation to generate getters/setters and then declare a method to guard for null:

@BeanProperty var injectedXyz : String

def xyz : Option[String] = Option(injectedXyz)

Admittedly this is not great (i.e. requires extra boilerplate). But I have not seen anything that looks like a widely-used scala DAO layer (for SQL)

like image 26
oxbow_lakes Avatar answered Jan 09 '23 11:01

oxbow_lakes