Postgres DB access

This submodule provides the PostgresAccess, an implementation of DbAccess for Postgres. It uses the asyncpg library, which gets pulled in as a dependency when the postgres extra is selected.

tablecache.postgres.DbRecord: asyncpg.Record
tablecache.postgres.RecordsSpec[Record]: tablecache.QueryArgsDbRecordsSpec[DbRecord, Record]
class tablecache.postgres.PostgresAccess

Bases: DbAccess[DbRecord, RecordsSpec], Generic

Postgres access.

Provides access to records stored in Postgres via records specs that contain a query and arguments.

Creates an asyncpg.pool.Pool connection pool on construction which is opened/closed on __aenter__() and __aexit__().

__init__(record_parser=None, **pool_kwargs)
Parameters:
  • record_parser (RecordParser[DbRecord, Record] | None) –

    An optional function that is applied to each record before it is returned. This overrides the parser in the records spec.

    Deprecated since version 4.2: Use the record parser in the records spec instead.

  • pool_kwargs (Any) – Arguments that will be passed to asyncpg.create_pool to create the connection pool. The pool is only created, not connected. Arguments min_size=0 and max_size=1 are added unless otherwise specified.

Return type:

None

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:

AsyncIterator