def get_latest_event_by_data_field(
            self,
            filters: Dict[str, Any],
    ) -> EventRecord:
        """ Return all state changes filtered by a named field and value."""
        cursor = self.conn.cursor()

        filters = _filter_from_dict(filters)
        where_clauses = []
        args = []
        for field, value in filters.items():
            where_clauses.append('json_extract(data, ?)=?')
            args.append(f'$.{field}')
            args.append(value)

        cursor.execute(
            "SELECT identifier, source_statechange_id, data FROM state_events WHERE "
            f"{' AND '.join(where_clauses)}"
            "ORDER BY identifier DESC LIMIT 1",
            args,
        )

        result = EventRecord(
            event_identifier=0,
            state_change_identifier=0,
            data=None,
        )

        row = cursor.fetchone()
        if row:
            event_id = row[0]
            state_change_identifier = row[1]
            event = row[2]
            result = EventRecord(
                event_identifier=event_id,
                state_change_identifier=state_change_identifier,
                data=event,
            )

        return result
def get_latest_event_by_data_field ( self , filters : Dict [ str , Any ] , ) -> EventRecord : cursor = self . conn . cursor ( ) filters = _filter_from_dict ( filters ) where_clauses = [ ] args = [ ] for field , value in filters . items ( ) : where_clauses . append ( 'json_extract(data, ?)=?' ) args . append ( f'$.{field}' ) args . append ( value ) cursor . execute ( "SELECT identifier, source_statechange_id, data FROM state_events WHERE " f"{' AND '.join(where_clauses)}" "ORDER BY identifier DESC LIMIT 1" , args , ) result = EventRecord ( event_identifier = 0 , state_change_identifier = 0 , data = None , ) row = cursor . fetchone ( ) if row : event_id = row [ 0 ] state_change_identifier = row [ 1 ] event = row [ 2 ] result = EventRecord ( event_identifier = event_id , state_change_identifier = state_change_identifier , data = event , ) return result
Return all state changes filtered by a named field and value.