Module ce_db

Database library.

Description

Database library.

This library complements mnesia. It uses mnesia to access the databases, using a simpler (but less efficient) interface.

Function Index

all_records/1Returns a list of all the records in the table.
connect/3Connects to a database hosted on a remote node.
create/1Creates a schema with the given tables if one does not already exist.
delete/2Deletes a single record from a data table.
export/3Exports a table to a disk file.
fold/2Equivalent to fold(Table, Fun, []).
fold/3Folds an entire table, calling fun/2 for each record.
foreach/2Traverses an entire table, calling fun/2 for each record.
import/3Imports a disk file into a table.
probe_db_nodes/1Used by connect/3 to probe the remote node.
read/2Reads the record with a matching primary key from the table.
read/3Reads all records with a matching secondary key from the table.
update_counter/2Increments an integer value in a table.
write/2Inserts or updates a single record in a data table.

Function Details

all_records/1

all_records(Table::table()) -> [record()]

Returns a list of all the records in the table. Complements mnesia:all_keys/1. Note that this is not a particularly scaleable solution.

connect/3

connect(Master::node(), RamTables::[table()], DiscTables::[table()]) -> ok | {error, Reason}

Connects to a database hosted on a remote node. This is useful for connecting slave nodes to a master after the database has been created on the master node using ce_db:create/1. This connection needs only be done once, at install time, not each time the application is started. If the connection is successful, local copies of the given tables from the master node will be made in RAM and/or on disc on the local node.

create/1

create(Tables::[tabledef()]) -> ok | {error, Reason}

Creates a schema with the given tables if one does not already exist. This schema is created on the local node only. If a schema already exists on the local node, the given tables are added to it. See the mnesia documentation for an explanation of the tabledef() structure.

delete/2

delete(Table::table(), Key::key()) -> true | false

Deletes a single record from a data table.

export/3

export(IoDevice::io_device(), Table::table(), FieldNames::[atom()]) -> ok | {error, Reason}

Exports a table to a disk file. For simplicity, FieldNames should be the output of record_info(fields, Table)

fold/2

fold(Table::table(), Fun::'fun'()) -> {ok, term()} | {error, Reason}

Equivalent to fold(Table, Fun, []).

fold/3

fold(Table::table(), Fun::'fun'(), Acc::term()) -> {ok, term()} | {error, Reason}

Folds an entire table, calling fun/2 for each record.

foreach/2

foreach(Table::table(), Fun::'fun'()) -> true | false

Traverses an entire table, calling fun/2 for each record. The result of the evaluation of the fun is discarded.

import/3

import(IoDevice::io_device(), Table::table(), FieldNames::[atom()]) -> ok | {error, Reason}

Imports a disk file into a table. For simplicity, FieldNames should be the output of record_info(fields, Table)

probe_db_nodes/1

probe_db_nodes(ForPid::pid()) -> ok

Used by connect/3 to probe the remote node. This function is invoked on the remote (master) node, and sends a message back to the local (slave) node.

read/2

read(Table::table(), Key::key()) -> record() | nil

Reads the record with a matching primary key from the table. Returns nil if no record was found.

read/3

read(Table::table(), Index::index(), Key::key()) -> [record()]

Reads all records with a matching secondary key from the table. Returns an empty list if none were found.

update_counter/2

update_counter(Table::table(), Key::key()) -> {ok, integer()} | {error, Reason}

Increments an integer value in a table. Complements mnesia:dirty_update_counter/2. This function is much less efficient, but it is cleaner.

write/2

write(Table::table(), Object::record()) -> true | false

Inserts or updates a single record in a data table.


Generated by EDoc, Dec 25 2007, 02:37:19.