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

Class Database

source code

object --+
         |
        Database
Known Subclasses:
Adapter.Adapter, Stores.filestore.Database, Stores.bsddbstore.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



See Also: queries

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

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
_txo_warn(self) source code
 
_txo_get(self) source code
 
_entries_get(self)
Return the result set that contains _all_ the entries.
source code
 
add(self, record, key=None)
Insert a new entry in the database.
source code
 
__setitem__(self, key, record)
Update a record.
source code
 
__getitem__(self, key)
Get a record by key.
source code
 
has_key(self, key)
Check for the existence of a key.
source code
 
query(self, query, permanent=False) source code
 
collate(self, rs, field)
Partition the result set in a list of sets for every value taken by the specified field
source code
 
save(self) source code
 
validate(self, entry)
Check an entry for conformance against the Schema.
source code
 
xmlwrite(self, fd)
Output a database in XML format
source code
 
xmlread(self, fd) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  rs
a ResultSetStore instance, containing all the result sets defined on this database.
Properties [hide private]
  txo
DEPRECATED, use schema.txo instead.
  entries
a resultset containing all the records of the database.

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

add(self, record, key=None)

source code 

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 (a Record) - the new record to add
  • key (a Key) - only useful for importing an existing database, by proposing a key choice.

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

source code 

Update a record.

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

__getitem__(self, key)
(Indexing operator)

source code 
Get a record by key.
Parameters:
  • key (a Key) - the key of the requested record

has_key(self, key)

source code 
Check for the existence of a key.
Parameters:
  • key (a Key) - the key to check for

validate(self, entry)

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

Property Details [hide private]

txo

DEPRECATED, use schema.txo instead. A TxoGroup instance, containing all the taxonomy definitions in the database. See TxoItem.
Get Method:
Pyblio.Store.Database._txo_get(self)

entries

a resultset containing all the records of the database.
Get Method:
Pyblio.Store.Database._entries_get(self) - Return the result set that contains _all_ the entries.