Charlie
Charlie

Reputation: 4329

Erlang- How to use Mnesia without records

From what I understand so far, Erlang records are tuples:

#myRecord{a="a", b="b"} = {myRecord, "a", "b"}

With this in mind, the following works:

mnesia:create_table({ attributes, [name, age] })
mnesia:activity(transaction, fun() -> mnesia:write(users, { user, "Charlie", "Unknow" }, write)

But how would I retrieve this entry? Most of the Mnesia examples online use records to store and access table rows.

Upvotes: 3

Views: 238

Answers (1)

Charlie
Charlie

Reputation: 4329

@Zeiss - You're right. mnesia:read/2 works. The problem was in me trying to use:

:mnesia.transaction(fn -> :mnesia.read(Users, b) end)

Instead of:

:mnesia.transaction(fn -> :mnesia.read(Users, "b") end)

Undoubtedly an elementary mistake. Hope the answer helps out anyone else who runs into the same (or similar...) issue.

Upvotes: 3

Related Questions