DB access
The DbAccess
is the abstract base for access to a database. It’s a
very simple interface, able to get records based on a
DbRecordsSpec
.
- tablecache.db.RecordParser[DbRecord, Record]: collections.abc.Callable[[DbRecord], Record]
A function parsing a record from the DB into a custom data structure.
- class tablecache.DbRecordsSpec
Base type for a specification of records in the DB.
- __init__(*, record_parser=None)
- Parameters:
record_parser (RecordParser | None) – An optional function that is applied to each record before it is returned. The default is to return the record as-is.
- class tablecache.QueryArgsDbRecordsSpec
A specification of DB records via a query and args.
- __init__(query, args, *, record_parser=None)
- Parameters:
record_parser (RecordParser | None) – An optional function that is applied to each record before it is returned. The default is to return the record as-is.
query (str) –
args (tuple) –
- class tablecache.DbAccess
A DB access abstraction.
Provides access to sets of records stored in the DB via a records spec that is up to the concrete implementation.
- async get_record(records_spec)
Fetch a single record.
This is just a convenience shortcut around
get_records()
.If more than one record matches the spec, one of them is returned, but there is no guarantee which. :raise KeyError: If no record matches.
- Parameters:
records_spec (RecordsSpec) –
- Return type:
Record
- abstract async get_records(records_spec)
Asynchronously iterate over a subset of records.
Fetches records matching the given spec and yields them.
- Parameters:
records_spec (RecordsSpec) – A specification of records.
- Returns:
The requested records, as an asynchronous iterator.
- Return type:
AsyncIterable