Skip to content

Datastore base

blackline.models.datastore_base

DataStoreBase

Bases: BaseModel

Parameters:

Name Type Description Default
type str required
adapter Any required
template_params required
Source code in BAR /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/models/datastore_base.py
class DataStoreBase(BaseModel):
    type: str
    adapter: Any = None

    @validator("adapter", pre=True, always=True)
    def load_adapter_cls(cls, value, values):
        return AdapterFactory.load_adapter(name=values["type"])

    @root_validator(pre=False)
    def initialize_adapter(cls, values):
        """
        Shit design patter. The values["config"] is only added by the subclass.
        This model cannot exist on it's on and is not labeled as an ABC.
        """
        values["adapter"] = values["adapter"](values["config"])
        return values

    @property
    def template_params(self):
        return TemplateParams(
            update_template=self.adapter.update_template(),
            set_template=self.adapter.set_template(),
            where_template=self.adapter.where_template(),
            redact_template=self.adapter.redact_template(),
            replace_template=self.adapter.replace_template(),
            mask_template=self.adapter.mask_template(),
        )

    def deidentify(self, dataset: Dataset, start_date: datetime = datetime.now()):
        for collection in dataset.collections.values():
            self.deidentify_collection(collection=collection, start_date=start_date)

    def deidentify_collection(
        self, collection: DatasetCollection, start_date: datetime = datetime.now()
    ):
        query_factory = QueryFactory(
            collection=collection,
            template_params=self.template_params,
            dialect=self.adapter.dialect,
            start_date=start_date,
            where_clause=collection.where,
        )
        for sql, values in query_factory.queries():
            self.adapter.execute(sql, values)

initialize_adapter(values)

Shit design patter. The values["config"] is only added by the subclass. This model cannot exist on it's on and is not labeled as an ABC.

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/models/datastore_base.py
@root_validator(pre=False)
def initialize_adapter(cls, values):
    """
    Shit design patter. The values["config"] is only added by the subclass.
    This model cannot exist on it's on and is not labeled as an ABC.
    """
    values["adapter"] = values["adapter"](values["config"])
    return values