Source code for loom.etl.observability.sinks._protocol

"""Persistence contracts for execution records."""

from __future__ import annotations

from collections.abc import Sequence
from typing import Any, Protocol

from loom.etl.declarative.expr._refs import TableRef
from loom.etl.observability.records import ExecutionRecord


[docs] class ExecutionRecordStore(Protocol): """Protocol for persisting execution records."""
[docs] def write_record(self, record: ExecutionRecord) -> None: """Persist one completed execution record."""
[docs] class ExecutionRecordWriter(Protocol): """Persist one execution record into a table destination."""
[docs] def write_record(self, record: ExecutionRecord, table_ref: TableRef, /) -> None: """Write *record* to *table_ref*."""
[docs] class RecordFrameTargetWriter(Protocol): """Target-writer capability required to persist execution records."""
[docs] def to_frame(self, records: Sequence[ExecutionRecord], /) -> Any: """Convert execution records into backend frame type."""
[docs] def append( self, frame: Any, table_ref: TableRef, params_instance: Any, /, *, streaming: bool = False, ) -> None: """Append backend frame into destination table."""
__all__ = ["ExecutionRecordStore", "ExecutionRecordWriter", "RecordFrameTargetWriter"]