To contents Next section

14.10.1 The database

The db object is the main Yabu database object. It is used to open the database and it can create table objects.

A Yabu database can operate in two basic modes:

Compressed databases opened without compress mode enabled will be handled correctly in both modes, provided that the Gz module is available. However, new records will no longer be compressed in write mode.

METHOD
Yabu.db.create - Open a Yabu database

SYNTAX
void create(string directory, string mode);

DESCRIPTION
Create takes two arguments:

  1. directory is a string specifying the directory where Yabu will store its files. Yabu will create the directory if it does not exist, provided Yabu is opened in write and create mode (see below).

  2. mode is a string specifying the mode in which Yabu will operate. There are five switches available:

NOTE
It is very important not to open the same a database more than once at a time. Otherwise there will be conflicts and most likely strange failures and unpredictable behaviours. Yabu does not check weather a database is already open or not.

EXAMPLE
// Open a database in create/write/transaction mode.
object db = Yabu.db("my.database", "cwt");

// Open a database in read mode.
object db = Yabu.db("my.database", "r");

// Open a database in create/write/compress mode.
object db = Yabu.db("my.database", "cwC");

SEE ALSO
Yabu.db->table, Yabu.db->list_tables, Yabu.db->sync and Yabu.db->purge

METHOD
Yabu.db.table - Open a table

SYNTAX
object(table) table(string table_name);
object(table) `[](string table_name);

DESCRIPTION
This method opens a table with table_name. If the table does not exist, it will be created. A table object will be returned.

SEE ALSO
Yabu.db->list_tables, Yabu.db->sync and Yabu.db->purge

METHOD
Yabu.db.list_tables - List all tables

SYNTAX
array(string) list_tables();
array(string) _indices();

DESCRIPTION
This method lists all available tables.

SEE ALSO
Yabu.db->table, Yabu.db->sync, Yabu.db->purge and Yabu.db->_values

METHOD
Yabu.db._values - Get all tables

SYNTAX
array(Yabu.table) _values();

DESCRIPTION
This method returns all available tables.

SEE ALSO
Yabu.db->table, Yabu.db->sync, Yabu.db->purge and Yabu.db->_indices

METHOD
Yabu.db.sync - Synchronize database

SYNTAX
void sync();

DESCRIPTION
This method synchronizes the database on disk. Yabu stores some information about the database in memory for performance reasons. Syncing is recommended when one wants the information on disk to be updated with the current information in memory.

SEE ALSO
Yabu.db->table, Yabu.db->list_tables and Yabu.db->purge

METHOD
Yabu.db.purge - Delete database

SYNTAX
void purge();

DESCRIPTION
This method deletes the whole database and all database files stored on disk.

SEE ALSO
Yabu.db->table, Yabu.db->list_tables and Yabu.db->sync


To contents Next section