ahvn.adapter.db module¶
- class ahvn.adapter.db.ORMUKFAdapter(*args, **kwargs)[source]¶
Bases:
BaseUKFAdapterSimplified ORM adapter that only provides access to entity classes and conversion methods.
This adapter creates SQLAlchemy ORM entities dynamically based on the included fields and provides conversion methods between UKF objects and ORM entities.
- virtual_fields = ('id', 'expiration_timestamp')¶
- __init__(*args, **kwargs)[source]¶
Initialize the ORM adapter with specified field inclusion.
- Parameters:
name – Name of the adapter instance.
include – List of BaseUKF field names to include in the ORM schema. If None, includes all available BaseUKF fields plus virtual fields. The ‘id’ field is always included automatically.
exclude – List of BaseUKF field names to exclude from the ORM schema. If None, excludes no fields.
*args – Additional positional arguments.
**kwargs – Additional configuration parameters.
- Returns:
None
- from_ukf(ukf)[source]¶
Convert a BaseUKF object to a ORMUKFMainEntity object.
- Parameters:
ukf (
BaseUKF) – BaseUKF object to convert.- Return type:
- Returns:
A dictionary mapping table names to their corresponding ORM entity instances. main key corresponds to the main entity, and other keys correspond to dimension entities. The main will always be the first item in the dictionary.
- entity_mappings(kls)[source]¶
Convert a list of BaseUKF objects to dictionary mappings for bulk insert.
This method generates mappings suitable for SQLAlchemy’s bulk_insert_mappings(), which is significantly more efficient than add_all() for large batches.
- to_ukf_data(entity)[source]¶
Convert a ORMUKFMainEntity object to a dictionary suitable for BaseUKF initialization.
- Parameters:
entity (
ExportableEntity) – The ORM entity to convert.- Return type:
- Returns:
A dictionary of field names and values for BaseUKF initialization.