Skip to content

Commit fa737ec

Browse files
committed
add to_dict method to BinLogEvent
1 parent 82240b7 commit fa737ec

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pymysqlreplication/event.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pymysqlreplication.exceptions import StatusVariableMismatch
1010
from pymysqlreplication.util.bytes import parse_decimal_from_bytes
1111
from typing import Union, Optional
12+
import json
1213

1314

1415
class BinLogEvent(object):
@@ -67,15 +68,27 @@ def _verify_event(self):
6768
self.packet.read_bytes -= 19 + self.event_size + 4
6869
self.packet.rewind(20)
6970

71+
@property
72+
def formatted_timestamp(self) -> str:
73+
return datetime.datetime.utcfromtimestamp(self.timestamp).isoformat()
74+
7075
def dump(self):
7176
print(f"=== {self.__class__.__name__} ===")
72-
print(f"Date: {datetime.datetime.utcfromtimestamp(self.timestamp).isoformat()}")
77+
print(f"Date: {self.formatted_timestamp}")
7378
print(f"Log position: {self.packet.log_pos}")
7479
print(f"Event size: {self.event_size}")
7580
print(f"Read bytes: {self.packet.read_bytes}")
7681
self._dump()
7782
print()
7883

84+
def to_dict(self) -> dict:
85+
return {
86+
"timestamp": self.formatted_timestamp,
87+
"log_pos": self.packet.log_pos,
88+
"event_size": self.event_size,
89+
"read_bytes": self.packet.read_bytes,
90+
}
91+
7992
def _dump(self):
8093
"""Core data dumped for the event"""
8194
pass

0 commit comments

Comments
 (0)