Skip to content

Commit

Permalink
Polish mnesia user guide wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaka27 committed Dec 15, 2024
1 parent 5674bfc commit a8ce0b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions lib/mnesia/doc/guides/mnesia_chap2.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ erDiagram
int number
}
Dept ||--|| Employee: Manager
Dept }|--|| Employee: Manager
Employee }|--|| Dept: At_dep
Employee }|--|{ Project: in_proj
```
Expand All @@ -142,8 +142,8 @@ The database model is as follows:
- There are three relationships between these entities:

1. A department is managed by an employee, hence the `manager` relationship.
1. An employee works at a department, hence the `at_dep` relationship.
1. Each employee works on a number of projects, hence the `in_proj`
2. An employee works at a department, hence the `at_dep` relationship.
3. Each employee works on a number of projects, hence the `in_proj`
relationship.

### Defining Structure and Content
Expand Down Expand Up @@ -177,7 +177,7 @@ This file defines the following structure for the example database:
```

The structure defines six tables in the database. In `Mnesia`, the function
[`mnesia:create_table(Name, ArgList)`](`mnesia:create_table/2`) creates tables.
[`mnesia:create_table(Name, Opts)`](`mnesia:create_table/2`) creates tables.
`Name` is the table name.

> #### Note {: .info }
Expand All @@ -188,7 +188,7 @@ The structure defines six tables in the database. In `Mnesia`, the function
For example, the table for employees is created with the function
`mnesia:create_table(employee, [{attributes, record_info(fields, employee)}])`.
The table name `employee` matches the name for records specified in `ArgList`.
The table name `employee` matches the name for records specified in `Opts`.
The expression `record_info(fields, RecordName)` is processed by the Erlang
preprocessor and evaluates to a list containing the names of the different
fields for a record.
Expand Down Expand Up @@ -285,8 +285,8 @@ ok
```

A set of tables is created. The function
[`mnesia:create_table(Name, ArgList)`](`mnesia:create_table/2`) creates the
required database tables. The options available with `ArgList` are explained in
[`mnesia:create_table(Name, Opts)`](`mnesia:create_table/2`) creates the
required database tables. The options available with `Opts` are explained in
[Create New Tables](mnesia_chap3.md#create_tables).

The function `company:init/0` creates the tables. Two tables are of type `bag`.
Expand Down Expand Up @@ -326,8 +326,8 @@ mk_projs(_, []) -> ok.
- The `insert_emp/3` arguments are as follows:

1. `Emp` is an employee record.
1. `DeptId` is the identity of the department where the employee works.
1. `ProjNames` is a list of the names of the projects where the employee
2. `DeptId` is the identity of the department where the employee works.
3. `ProjNames` is a list of the names of the projects where the employee
works.

The function `insert_emp/3` creates a Functional Object (Fun). `Fun` is passed
Expand Down Expand Up @@ -551,8 +551,8 @@ following function can be constructed to call from the shell:
```erlang
all_females() ->
F = fun() ->
Female = #employee{sex = female, name = '$1', _ = '_'},
mnesia:select(employee, [{Female, [], ['$1']}])
Female = #employee{sex = female, name = '$1', _ = '_'},
mnesia:select(employee, [{Female, [], ['$1']}])
end,
mnesia:transaction(F).
```
Expand Down Expand Up @@ -592,10 +592,10 @@ within a transaction. Consider the following function:
```erlang
females() ->
F = fun() ->
Q = qlc:q([E#employee.name || E <- mnesia:table(employee),
E#employee.sex == female]),
qlc:e(Q)
end,
Q = qlc:q([E#employee.name || E <- mnesia:table(employee),
E#employee.sex == female]),
qlc:e(Q)
end,
mnesia:transaction(F).
```

Expand Down Expand Up @@ -630,7 +630,7 @@ raise_females(Amount) ->
F = fun() ->
Q = qlc:q([E || E <- mnesia:table(employee),
E#employee.sex == female]),
Fs = qlc:e(Q),
Fs = qlc:e(Q),
over_write(Fs, Amount)
end,
mnesia:transaction(F).
Expand Down
20 changes: 10 additions & 10 deletions lib/mnesia/doc/guides/mnesia_chap3.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,28 +191,28 @@ enter the following commands:
gin % erl -sname a -mnesia dir '"/ldisc/scratch/Mnesia.company"'
```

1. On the node `b@skeppet`:
2. On the node `b@skeppet`:

```text
skeppet % erl -sname b -mnesia dir '"/ldisc/scratch/Mnesia.company"'
```

1. On one of the two nodes:
3. On one of the two nodes:

```erlang
(a@gin)1> mnesia:create_schema([a@gin, b@skeppet]).
```

1. The function [`mnesia:start()`](`mnesia:start/0`) is called on both nodes.
1. To initialize the database, execute the following code on one of the two
4. The function [`mnesia:start()`](`mnesia:start/0`) is called on both nodes.
5. To initialize the database, execute the following code on one of the two
nodes:

```erlang
dist_init() ->
mnesia:create_table(employee,
[{ram_copies, [a@gin, b@skeppet]},
{attributes, record_info(fields,
employee)}]),
employee)}]),
mnesia:create_table(dept,
[{ram_copies, [a@gin, b@skeppet]},
{attributes, record_info(fields, dept)}]),
Expand All @@ -222,7 +222,7 @@ dist_init() ->
mnesia:create_table(manager, [{type, bag},
{ram_copies, [a@gin, b@skeppet]},
{attributes, record_info(fields,
manager)}]),
manager)}]),
mnesia:create_table(at_dep,
[{ram_copies, [a@gin, b@skeppet]},
{attributes, record_info(fields, at_dep)}]),
Expand Down Expand Up @@ -324,7 +324,7 @@ information about the start failure, use command-line arguments

## Create Tables

The function [`mnesia:create_table(Name, ArgList)`](`mnesia:create_table/2`)
The function [`mnesia:create_table(Name, Opts)`](`mnesia:create_table/2`)
creates tables. When executing this function, it returns one of the following
responses:

Expand All @@ -335,7 +335,7 @@ The function arguments are as follows:

- `Name` is the name of the table. It is usually the same name as the name of
the records that constitute the table. For details, see `record_name`.
- `ArgList` is a list of `{Key,Value}` tuples. The following arguments are
- `Opts` is a list of `{Key,Value}` tuples. The following options are
valid:

- `{type, Type}`, where `Type` must be either of the atoms `set`,
Expand Down Expand Up @@ -406,8 +406,8 @@ The function arguments are as follows:
representation of the record.

- `{snmp, SnmpStruct}`. `SnmpStruct` is described in the
[SNMP](`e:snmp:index.html`) User's Guide. Basically, if this attribute is
present in `ArgList` of `mnesia:create_table/2`, the table is immediately
[SNMP](`e:snmp:index.html`) User's Guide. Basically, if this option is
present in `Opts` of `mnesia:create_table/2`, the table is immediately
accessible the SNMP.
It is easy to design applications that use SNMP to manipulate and control
Expand Down
4 changes: 2 additions & 2 deletions lib/mnesia/doc/guides/mnesia_chap4.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,13 @@ To check if your code is executed within a transaction, use the function
`mnesia:is_transaction/0`. It returns `true` when called inside a transaction
context, otherwise `false`.

`Mnesia` tables with storage type `RAM_copies` and `disc_copies` are implemented
`Mnesia` tables with storage type `ram_copies` and `disc_copies` are implemented
internally as `ets` tables. Applications can access the these tables directly.
This is only recommended if all options have been weighed and the possible
outcomes are understood. By passing the earlier mentioned "fun" to the function
[`mnesia:ets(Fun [, Args])`](`mnesia:ets/1`), it is performed but in a raw
context. The operations are performed directly on the local `ets` tables,
assuming that the local storage type is `RAM_copies` and that the table is not
assuming that the local storage type is `ram_copies` and that the table is not
replicated on other nodes.

Subscriptions are not triggered and no checkpoints are updated, but this
Expand Down

0 comments on commit a8ce0b2

Please sign in to comment.