Scala Database mapping library similar to iBATIS

I have been using iBATIS for many years and have been very pleased with this. iBATIS makes it very good to write your own SQL when processing mundane work on mapping data to / from objects / database. I would like the special Scala library that does the same types of mappings as iBATIS. I believe Scala a specific tool will be

  • do not require objects to be Java Beans (i.e., receivers and setters)
  • use option instead of null values
  • I think it is, but maybe more

I have seen tons of things on the Internet telling about ORM for Java and Scala, but I have not seen anything like iBATIS for Scala.

Does anyone know about this tool in Scala?

+4
source share
5 answers

On the Scala website (www.scala-lang.org/node/6539) nilskp recommends orbroker (http://code.google.com/p/orbroker/) because it was originally written for Scala.

+2
source

Times have changed. There is currently a MyBatis Scala project that is much more idiomatic for Scala.

http://mybatis.imtqy.com/scala/

I rated it, and it looked a lot smaller than any other ORM or Scala oriented conservation libraries.

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

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

+6
source

Why not just keep using iBatis ? This is Java, after all (and therefore can be used from Scala). I still use Spring JDBC as my DAO layer.

Regarding scala specifics; you can add @BeanProperty annotation to generate getters / seters, and then declare a protection method for null :

 @BeanProperty var injectedXyz : String def xyz : Option[String] = Option(injectedXyz) 

Admittedly, this is not very convenient (i.e. requires an additional template). But I didn’t see anything like the widely used scala DAO level (for SQL)

+3
source

If I chose ORM, I would look at Squeryl (http://squeryl.org/). I tried Lift Mapper and it works well with Lift Webkit, but it is a bit integrated and has certain design options that I don’t like.

+1
source

You may prefer ScalikeJDBC. Take a look at this.

https://github.com/seratch/scalikejdbc

It also has a source code generator. Especially if you are accessing an existing obsolete database, this is very convenient.

https://github.com/seratch/scalikejdbc-mapper-generator

0
source

Source: https://habr.com/ru/post/1341210/


All Articles