Added support for Mnesia. See gamedb_usage.txt for further instructions.
This commit is contained in:
parent
265f7242a0
commit
0590fa6ca1
6 changed files with 49 additions and 0 deletions
31
Mnesia/gamedb.erl
Normal file
31
Mnesia/gamedb.erl
Normal file
|
@ -0,0 +1,31 @@
|
|||
%Test Mnesia
|
||||
-module(gamedb).
|
||||
-import(mnesia).
|
||||
-export([init/0,insert_player/1,example_player/0,read_player/1,test_player/0]).
|
||||
-include("gamedb.hrl").
|
||||
|
||||
init() ->
|
||||
mnesia:create_table(player, [{attributes, record_info(fields, player)}]).
|
||||
|
||||
test_player() ->
|
||||
insert_player(example_player()),
|
||||
read_player(0001).
|
||||
|
||||
insert_player(Player) ->
|
||||
Fun = fun() ->
|
||||
mnesia:write(Player)
|
||||
end,
|
||||
mnesia:transaction(Fun).
|
||||
|
||||
example_player() ->
|
||||
#player{id = 0001,
|
||||
name = "Tux"}.
|
||||
|
||||
read_player(Player_Key) ->
|
||||
Fun = fun() ->
|
||||
[P] = mnesia:read(player, Player_Key),
|
||||
Name = P#player.name,
|
||||
io:format("Player name: ~s~n",[Name])
|
||||
end,
|
||||
mnesia:transaction(Fun).
|
||||
|
6
Mnesia/gamedb.hrl
Normal file
6
Mnesia/gamedb.hrl
Normal file
|
@ -0,0 +1,6 @@
|
|||
%% gamedb.hrl
|
||||
|
||||
-record(player, {id, name}).
|
||||
|
||||
|
||||
|
12
Mnesia/gamedb_usage.txt
Normal file
12
Mnesia/gamedb_usage.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
1. From terminal: erl -mnesia dir '"/home/user/dir/to/GGS/GameDB.Player"'
|
||||
2. mnesia:create_schema([node()]).
|
||||
3. mnesia:start().
|
||||
4. c(gamedb).
|
||||
5. gamedb:init().
|
||||
6. mnesia:info().
|
||||
7. gamedb:test_player().
|
||||
|
||||
Last output should be:
|
||||
Player name: Tux
|
||||
{atomic,ok}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in a new issue