Class::AutoDB::Collection - Schema information for one collection
This is a helper class for Class::AutoDB::Registry which represents the schema information for one collection.
use Class::AutoDB::Registration; use Class::AutoDB::Collection; my $registration=new Class::AutoDB::Registration (-class=>'Person', -collection=>'Person', -keys=>qq(name string, dob integer, significant_other object, friends list(object)), -transients=>[qw(age)], -auto_gets=>[qw(significant_other)]); my $collection=new Class::AutoDB::Collection (-name=>'Person',-register=>$registration); # Get the object's attributes my $name=$collection->name; my $keys=$collection->keys; # hash of key=>type pairs my $tables=$collection->tables; # Class::AutoDB::Table objects # that implement this collection my @sql=$collection->schema; # SQL statements to create collection my @sql=$collection->schema('create'); # same as above my @sql=$collection->schema('drop'); # SQL statements to drop collection my @sql=$collection->schema('alter',$diff); # SQL statements to alter collection # ($diff is CollectionDiff object)
This class represents processed registration information for one collection. Registrations are fed into the class via the 'register' method which combines the information to obtain a single hash of key=>type pairs. It makes sure that if the same key is registered multiple times, it has the same type each time. It further processes the information to determine the database tables needed to implement the collection, and the SQL statements needed to create, and drop those tables. It also has the ability to compare its current state to a Class::AutoDB::CollectionDiff object and generate the SQL statements needed to alter the current schema the new one.
This class does not talk to the database.
Name |
Description |
Priority/When |
---|---|---|
Schema alter |
schema('alter') included for completeness, but probably doesn't produce the correct SQL, and seems not to be used. Should fix or trash. |
Wish-list |
Title |
new |
|
Usage |
my $collection=new Class::AutoDB::Collection (-name=>'Person', -register=>$registration); |
|
Function |
Constructor. |
|
Args |
-name |
Name of collection being registered |
-register |
One Class::AutoDB::Registration object or an ARRAY ref of same for this collection |
|
Returns |
Collection object |
These are methods for getting and setting the values of simple attributes. Methods have the same name as the attribute. Some of these should be read-only (more precisely, should only be written by code internal to the object), but this is not enforced.
To get the value of attribute xxx, just say
$xxx=$object->xxx;
To set an attribute, say
$object->xxx($new_value);
To clear it, say
$object->xxx(undef);
Attribute |
name |
Function |
Collection name |
Access |
Read-only |
Title |
register |
|
Usage |
$collection->register($registration) |
|
$collection->register($registration1,$registration2) |
||
$collection->register($registrations) |
||
Function |
Set registration objects for this collection. |
|
Args |
$registration |
One or more Class:AutoDB::Registration objects |
$registrations |
ARRAY ref of Class:AutoDB::Registration objects |
|
Returns |
Nothing |
Title |
merge |
|
Usage |
$collection->merge($diff) |
|
Function |
Add search keys to collection as specified by diff. |
|
Args |
$diff |
Class:AutoDB::CollectionDiff object comparing this collection to new on |
Returns |
Nothing |
Title |
keys |
|
Usage |
my %keys=$collection->keys |
|
my $keys=$collection->keys |
||
my %keys=$collection->keys($keys) |
||
my $keys=$collection->keys($keys) |
||
Function |
Get search keys for this collection. Used internally to set keys, but external programs should not attempt this as the keys are computed from the registrations. |
|
Args |
$keys |
Search keys for collection. HASH ref of key=>type pairs |
Returns |
HASH or HASH ref depending on context |
Title |
tables |
|
Usage |
my @tables=$collection->tables |
|
my $tables=$collection->tables |
||
my @tables=$collection->tables($tables) |
||
my $collections=$table->tables($tables) |
||
Function |
Get Class::AutoDB:Table objects for this collection. Used internally to set the tables, but external programs should not attempt this as the tables are computed from the registrations. |
|
Args |
$tables |
ARRAY ref of Class::AutoDB:Table objects |
Returns |
ARRAY or ARRAY ref depending on context |
Title |
put |
|
Usage |
$collection->put($object) |
|
Function |
Returns SQL statements needed to store the object in the tables that implement the collection. Does not touch the database |
|
Args |
$object |
Object to be stored. |
Returns |
ARRAY or ARRAY ref depending on context. Each element of the results is a single SQL statement as a string. |
Title |
create |
|
Usage |
$collection->create |
|
Function |
Returns SQL statements needed to create the tables that implement the collection. Does not touch the database |
|
Args |
none |
|
Returns |
ARRAY or ARRAY ref depending on context. Each element of the results is a single SQL statement as a string. |
Title |
drop |
|
Usage |
$collection->drop |
|
Function |
Returns SQL statements needed to drop the tables that implement the collection. Does not touch the database |
|
Args |
none |
|
Returns |
ARRAY or ARRAY ref depending on context. Each element of the results is a single SQL statement as a string. |
Title |
alter |
|
Usage |
$collection->alter($diff) |
|
Function |
Returns SQL statements needed to alter the tables that implement the collection. Does not touch the database |
|
Args |
$diff |
Class:AutoDB::CollectionDiff object comparing this collection to new one. |
Returns |
ARRAY or ARRAY ref depending on context. Each element of the results is a single SQL statement as a string. |