summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-07-12 17:48:41 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-07-12 17:48:41 +0200
commita132188ccc244a6d802bd1c32fbf196d4cb53cbd (patch)
treebd54e576ea8164d3efc801d9c56420218a74e591 /src/db
parentb853df7a1c3efef6b84b90fe8c492611564f8b53 (diff)
Got it to load the map (full of "error" tiles).
Diffstat (limited to 'src/db')
-rw-r--r--src/db/db_node.erl6
-rw-r--r--src/db/struct/db_model.erl19
2 files changed, 17 insertions, 8 deletions
diff --git a/src/db/db_node.erl b/src/db/db_node.erl
index be295c6..aaf6ae3 100644
--- a/src/db/db_node.erl
+++ b/src/db/db_node.erl
@@ -25,7 +25,9 @@ wait_for_stop () ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec start () -> 'ok'.
start () ->
- DB = db_model:new(battle_db, "/tmp/battle_db.mnesia", []),
- db_model:start(DB),
+ Mnesia = db_model:new("/tmp/to_db_node.mnesia", []),
+ db_model:start(Mnesia),
+ db_model:add_db(battle_db, Mnesia),
+ db_model:add_db(map_db, Mnesia),
wait_for_stop(),
ok.
diff --git a/src/db/struct/db_model.erl b/src/db/struct/db_model.erl
index e6ec721..2cd58d4 100644
--- a/src/db/struct/db_model.erl
+++ b/src/db/struct/db_model.erl
@@ -8,7 +8,6 @@
(
db_model,
{
- name :: atom(),
store_file :: string(),
neighbors :: list(node())
}
@@ -24,7 +23,8 @@
-export
(
[
- new/3,
+ new/2,
+ add_db/2,
start/1
]
).
@@ -36,27 +36,34 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec new (atom(), string(), list(node())) -> type().
-new (DBName, StorageFile, Neighbors) ->
+-spec new (string(), list(node())) -> type().
+new (StorageFile, Neighbors) ->
#db_model
{
- name = DBName,
store_file = StorageFile,
neighbors = Neighbors
}.
-spec start(type()) -> 'ok'.
start (Model) ->
- DBName = Model#db_model.name,
StorageFile = Model#db_model.store_file,
Neighbors = Model#db_model.neighbors,
ok = application:set_env(mnesia, dir, StorageFile),
+
case mnesia:create_schema([node()|Neighbors]) of
{error, {Name, {already_exists, Name}}} -> ok;
ok -> ok
end,
+
ok = mnesia:start(),
+
+ ok.
+
+-spec add_db (atom(), type()) -> 'ok'.
+add_db (DBName, Model) ->
+ Neighbors = Model#db_model.neighbors,
+
mnesia:create_table
(
DBName,