可擴展的Scala ORM框架:SORM
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()
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!