big_corporation_inc.id_translation.customization#

Custom implementations may be used to change behavior in ways that TOML configuration alone does not permit.

Classes

CustomSqlFetcher(connection_string[, ...])

A custom SqlFetcher for Big Corporation Inc. databases.

CustomTranslator([fetcher, fmt, mapper, ...])

class CustomTranslator(fetcher=None, fmt='{id}:{name}', mapper=None, default_fmt='<Failed: id={id!r}>', default_fmt_placeholders=None, enable_uuid_heuristics=False, transformers=None)#

Bases: Translator[NameType, SourceType, IdType]

classmethod from_config(*args, **kwargs)#

Create a Translator from TOML inputs.

Parameters:
  • path – Path to the main TOML configuration file.

  • extra_fetchers – Paths to fetching configuration TOML files. If multiple fetchers are defined, they are ranked by input order. If a fetcher defined in the main configuration, it will be prioritized (rank=0).

Returns:

A new Translator instance with a config_metadata attribute.

class CustomSqlFetcher(connection_string, password=None, whitelist_tables=None, blacklist_tables=(), schema=None, include_views=False, engine_kwargs=None, **kwargs)#

Bases: SqlFetcher[IdType]

A custom SqlFetcher for Big Corporation Inc. databases.

Reads the database password from AWS and filters queries based on an ‘enabled’ status flag.

classmethod parse_connection_string(connection_string, arn)#

Finalize the connection string by reading the password from AWS.

classmethod select_where(select, *, ids, id_column, table)#

User method for modifying SELECT statements.

The default implementation returns select as-is. Selection based on IDs is done before this method is called. Users may override this method to change what and which data is returned, e.g. by additional WHERE-clauses.

Parameters:
  • select – A sqlalchemy.sql.Select element. If returned as-is, all IDs in the table will be fetched.

  • ids – Set of IDs to fetch. Will be None if fetch_all() was called.

  • id_column – The ID sqlalchemy.sql.Column of the table, from which ids are fetched.

  • table – Table to select from.

Returns:

The final statement object to use.