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
我多年来一直在使用iBATIS并且对它非常满意。 iBATIS非常适合让人们编写自己的SQL,同时处理将数据映射到对象/数据库或从对象/数据库映射数据的平凡工作。我想要一个Scala特定的库,它可以执行与iBATIS相同类型的映射。我想一个Scala特定工具会
- not require the objects to be Java Beans (i.e. getters and setters)
- 不要求对象是Java Bean(即getter和setter)
- use Option instead of null values
- 使用Option而不是null值
- 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.
我在网上看到了很多关于Java和Scala的ORM的东西,但我还没有看到像scala的iBATIS这样的东西。
Does anybody know of a tool like this in Scala?
在Scala中有人知道这样的工具吗?
5 个解决方案
#1
2
On the Scala website (www.scala-lang.org/node/6539), nilskp recommends orbroker (http://code.google.com/p/orbroker/) because it is written natively for Scala.
在Scala网站(www.scala-lang.org/node/6539)上,nilskp建议使用orbroker(http://code.google.com/p/orbroker/),因为它是为Scala本地编写的。
#2
6
Times have changed. There is now a MyBatis Scala project which is much more idiomatic to Scala.
时代变了。现在有一个MyBatis Scala项目,它比Scala更加惯用。
http://mybatis.github.io/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.
我已经对它进行了评估,它看起来比任何其他ORM或Scala导向的持久性库都要麻烦得多。
The links on their project page are currently broken, but you can get to the GitHub page here: https://github.com/mybatis/scala
他们的项目页面上的链接目前已被破坏,但您可以访问GitHub页面:https://github.com/mybatis/scala
They have various samples under "mybatis-scala-samples". This DAO / CRUD example is a particularly nice example: ItemDAO.scala
他们在“mybatis-scala-samples”下有各种样本。这个DAO / CRUD示例是一个特别好的示例:ItemDAO.scala
#3
3
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.
为什么不继续使用iBatis?毕竟它是Java(因此可以从Scala中使用)。我仍然使用Spring JDBC作为我的DAO层。
As for the scala-specifics; you could add the @BeanProperty
annotation to generate getters/setters and then declare a method to guard for null
:
至于scala-specifics;你可以添加@BeanProperty注释来生成getter / setter,然后声明一个方法来保护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)
不可否认,这并不是很好(即需要额外的样板)。但我还没有看到任何看起来像广泛使用的scala DAO层(对于SQL)
#4
1
If I were to choose an ORM I'd look into Squeryl (http://squeryl.org/). I've tried out the Lift Mapper and it works well with the Lift Webkit, but it's a little bit to integrated and have certain design choices I don't like.
如果我选择ORM,我会看看Squeryl(http://squeryl.org/)。我已经尝试过Lift Mapper,它与Lift Webkit配合得很好,但它有点集成并且有一些我不喜欢的设计选择。
#5
0
You might prefer ScalikeJDBC. Take a look at it.
您可能更喜欢ScalikeJDBC。看看吧。
https://github.com/seratch/scalikejdbc
https://github.com/seratch/scalikejdbc
It also has source code generator. Especially if you access the existing legacy database, it's much convenient.
它还有源代码生成器。特别是如果您访问现有的旧数据库,它会非常方便。
https://github.com/seratch/scalikejdbc-mapper-generator
https://github.com/seratch/scalikejdbc-mapper-generator
#1
2
On the Scala website (www.scala-lang.org/node/6539), nilskp recommends orbroker (http://code.google.com/p/orbroker/) because it is written natively for Scala.
在Scala网站(www.scala-lang.org/node/6539)上,nilskp建议使用orbroker(http://code.google.com/p/orbroker/),因为它是为Scala本地编写的。
#2
6
Times have changed. There is now a MyBatis Scala project which is much more idiomatic to Scala.
时代变了。现在有一个MyBatis Scala项目,它比Scala更加惯用。
http://mybatis.github.io/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.
我已经对它进行了评估,它看起来比任何其他ORM或Scala导向的持久性库都要麻烦得多。
The links on their project page are currently broken, but you can get to the GitHub page here: https://github.com/mybatis/scala
他们的项目页面上的链接目前已被破坏,但您可以访问GitHub页面:https://github.com/mybatis/scala
They have various samples under "mybatis-scala-samples". This DAO / CRUD example is a particularly nice example: ItemDAO.scala
他们在“mybatis-scala-samples”下有各种样本。这个DAO / CRUD示例是一个特别好的示例:ItemDAO.scala
#3
3
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.
为什么不继续使用iBatis?毕竟它是Java(因此可以从Scala中使用)。我仍然使用Spring JDBC作为我的DAO层。
As for the scala-specifics; you could add the @BeanProperty
annotation to generate getters/setters and then declare a method to guard for null
:
至于scala-specifics;你可以添加@BeanProperty注释来生成getter / setter,然后声明一个方法来保护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)
不可否认,这并不是很好(即需要额外的样板)。但我还没有看到任何看起来像广泛使用的scala DAO层(对于SQL)
#4
1
If I were to choose an ORM I'd look into Squeryl (http://squeryl.org/). I've tried out the Lift Mapper and it works well with the Lift Webkit, but it's a little bit to integrated and have certain design choices I don't like.
如果我选择ORM,我会看看Squeryl(http://squeryl.org/)。我已经尝试过Lift Mapper,它与Lift Webkit配合得很好,但它有点集成并且有一些我不喜欢的设计选择。
#5
0
You might prefer ScalikeJDBC. Take a look at it.
您可能更喜欢ScalikeJDBC。看看吧。
https://github.com/seratch/scalikejdbc
https://github.com/seratch/scalikejdbc
It also has source code generator. Especially if you access the existing legacy database, it's much convenient.
它还有源代码生成器。特别是如果您访问现有的旧数据库,它会非常方便。
https://github.com/seratch/scalikejdbc-mapper-generator
https://github.com/seratch/scalikejdbc-mapper-generator