Difference between revisions of "API:EPrints/DataSet"
Line 21: | Line 21: | ||
print sprintf("There are %d records in the inbox\n", | print sprintf("There are %d records in the inbox\n", | ||
$dataset->count); | $dataset->count); | ||
+ | |||
+ | $string = $dataset->base_id; # eprint | ||
+ | $string = $dataset->id; # inbox | ||
+ | |||
+ | $dataobj = $dataset->create_dataobj( $data ); | ||
+ | $user = $dataset->dataobj( 23 ); | ||
+ | |||
+ | $search = $dataset->prepare_search( %options ); | ||
+ | $list = $dataset->search( %options ); # prepare_search( %options )->execute | ||
+ | $list = $dataset->search; # match ALL | ||
+ | |||
+ | $metafield = $dataset->field( $fieldname ); | ||
+ | $metafield = $dataset->key_field; | ||
+ | @metafields = $dataset->fields; | ||
+ | |||
+ | $dataset->search->map( sub {}, $ctx ); | ||
+ | $n = $dataset->search->count; | ||
+ | $ids = $dataset->search->ids; | ||
+ | $list = $dataset->list( \@ids ); | ||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 37: | Line 56: | ||
A normal dataset (eg. "user") has a package associated with it (eg. EPrints::DataObj::User) which must be a subclass of EPrints::DataObj and a number of SQL tables which are prefixed with the dataset name. Most datasets also have a set of associated EPrints::MetaField's which may be optional or compulsary depending on the type eg. books have editors but posters don't but they are both EPrints. | A normal dataset (eg. "user") has a package associated with it (eg. EPrints::DataObj::User) which must be a subclass of EPrints::DataObj and a number of SQL tables which are prefixed with the dataset name. Most datasets also have a set of associated EPrints::MetaField's which may be optional or compulsary depending on the type eg. books have editors but posters don't but they are both EPrints. | ||
− | The fields contained in a dataset are defined by the data object and by any additional fields defined in cfg.d. Some datasets don't have any fields | + | The fields contained in a dataset are defined by the data object and by any additional fields defined in cfg.d. Some datasets don't have any fields. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Some datasets are "virtual" datasets made from others. Examples include "inbox", "archive", "buffer" and "retired" which are all virtual datasets of of the "eprint" dataset. That is to say "inbox" is a subset of "eprint" and by inference contains EPrints::DataObj::EPrints. You can define your own virtual datasets which opperate on existing datasets. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 284: | Line 77: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_base_id --> | <!-- Pod2Wiki=item_base_id --> | ||
− | ====base_id==== | + | ====$id = $ds->base_id==== |
− | |||
$ds = $repo->dataset( "inbox" ); | $ds = $repo->dataset( "inbox" ); | ||
$id = $ds->base_id; # returns "eprint" | $id = $ds->base_id; # returns "eprint" | ||
Returns the identifier of the base dataset for this dataset (same as {{API:PodLink|file=|package_name=|section=id|text=/id}} unless this dataset is virtual). | Returns the identifier of the base dataset for this dataset (same as {{API:PodLink|file=|package_name=|section=id|text=/id}} unless this dataset is virtual). | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 339: | Line 92: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_field --> | <!-- Pod2Wiki=item_field --> | ||
− | ====field==== | + | ====$metafield = $ds->field( $fieldname )==== |
− | |||
Returns the [[API:EPrints/MetaField|EPrints::MetaField]] from this dataset with the given name, or undef. | Returns the [[API:EPrints/MetaField|EPrints::MetaField]] from this dataset with the given name, or undef. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 380: | Line 104: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_id --> | <!-- Pod2Wiki=item_id --> | ||
− | ====id==== | + | ====$id = $ds->id==== |
− | |||
Return the id of this dataset. | Return the id of this dataset. | ||
Line 393: | Line 116: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_count --> | <!-- Pod2Wiki=item_count --> | ||
− | ====count==== | + | ====$n = $ds->count( $session )==== |
− | |||
Return the number of records in this dataset. | Return the number of records in this dataset. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 484: | Line 128: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_fields --> | <!-- Pod2Wiki=item_fields --> | ||
− | ====fields==== | + | ====@fields = $ds->fields==== |
− | |||
Returns a list of the [[API:EPrints/MetaField|EPrints::MetaField]]s belonging to this dataset. | Returns a list of the [[API:EPrints/MetaField|EPrints::MetaField]]s belonging to this dataset. | ||
Line 497: | Line 140: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_key_field --> | <!-- Pod2Wiki=item_key_field --> | ||
− | ====key_field==== | + | ====$field = $ds->key_field==== |
− | |||
Return the [[API:EPrints/MetaField|EPrints::MetaField]] representing the primary key field. | Return the [[API:EPrints/MetaField|EPrints::MetaField]] representing the primary key field. | ||
Line 511: | Line 153: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
</div> | </div> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=item_make_dataobj --> |
− | ==== | + | ====$dataobj = $ds->make_dataobj( $epdata )==== |
− | + | Return an object of the class associated with this dataset, always a subclass of [[API:EPrints/DataObj|EPrints::DataObj]]. | |
− | Return an object of the class associated with this dataset, always a subclass of EPrints::DataObj. | ||
− | $ | + | $epdata is a hash of values for fields in this dataset. |
− | + | Returns $epdata if no class is associated with this dataset. | |
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 529: | Line 170: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_create_dataobj --> | <!-- Pod2Wiki=item_create_dataobj --> | ||
− | ====create_dataobj==== | + | ====$obj = $ds->create_dataobj( $data )==== |
− | |||
Returns a new object in this dataset based on $data or undef on failure. | Returns a new object in this dataset based on $data or undef on failure. | ||
If $data describes sub-objects then those will also be created. | If $data describes sub-objects then those will also be created. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 570: | Line 184: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_dataobj --> | <!-- Pod2Wiki=item_dataobj --> | ||
− | ====dataobj==== | + | ====$dataobj = $ds->dataobj( $id )==== |
− | |||
Returns the object from this dataset with the given id, or undefined. | Returns the object from this dataset with the given id, or undefined. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 624: | Line 196: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_repository --> | <!-- Pod2Wiki=item_repository --> | ||
− | ====repository==== | + | ====$repository = $ds->repository==== |
− | |||
Returns the [[API:EPrints/Repository|EPrints::Repository]] to which this dataset belongs. | Returns the [[API:EPrints/Repository|EPrints::Repository]] to which this dataset belongs. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 732: | Line 208: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_prepare_search --> | <!-- Pod2Wiki=item_prepare_search --> | ||
− | ====prepare_search==== | + | ====$searchexp = $ds->prepare_search( %options )==== |
− | |||
Returns a [[API:EPrints/Search|EPrints::Search]] for this dataset with %options. | Returns a [[API:EPrints/Search|EPrints::Search]] for this dataset with %options. | ||
Line 745: | Line 220: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_search --> | <!-- Pod2Wiki=item_search --> | ||
− | ====search==== | + | ====$list = $ds->search( %options )==== |
− | |||
Short-cut to {{API:PodLink|file=|package_name=|section=prepare_search|text=/prepare_search}}( %options )->execute. | Short-cut to {{API:PodLink|file=|package_name=|section=prepare_search|text=/prepare_search}}( %options )->execute. | ||
Line 758: | Line 232: | ||
</div> | </div> | ||
<!-- Pod2Wiki=item_list --> | <!-- Pod2Wiki=item_list --> | ||
− | ====list==== | + | ====$list = $ds->list( $ids )==== |
− | |||
Returns a [[API:EPrints/List|EPrints::List]] for this dataset for the given $ids list. | Returns a [[API:EPrints/List|EPrints::List]] for this dataset for the given $ids list. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> |
Revision as of 17:23, 31 December 2010
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki
Contents
- 1 NAME
- 2 SYNOPSIS
- 3 DESCRIPTION
- 3.1 Object Methods
- 3.1.1 $id = $ds->base_id
- 3.1.2 $metafield = $ds->field( $fieldname )
- 3.1.3 $id = $ds->id
- 3.1.4 $n = $ds->count( $session )
- 3.1.5 @fields = $ds->fields
- 3.1.6 $field = $ds->key_field
- 3.1.7 $dataobj = $ds->make_dataobj( $epdata )
- 3.1.8 $obj = $ds->create_dataobj( $data )
- 3.1.9 $dataobj = $ds->dataobj( $id )
- 3.1.10 $repository = $ds->repository
- 3.1.11 $searchexp = $ds->prepare_search( %options )
- 3.1.12 $list = $ds->search( %options )
- 3.1.13 $list = $ds->list( $ids )
- 3.1 Object Methods
NAME
EPrints::DataSet - a dataset is a set of records in the eprints system with the same metadata.
SYNOPSIS
my $dataset = $repository->get_dataset( "inbox" ); print sprintf("There are %d records in the inbox\n", $dataset->count); $string = $dataset->base_id; # eprint $string = $dataset->id; # inbox $dataobj = $dataset->create_dataobj( $data ); $user = $dataset->dataobj( 23 ); $search = $dataset->prepare_search( %options ); $list = $dataset->search( %options ); # prepare_search( %options )->execute $list = $dataset->search; # match ALL $metafield = $dataset->field( $fieldname ); $metafield = $dataset->key_field; @metafields = $dataset->fields; $dataset->search->map( sub {}, $ctx ); $n = $dataset->search->count; $ids = $dataset->search->ids; $list = $dataset->list( \@ids );
DESCRIPTION
This module describes an EPrint dataset.
A repository has several datasets that make up the repository's database. The list of dataset ids can be obtained from the repository object (see EPrints::Repository).
A normal dataset (eg. "user") has a package associated with it (eg. EPrints::DataObj::User) which must be a subclass of EPrints::DataObj and a number of SQL tables which are prefixed with the dataset name. Most datasets also have a set of associated EPrints::MetaField's which may be optional or compulsary depending on the type eg. books have editors but posters don't but they are both EPrints.
The fields contained in a dataset are defined by the data object and by any additional fields defined in cfg.d. Some datasets don't have any fields.
Some datasets are "virtual" datasets made from others. Examples include "inbox", "archive", "buffer" and "retired" which are all virtual datasets of of the "eprint" dataset. That is to say "inbox" is a subset of "eprint" and by inference contains EPrints::DataObj::EPrints. You can define your own virtual datasets which opperate on existing datasets.
Object Methods
$id = $ds->base_id
$ds = $repo->dataset( "inbox" ); $id = $ds->base_id; # returns "eprint"
Returns the identifier of the base dataset for this dataset (same as /id unless this dataset is virtual).
$metafield = $ds->field( $fieldname )
Returns the EPrints::MetaField from this dataset with the given name, or undef.
$id = $ds->id
Return the id of this dataset.
$n = $ds->count( $session )
Return the number of records in this dataset.
@fields = $ds->fields
Returns a list of the EPrints::MetaFields belonging to this dataset.
$field = $ds->key_field
Return the EPrints::MetaField representing the primary key field.
Always the first field.
$dataobj = $ds->make_dataobj( $epdata )
Return an object of the class associated with this dataset, always a subclass of EPrints::DataObj.
$epdata is a hash of values for fields in this dataset.
Returns $epdata if no class is associated with this dataset.
$obj = $ds->create_dataobj( $data )
Returns a new object in this dataset based on $data or undef on failure.
If $data describes sub-objects then those will also be created.
$dataobj = $ds->dataobj( $id )
Returns the object from this dataset with the given id, or undefined.
$repository = $ds->repository
Returns the EPrints::Repository to which this dataset belongs.
$searchexp = $ds->prepare_search( %options )
Returns a EPrints::Search for this dataset with %options.
$list = $ds->search( %options )
Short-cut to /prepare_search( %options )->execute.
$list = $ds->list( $ids )
Returns a EPrints::List for this dataset for the given $ids list.