I am developing an Erlang application that requires a lot of DB writing. In my scheme, in addition to the primary key, there is another attribute that enforces a unique constraint.
Say I have an identifier, a unique_field_field and some other fields. I need to update a row in the database corresponding to a unique identifier, given that no other row should already have the value of the unique_constraint_field value that I am going to update.
Due to the large volume of updates (each update will only affect 1 line), I need to execute (also requiring low latency). I rely on the primary key and the unique restriction on this attribute to catch duplication, not the update statement using a subquery. This allows me to update in one request (which happens in 95% of cases), and in the remaining 5% I can catch an exception to take the necessary actions regarding the primary key or violation of a unique attribute.
I am currently using the mysql ODBC driver. However, the driver returns a very general error message for ANY error. Although my prototype is working fine now when I assume that some kind of mistake is a key violation, this model is obviously pretty much wrong. I can not find another decent driver / way to connect to mysql from erlang.
I'm thinking of switching to Mnesia (a memory-only mode for my speed requirements), since Erlang and Mnesia combine so easily. However, I see that Mnesia does not have any unique key constraints that I can use to perform my database update in a single query.
I need suggestions on how best to implement this requirement from within Erlang. Is there a way to do conditional updates in Mnesia? Or is there any other high-speed DB alternative that I should look at? Any help / understanding is greatly appreciated.
source share