WeBWorK::DB - interface with the WeBWorK databases.
my $db = WeBWorK::DB->new($ce);
my @userIDs = $db->listUsers();
my $Sam = $db->{user}->{record}->new();
$Sam->user_id("sammy");
$Sam->first_name("Sam");
$Sam->last_name("Hathaway");
# etc.
$db->addUser($User);
my $Dennis = $db->getUser("dennis");
$Dennis->status("C");
$db->putUser->($Dennis);
$db->deleteUser("sammy");
WeBWorK::DB provides a database interface. Access and modification functions are provided for each logical table used by the webwork system. The particular schema, record class, and additional parameters are specified by the hash return by the DBLayout::databaseLayout
method.
The new database system uses a three-tier architecture to insulate each layer from the adjacent layers.
The top layer of the architecture is the DB module. It provides the methods listed below, and uses schema modules (via tables) to implement those methods.
/ new* list* exists* add* get* get*s put* delete* \ <- api
+------------------------------------------------------------------+
| DB |
+------------------------------------------------------------------+
\ password permission key user set set_user problem problem_user / <- tables
The middle layer of the architecture is provided by one or more schema modules. They are called "schema" modules because they control the structure of the data for a table.
The schema modules provide an API that matches the requirements of the DB layer, on a per-table basis.
The Database
module implements a DBI connection handle. It provides physical access to the database.
In the database layout, each table is assigned a record class, used for passing complete records to and from the database. The default record classes are subclasses of the WeBWorK::DB::Record class, and are named as follows: User, Password, PermissionLevel, Key, Set, UserSet, Problem, UserProblem. In the following documentation, a reference to the record class for a table means the record class currently defined for that table in the database layout.
my $db = WeBWorK::DB->new($ce)
The new
method creates a DB object, connects to the database via the Database
module, and brings up the underlying schema structure according to the hash referenced in the database layout. A course environment object is the only required argument (as it is used to construct the database layout).
For each table defined in the database layout, new
loads the record and schema modules.