Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Mapper or Record in Lift?

I would like to understand what are the use cases, advantages and inconveniences of choosing to use Record , Mapper or even both, in a Liftweb application.

This question came up when I tried to:

  • create a tree like structure for the model classes
  • create a similar tree like structure for rendering of the classes in a page
  • ensure different classes in the tree can be in different states at the same time. One is in the EDIT or CREATE state and the other in the VISUALIZE state for example.
  • model classes can be created, read or saved to a RESTful Web Service that is already functioning.

I'm putting the use cases here just for the record. You can answer in a more general way.

like image 804
Alexandre Martins Avatar asked Jul 03 '11 17:07

Alexandre Martins


2 Answers

Mapper has been part of Lift before Lift was Lift. It's a simple "Active Record" style bridge between the database and Scala. I built Mapper based on ideas outlined here: http://web.archive.org/web/20070303054927/http://blog.lostlake.org/index.php?/archives/19-Keeping-the-meaning-with-the-bytes.html

Mapper is intimately tied to JDBC and thus relational databases. Mapper has a reasonable mechanism for building simple queries, but for complex stuff one has to hand-write SQL.

Mapper is solid but crufty.

Record is a more generic abstraction between backing store and Scala. It has weaker implementations of the ideas outlined in "Keeping the meaning with the Bytes"... and very few people notice or care.

There are Record implementations for MongoDB, CouchDB, Squeryl and other storage mechanisms. Writing a new back-end is a few days of work.

Record has a lot of "anomalies" and each back end has its own quirks. The current Record owner has embarked on a wholesale refactoring of Record.

I do not think either Record or Mapper will give you tree-like structures "out of the box" unless you're using the MongoDB backend and in that case, your tree structures will be based on JSON documents rather than relations.

like image 138
David Pollak Avatar answered Sep 29 '22 10:09

David Pollak


Well, the Mapper and Record libraries are only different abstractions for the database access in Lift applications. Record is the newer one and is considered to substitute Mapper one day. At the moment Record supports NoSQL databases like CouchDB and MongoDB. If your data model fits into the NoSQL world, try Record. Otherwise you can use Mapper in connection with a typical relational database.

I hopefully mentioned some interesting points for you.

like image 33
Felix Avatar answered Sep 29 '22 10:09

Felix