Last active
July 30, 2019 17:20
-
-
Save xtpor/da869c8766ea9af6e781180cffa75a6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule UserUtil do | |
def list do | |
{:atomic, records} = | |
:mnesia.transaction(fn -> | |
:mnesia.match_object({:user_info, :_, :_}) | |
end) | |
Enum.map(records, fn {:user_info, username, _password} -> username end) | |
end | |
def delete(username) do | |
{:atomic, _} = | |
:mnesia.transaction(fn -> | |
# First delete the user information | |
:mnesia.delete({:user_info, username}) | |
# Also delete the save data | |
:mnesia.match_object({:user_savedata, {username, :_}, :_}) | |
|> Enum.each(fn {:user_savedata, key, _} -> | |
:mnesia.delete({:user_savedata, key}) | |
end) | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment