Package spade :: Module dblite :: Class Base
[hide private]
[frames] | no frames]

Class Base

source code

Instance Methods [hide private]
 
__init__(self, basename) source code
 
create(self, *fields, **kw)
Create a new base with specified field names...
source code
 
create_index(self, *fields)
Create an index on the specified field names
source code
 
open(self)
Open an existing database and load its content into memory
source code
 
commit(self)
Write the database to a file
source code
 
insert(self, *args, **kw)
Insert a record in the database Parameters can be positional or keyword arguments.
source code
 
delete(self, removed)
Remove a single record, or the records in an iterable Before starting deletion, test if all records are in the base and don't have twice the same __id__ Return the number of deleted items
source code
 
update(self, record, **kw)
Update the record with new keys and values and update indices
source code
 
add_field(self, field, default=None) source code
 
drop_field(self, field) source code
 
__call__(self, **kw)
Selection by field values db(key=value) returns the list of records where r[key] = value
source code
 
__getitem__(self, record_id)
Direct access by record id
source code
 
__len__(self) source code
 
__delitem__(self, record_id)
Delete by record id
source code
 
__iter__(self)
Iteration on the records
source code
Method Details [hide private]

create(self, *fields, **kw)

source code 
Create a new base with specified field names
A keyword argument mode can be specified ; it is used if a file
with the base name already exists
- if mode = 'open' : open the existing base, ignore the fields
- if mode = 'override' : erase the existing base and create a
new one with the specified fields

create_index(self, *fields)

source code 

Create an index on the specified field names

An index on a field is a mapping between the values taken by the field and the sorted list of the ids of the records whose field is equal to this value

For each indexed field, an attribute of self is created, an instance of the class Index (see above). Its name it the field name, with the prefix _ to avoid name conflicts

insert(self, *args, **kw)

source code 

Insert a record in the database Parameters can be positional or keyword arguments. If positional they must be in the same order as in the create() method If some of the fields are missing the value is set to None Returns the record identifier