Storing Complex Data in Tables

One of the disadvantages of using a conventional DBMS is that there are a limited number of data types you can store in a table column. You can store an integer, a string, a float, and so on. But if you want to store a complex object, then you’re in trouble. So, for example, if you’re a Java programmer, storing a Java object in a SQL database is pretty messy.

Mnesia is designed to store Erlang data structures. In fact, you can store any Erlang data structure you want in an Mnesia table.

To illustrate this, we’ll suppose that a number of architects want to store their designs in an Mnesia database. To start with, we must define a record to represent their designs.

test_mnesia.erl
 
-record​(design, {id, plan}). ...

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.