renaming Mnesia/ to mnesia/
This commit is contained in:
parent
3c15d3a370
commit
f59d59814a
4 changed files with 68 additions and 0 deletions
BIN
mnesia/.gamedb.erl.swp
Normal file
BIN
mnesia/.gamedb.erl.swp
Normal file
Binary file not shown.
50
mnesia/gamedb.erl
Normal file
50
mnesia/gamedb.erl
Normal file
|
@ -0,0 +1,50 @@
|
|||
%%%%----------------------------------------------------
|
||||
%%% @author Mattias Pettersson <mattiaspgames@gmail.com>
|
||||
%%% @copyright 2011 Mattias Pettersson
|
||||
%%% @doc Database for runtime game variable storage.
|
||||
%%% @end
|
||||
|
||||
Test Mnesia
|
||||
-module(gamedb).
|
||||
-import(mnesia).
|
||||
-export([init/0,insert_player/1,example_player/0,read_player/1,test_player/0]).
|
||||
-include("gamedb.hrl").
|
||||
|
||||
%%-----------------------------------------------------
|
||||
%% Creation
|
||||
%%-----------------------------------------------------
|
||||
init() ->
|
||||
mnesia:create_table(player, [{attributes, record_info(fields, player)}]).
|
||||
|
||||
%%-----------------------------------------------------
|
||||
%% Test
|
||||
%%-----------------------------------------------------
|
||||
test_player() ->
|
||||
insert_player(example_player()),
|
||||
read_player(0001).
|
||||
|
||||
example_player() ->
|
||||
#player{id = 0001,
|
||||
name = "Tux"}.
|
||||
|
||||
%%-----------------------------------------------------
|
||||
%% Insertions
|
||||
%%-----------------------------------------------------
|
||||
insert_player(Player) ->
|
||||
Fun = fun() ->
|
||||
mnesia:write(Player)
|
||||
end,
|
||||
mnesia:transaction(Fun).
|
||||
|
||||
|
||||
%%-----------------------------------------------------
|
||||
%% Querries
|
||||
%%-----------------------------------------------------
|
||||
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}
|
||||
|
Reference in a new issue