Thursday, 9 October 2008

Dealing with Databases in Erlang

Correction: Thanks to Brandon's comment below, there is also Erlang ODBC which comes with the OTP distribution. This is the 'official' gateway to the RDBMS world. I had a go at it in this post. There is also CouchDB from Apache, which is still in incubation.

Currently there are basically two ways to use database in Erlang - Mnesia and ErlyDB. There is also the prospect of edbc. But nothing is available yet from the project.

Mnesia is the native DBMS in Erlang. It is bundled with Erlang/OTP distribution and is written in Erlang as well. It was originally developed for telco switching applications by Ericsson. Therefore, it boasts a lot of non-functional features - in-memory database, distributed database, high performance (for read), making changes without downtime, etc. However, all these benefits are at the cost of sacrificing many of the basic functionality of a traditional RDBMS - such as referential integrity check, data type validation/check, normalisation support, triggers, stored procedures, etc.

ErlyDB is essentially Yariv's one-man effort. It's a code generator to generate the data access layer code in Erlang to work with RDBMS (and perhaps Mnesia). Currently supported RDBMS are MySQL and Postgress. It's primary use case was ErlyWeb from the same author. It looked promising. However, the whole ErlyWeb and ErlyDB/ErlySQL seem to have lost its momentum: The last ErlyWeb release was over a year ago; ErlyDB is no longer a project on its own right, therefore, no information on its releases; promised features from Yariv's blog have not eventuate after 1 to 2 years.

So given the database landscape in Erlang, the most viable approach is to use Mnesia if you don't mind the lack of database features and tools. I will give it a try by porting my prototype Address database into Mnesia.

2 comments:

Brandon said...

Have you tried the Erlang ODBC module?
http://www.erlang.org/doc/apps/odbc/index.html

Or the pgsql found here:
http://jungerl.sourceforge.net/

I am curious about database options in Erlang as well.

Romen said...

Thanks for the pointers Brandon.

I had a look at the links. Erlang ODBC sounds promising (how could I have missed that in the first place?!). I will give it a try after Mnesia. However, I am not a fan of ODBC for it is an old technology falling out of favor of even Microsoft and I had the impression of ODBC having bad performance and scalability (although my last commercial use of ODBC was almost 10 years ago).

I will give PGSql a miss as I've never had any use for Postgres and PGSql itself is less mature than ErlyDB.

cheers
romen