Circumflex ORM

Circumflex ORM is an Object-Relational Mapping (ORM) framework for creating concise and efficient data-centric applications with elegant DSL.

The term «Object-Relational Mapping» refers to the technique of mapping a data representation from an object model to a relational data model. ORM tools may significantly speed up development by eliminating boilerplates for common CRUD operations, making applications more portable by incapsulating vendor-specific SQL dialects, providing object-oriented API for querying, allowing transparent navigation between object associations and much more.

The data definition DSL and querying API of Circumflex ORM closely resemble SQL — native language of modern databases.

Feature list includes:

Here's a simple example of fictional domain model:

class Country extends Record[String, Country] {
  val code = "code".VARCHAR(2).NOT_NULL.DEFAULT("'ch'")
  val name = "name".TEXT.NOT_NULL

  def cities = inverseMany(City.country)
  def relation = Country
  def PRIMARY_KEY = code
}

object Country extends Country with Table[String, Country]

class City extends Record[Long, City] with SequenceGenerator[Long, City] {
  val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
  val name = "name".TEXT
  val country = "country_code".TEXT.NOT_NULL
          .REFERENCES(Country)
          .ON_DELETE(CASCADE)
          .ON_UPDATE(CASCADE)

  def relation = City
  def PRIMARY_KEY = id
}

object City extends City with Table[Long, City]

And here's a snippet which shows various querying options:

// Prepare the relations that will participate in queries:
val ci = City AS "ci"
val co = Country AS "co"
// Select all cities of Switzerland, return Seq[City]:
SELECT (ci.*) FROM (ci JOIN co) WHERE (co.code LIKE "ch") ORDER_BY (ci.name ASC) list
// Select countries and count their cities, return Seq[(Option[Country], Option[Long])]:
SELECT (co.* -> COUNT(ci.id)) FROM (co JOIN ci) GROUP_BY (co.*) list
// Select countries with corresponding cities, return a sequence of alias maps:
SELECT (co.* AS "country", ci.* AS "city") FROM (co JOIN ci) list