Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord for Erlang

I am continuing to delve into Erlang. I am thinking of starting my next web project using Erlang, and at this stage the only thing I will really miss from Ruby on Rails is ActiveRecord.

Is there a good alternative technology for Erlang?

Update: The closest I have come to a solution is to ErlyDB, a component of ErlyWeb.

ErlyDB is a database abstraction layer generator for Erlang. ErlyDB combines database metadata and user-provided metadata to generate functions that let you perform common data access operations in an intuitive manner. It also provides a single API for working with different database engines (although currently, only MySQL is supported), letting you write portable data access code.

like image 498
Toby Hede Avatar asked Aug 15 '09 02:08

Toby Hede


4 Answers

Well, the major advantages of ActiveRecord (as I see it) are:

  1. You can persist your objects in a relational database nearly transparently.
  2. You can search the database by any attribute of your objects.
  3. You can validate objects when persisting them.
  4. You can have callbacks on deleting, updating, or inserting objects.

With Mnesia:

  1. You can persist any Erlang data absolutely transparently.
  2. Using pattern matching, you can search the database by any attribute of your data or their combination.
  3. QLC gives you a nice query interface for cases when pattern matching isn't enough.

No solutions for validating and callbacks, however...

So, what else do you have in ActiveRecord that is lacking in Mnesia?

like image 74
Alexey Romanov Avatar answered Oct 23 '22 03:10

Alexey Romanov


I don't think there really is at the time of this writing. That may be because the kinds of systems being written in erlang and the type of people writing them don't really call for Relational Databases. I see much more code using mnesia, CouchDB, Tokyo Cabinet and other such alternative database technologies.

That's not to say someone might not want to create something like active record. It's just hasn't really been a need yet. Maybe you will be the first? :-)

like image 41
Jeremy Wall Avatar answered Oct 23 '22 05:10

Jeremy Wall


You might be interested in Chicago Boss's "BossRecords":

http://www.chicagoboss.org/api-record.html

They are quite explicitly modeled on the Active Record pattern, and use a lot of compiler magic to make the syntax squeaky clean. BossRecords support save/validate as well as has_many/belongs_to associations. Attributes in your data model are made available through generated functions (e.g. "Employee:first_name()").

like image 40
Emiller Avatar answered Oct 23 '22 03:10

Emiller


Some googling reveals libs / clients / wrappers for Couchdb described "ActiveRecord like libraries like CouchFoo", and advise to steer clear:

http://upstream-berlin.com/2009/03/31/the-case-of-activerecord-vs-couchdb/

http://debasishg.blogspot.com/2009/04/framework-inertia-couchdb-and-case-of.html#

as to your comment on "not suited for web apps yet", I think the pieces are there: mochiweb, couch, yaws, nitrogen, erlyweb. There's some powerful tools, very different paradigm, certainly, from rails, django and PHP.

like image 45
Gene T Avatar answered Oct 23 '22 03:10

Gene T