Package Pyblio :: Module Store :: Class Database
[show private | hide private]
[frames | no frames]

Type Database

object --+
         |
        Database

Known Subclasses:
Adapter, Database, Database

A bibliographic database.

A database behaves like a dictionnary, linking a key with a record. The records are typed, and must follow the specifications of a Schema.

Adding a new record

To add a new record r to a database db:
>>> record = Record ()
>>> record ['title'] = Attribute.Text ('my title')
>>> # ...
>>> key = db.add (record)
When the record is added, a key is generated which uniquely references the record.

Accessing a record

It is possible to use the database as a dictionnary. So, given a key k:
>>> r = db [k]
Alternatively, one can access all the records in a database in random order:
>>> for key, record in db.entries.iteritems ():
>>>    # do something with the record...

Updating a record

Simply store the record back once it is updated:
>>> record = db [key]
>>> ... # update the record
>>> db [key] = record

Attention: getting a record from the database returns a new copy at each access. Updating this copy does not change the stored value.

See Also: queries

Method Summary
  __init__(self)
  __getitem__(self, key)
Get a record by key.
  __setitem__(self, key, record)
Update a record.
  add(self, record, key)
Insert a new entry in the database.
  collate(self, rs, field)
Partition the result set in a list of sets for every value taken by the specified field
  has_key(self, key)
Check for the existence of a key.
  query(self, query, permanent)
  save(self)
  validate(self, entry)
Check an entry for conformance against the Schema.
  xmlread(self, fd)
  xmlwrite(self, fd)
Output a database in XML format
  _entries_get(self)
Return the result set that contains _all_ the entries.
  _txo_get(self)
  _txo_warn(self)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
  entries
  txo

Class Variable Summary
  entries = Pyblio.Store.Database.entries
  rs: a ResultSetStore instance, containing all the result sets defined on this database.
  txo = Pyblio.Store.Database.txo

Method Details

__getitem__(self, key)
(Indexing operator)

Get a record by key.
Parameters:
key - the key of the requested record
           (type=a Key)

__setitem__(self, key, record)
(Index assignment operator)

Update a record.

Updates a record with a new value.
Parameters:
key - the record's key
           (type=a Key)
record - the new value of the record
           (type=a Record)

add(self, record, key=None)

Insert a new entry in the database.

New entries MUST be added with this method, not via an update with a hand-made Key.
Parameters:
record - the new record to add
           (type=a Record)
key - only useful for importing an existing database, by proposing a key choice.
           (type=a Key)

collate(self, rs, field)

Partition the result set in a list of sets for every value taken by the specified field

has_key(self, key)

Check for the existence of a key.
Parameters:
key - the key to check for
           (type=a Key)

validate(self, entry)

Check an entry for conformance against the Schema. This method may modify the entry to normalize certain fields.

xmlwrite(self, fd)

Output a database in XML format

_entries_get(self)

Return the result set that contains _all_ the entries.

Property Details

entries

Get Method:
_entries_get(self)

txo

Get Method:
_txo_get(self)

Class Variable Details

rs

a ResultSetStore instance, containing all the result sets defined on this database.

Generated by Epydoc 2.1 on Sun Sep 24 23:52:43 2006 http://epydoc.sf.net