Module db_mnesia

DB back-end using mnesia.

Copyright © 2013-2015 Zuse Institute Berlin,

Behaviours: db_backend_beh.

Authors: Tanguy Racinet.

Description

DB back-end using mnesia. Two keys K and L are considered equal if K == L yields true.

Data Types

db()

db() = atom()

entry()

entry() = db_backend_beh:entry()

key()

key() = db_backend_beh:key()

'$end_of_table' is not allowed as key() or else iterations won't work!

Function Index

close/1Closes the DB named DBName.
close_and_delete/1Closes and deletes the DB named DBName.
delete/2Deletes the tuple saved under Key and returns the new DB.
delete_mnesia_tables/1Close recursivly all mnesia tables in List.
foldl/3Is equivalent to ets:foldl(Fun, Acc0, DB).
foldl/4foldl/4 iterates over DB and applies Fun(Entry, AccIn) to every element encountered in Interval.
foldl/5foldl/5 iterates over DB and applies Fun(Entry, AccIn) to every element encountered in Interval.
foldl_unordered/3Works similar to foldl/3 but uses mnesia:foldl instead of our own implementation.
foldr/3Is equivalent to foldr(Fun, Acc0, DB).
foldr/4Is equivalent to foldr(DB, Fun, Acc0, Interval, get_load(DB)).
foldr/5Behaves like foldl/5 with the difference that it starts at the end of Interval and iterates towards the start of Interval.
get/2Returns the entry that corresponds to Key or {} if no such tuple exists.
get_load/1Returns the current load (i.e.
get_name/1Returns the name of the DB specified in new/1.
get_persisted_tables/0Gets a list of persisted tables.
is_available/0Checks for modules required for this DB backend.
mnesia_tables_of/1Return all the tables owned by PidGroup NOTE: only returns tables with names according to this regular expression: ^[^:]+:PidGroup(:.*)?$
new/1Creates new DB handle named DBName.
new/2Creates new DB handle named DBName with possibility to pass Options.
open/1Open a previously existing database assuming the database has been restored by the start of the mnesia application.
put/2Saves arbitrary tuple Entry or list of tuples Entries in DB DBName and returns the new DB.
start/0
supports_feature/1Returns true if the DB support a specific feature (e.g.
tab2list/1
traverse_table_and_show/1traverse table and print content.

Function Details

start/0

start() -> ok

traverse_table_and_show/1

traverse_table_and_show(Table_name :: nonempty_string()) -> ok

traverse table and print content

mnesia_tables_of/1

mnesia_tables_of(PidGroup :: pid_groups:groupname()) -> [atom()]

Return all the tables owned by PidGroup NOTE: only returns tables with names according to this regular expression: ^[^:]+:PidGroup(:.*)?$

get_persisted_tables/0

get_persisted_tables() -> [nonempty_string()]

Gets a list of persisted tables.

delete_mnesia_tables/1

delete_mnesia_tables(Tabs :: list()) -> ok

Close recursivly all mnesia tables in List

new/1

new(DBName :: nonempty_string()) -> db()

Creates new DB handle named DBName.

new/2

new(DBName :: nonempty_string(), Options :: [term()]) -> db()

Creates new DB handle named DBName with possibility to pass Options.

open/1

open(DBName :: nonempty_string()) -> db()

Open a previously existing database assuming the database has been restored by the start of the mnesia application.

close/1

close(DB :: db()) -> true

Closes the DB named DBName

close_and_delete/1

close_and_delete(DBName :: db()) -> true

Closes and deletes the DB named DBName

put/2

put(DBName :: db(), Entry :: entry() | [Entries :: entry()]) ->
       db()

Saves arbitrary tuple Entry or list of tuples Entries in DB DBName and returns the new DB. The key is expected to be the first element of Entry.

get/2

get(DBName :: db(), Key :: key()) -> entry() | {}

Returns the entry that corresponds to Key or {} if no such tuple exists.

delete/2

delete(DBName :: db(), Key :: key()) -> db()

Deletes the tuple saved under Key and returns the new DB. If such a tuple does not exists nothing is changed.

get_name/1

get_name(DB :: db()) -> nonempty_string()

Returns the name of the DB specified in new/1.

is_available/0

is_available() -> boolean() | [atom()]

Checks for modules required for this DB backend. Returns true if no modules are missing, or else a list of missing modules

supports_feature/1

supports_feature(Feature :: atom()) -> boolean()

Returns true if the DB support a specific feature (e.g. recovery), false otherwise.

get_load/1

get_load(DB :: db()) -> non_neg_integer()

Returns the current load (i.e. number of stored tuples) of the DB.

foldl/3

foldl(DB :: db(),
      Fun :: fun((Key :: key(), AccIn :: A) -> AccOut :: A),
      Acc0 :: A) ->
         Acc1 :: A

Is equivalent to ets:foldl(Fun, Acc0, DB).

foldl/4

foldl(DB :: db(),
      Fun :: fun((Key :: key(), AccIn :: A) -> AccOut :: A),
      Acc0 :: A,
      Interval :: db_backend_beh:interval()) ->
         Acc1 :: A

foldl/4 iterates over DB and applies Fun(Entry, AccIn) to every element encountered in Interval. On the first call AccIn == Acc0. The iteration only apply Fun to the elements inside the Interval.

foldl/5

foldl(DB :: db(),
      Fun :: fun((Key :: key(), A) -> A),
      A,
      Interval :: db_backend_beh:interval(),
      MaxNum :: non_neg_integer()) ->
         Acc1 :: A

foldl/5 iterates over DB and applies Fun(Entry, AccIn) to every element encountered in Interval. On the first call AccIn == Acc0. The iteration stops as soon as MaxNum elements have been encountered.

foldr/3

foldr(DB :: db(),
      Fun :: fun((Key :: key(), AccIn :: A) -> AccOut :: A),
      Acc0 :: A) ->
         Acc1 :: A

Is equivalent to foldr(Fun, Acc0, DB).

foldr/4

foldr(DB :: db(),
      Fun :: fun((Key :: key(), AccIn :: A) -> AccOut :: A),
      Acc0 :: A,
      Interval :: db_backend_beh:interval()) ->
         Acc1 :: A

Is equivalent to foldr(DB, Fun, Acc0, Interval, get_load(DB)).

foldr/5

foldr(DB :: db(),
      Fun :: fun((Key :: key(), AccIn :: A) -> AccOut :: A),
      Acc0 :: A,
      Interval :: db_backend_beh:interval(),
      MaxNum :: non_neg_integer()) ->
         Acc1 :: A

Behaves like foldl/5 with the difference that it starts at the end of Interval and iterates towards the start of Interval.

foldl_unordered/3

foldl_unordered(DB :: db(),
                Fun ::
                    fun((Entry :: entry(), AccIn :: A) ->
                            AccOut :: A),
                Acc0 :: A) ->
                   Acc1 :: A

Works similar to foldl/3 but uses mnesia:foldl instead of our own implementation. The order in which will be iterated over is unspecified, but using this fuction might be faster than foldl/3 if it does not matter.

tab2list/1

tab2list(Table_name :: db()) -> [Entries :: entry()]


Generated by EDoc, Aug 2 2016, 13:42:12.