Étude 10-2: Using Mnesia
I have good news and bad news. First, the bad news. Mnesia is not a relational detabase management system. If you try to use a query list comprehension to join three tables, Erlang will complain that joins with more than two tables are not efficient.
Now, the good news. While trying to find a way around this, I discovered something about query list comprehensions that is really pretty neat, and I’m happy to share it with you.
In this étude, you will use add a table of customer names and use Mnesia query list comprehensions to join data from those tables when producing a summary.
Part One
You will need to add a record for customers to phone_records.hrl
. Its fields
will be:
- Phone Number (this is the key)
- Customer’s last name
- Customer’s first name
- Customer’s middle name
- Rate paid per minute (float)
Again, you may name the record whatever you wish, and you may use any field names you wish.
Part Two
In a module named phone_mnesia
,
create the Mnesia tables for the two files. The function
that does this will be named setup/2
, and its arguments will be the
names of the file containing the data.
Use the phone call data from Étude 10-1, and
use this data for the customers. Put it in a file named
customer_data.csv
or whatever other name you wish.
213-555-0172,Nakamura,Noriko,,0.12 301-555-0433,Ekberg,Erik,Engvald,0.07 415-555-7871,Alvarez,Alberto,Agulto,0.15 650-555-3326,Girard,Georges,Gaston,0.10 729-555-8855,Tran,Truong,Thai,0.09 838-555-1099,Smith,Samuel,Steven,0.10 ...
Get Études for Erlang 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.