-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbase.py
96 lines (84 loc) · 3.71 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from __future__ import absolute_import, unicode_literals
from ..event.row_wrapper import InsertEventRow, UpdateEventRow, DeleteEventRow
class IEventHandler(object):
def on_insert_raw(self, ev_id, ev):
ev_timestamp = ev.packet.timestamp
schema = ev.schema
table = ev.table
affected_rows = []
for row in ev.rows:
affected_rows.append(InsertEventRow(
ev_id=ev_id,
ev=ev,
new_values=row['values'],
))
self.on_insert(ev_id, ev_timestamp, schema, table, affected_rows)
def on_update_raw(self, ev_id, ev):
ev_timestamp = ev.packet.timestamp
schema = ev.schema
table = ev.table
affected_rows = []
for row in ev.rows:
affected_rows.append(UpdateEventRow(
ev_id=ev_id,
ev=ev,
old_values=row['before_values'],
new_values=row['after_values'],
))
self.on_update(ev_id, ev_timestamp, schema, table, affected_rows)
def on_delete_raw(self, ev_id, ev):
ev_timestamp = ev.packet.timestamp
schema = ev.schema
table = ev.table
affected_rows = []
for row in ev.rows:
affected_rows.append(DeleteEventRow(
ev_id=ev_id,
ev=ev,
old_values=row['values'],
))
self.on_delete(ev_id, ev_timestamp, schema, table, affected_rows)
pass
def on_insert(self, ev_id, ev_timestamp, schema, table, affected_rows):
"""
:param ev_id: unique string id for each event
:param ev_timestamp: unix epoch for the time event happens
:param schema: affected database name
:param table: affected table name
:param affected_rows: list of instance of mysqlevp.event.row_wrapper.InsertEventRow
each of instance has an attr named "new_values",
which is a dict(whose key is MySQL column name) of the new inserted row
for row in affected_rows:
do_something(row.new_values)
"""
pass
def on_update(self, ev_id, ev_timestamp, schema, table, affected_rows):
"""
:param ev_id: unique string id for each event
:param ev_timestamp: unix epoch for the time event happens
:param schema: affected database name
:param table: affected table name
:param affected_rows: list of instance of mysqlevp.event.row_wrapper.UpdateEventRow
each of instance has two attrs named "new_values" and "old_values",
which are dicts(whose key is MySQL column name) of the new inserted row and the old replaced row
for row in affected_rows:
do_something(row.new_values, row.old_values)
"""
pass
def on_delete(self, ev_id, ev_timestamp, schema, table, affected_rows):
"""
:param ev_id: unique string id for each event
:param ev_timestamp: unix epoch for the time event happens
:param schema: affected database name
:param table: affected table name
:param affected_rows: list of instance of mysqlevp.event.row_wrapper.DeleteEventRow
each of instance has an attr named "old_values",
which is a dict(whose key is MySQL column name) of the deleted row
for row in affected_rows:
do_something(row.old_values)
"""
pass
def close(self):
"""allow user to release some resource
"""
pass