forked from julien-duponchelle/python-mysql-replication
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtable.py
40 lines (33 loc) · 1.27 KB
/
table.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
# -*- coding: utf-8 -*-
from typing import List
from typing import Dict
from typing import Optional
from pymysqlreplication.column import Column
class Table(object):
def __init__(self, column_schemas: List[Dict[str, str]], table_id: int, schema: str, table: str,
columns: List[Column], primary_key: Optional[List[str]] = None):
if primary_key is None:
primary_key = [c.data["name"] for c in columns if c.data["is_primary"]]
if len(primary_key) == 0:
primary_key = ''
elif len(primary_key) == 1:
primary_key, = primary_key
else:
primary_key = tuple(primary_key)
self.__dict__.update({
"column_schemas": column_schemas,
"table_id": table_id,
"schema": schema,
"table": table,
"columns": columns,
"primary_key": primary_key
})
@property
def data(self):
return dict((k, v) for (k, v) in self.__dict__.items() if not k.startswith('_'))
def __eq__(self, other: 'Table') -> bool:
return self.data == other.data
def __ne__(self, other: 'Table') -> bool:
return not self.__eq__(other)
def serializable_data(self) -> 'Table':
return self.data