I am about to start my first project in the Lift framework and I have to decide which persistence library to choose. I am about to use relational backend so both Mapper and Record may come in play.
In case of Mapper - the thing I miss the most is the ability to control the queries being sent to the RDBMS - especially when it comes to more complicated queries which would be solved by joins, aggregation etc in SQL. Take the following example - let's have following two entities:
class BaseProduct extends LongKeyedMapper[BaseProduct] with IdPK {
// some fields
}
object BaseProduct extends BaseProduct with LongKeyedMetaMapper[BaseProduct]
class MyProduct extends LongKeyedMapper[MyProduct] with IdPK {
// some fields
object base extends MappedLongForeignKey(this, BaseProduct)
}
object MyProduct extends MyProduct with LongKeyedMetaMapper[MyProduct]
Where MyProduct
is one of the specialization of the BaseProduct
entity. There is obviously a one-to-one relation between these entities. However the best possibility I've come up with to query for the exact MyProduct
together with its BaseProduct
was a query like this:
MyProduct.findAll(PreCache(MyProduct.base))
Which issues two queries (moreover I am afraid I am not able to control which fields of the MyProduct
entity I want to select.
Enough bad for the Mapper library. My main concern about the Record/Squeryl API is the fact that it lacks all those Proto
-classes that are present around the Mapper API. Is there something close to the functionality of these classes for the Record? Is it possible to access database specific features in Squeryl (eg. geometrical queries in PostgreSQL)?
Are there any other pros and cons for either of these layers? Or is there any other abstraction layer which would deserve attention if I want to have decent typesafe encapsulation of the communication with the database and which would provide decent control over the queries (I was used to issuing queries directly using the PDO layer in PHP - I don't want such a direct querying interface but some possibility of having control over queries would be great) Integration with Lift framework is definitely an advantage.
Thank you!