可扩展的Scala ORM框架:SORM

jopen 11年前

SORM是一个Scala的ORM框架,旨在消除样板代码和解决可扩展性问题,通过高层次的抽象和函数式编程风格。

特性:

  • 完全抽象的关系概念. You work with case classes, collections and other standard Scala data types instead of tables, rows, foreign keys and relations.
  • 从持久层完全分离的域模型. There are no annotations, special types or any other dependencies on persistence layer present in model declaration. This house is clear!
  • 一个直观和集中的连接无关的API. No tangled implicit constructions polluting your namespace and functionality scattered across multiple components. No manual management of connections.
  • Concurrency. A single SORM instance can safely be used across multiple threads and seamlessly integrates into actor-based concurrent systems, like Akka.
  • 集成连接池. Scalable just by setting a “poolSize” parameter.
  • 自动生成数据库结构
下面是一个完整的例子:
// Declare a model:  case class Artist( name : String, genres : Set[Genre] )  case class Genre( name : String )     // Initialize SORM, automatically generating schema:  import sorm._  object Db extends Instance(    entities = Set( Entity[Artist](), Entity[Genre]() ),    url = "jdbc:h2:mem:test"  )    // Store values in the db:  val metal = Db.save( Genre("Metal") )  val rock = Db.save( Genre("Rock") )  Db.save( Artist("Metallica", Set(metal, rock) ) )  Db.save( Artist("Dire Straits", Set(rock) ) )    // Retrieve values from the db:  // Option[Artist with Persisted]:  val metallica = Db.query[Artist].whereEqual("name", "Metallica").fetchOne()   // Stream[Artist with Persisted]:  val rockArtists = Db.query[Artist].whereEqual("genres.item.name", "Rock").fetch() 

项目主页:http://www.open-open.com/lib/view/home/1371526720703