FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-mysql-replication/examples/rethinkdb_sync.py at master · PKUbuntu/python-mysql-replication · GitHub
PKUbuntu
/
python-mysql-replication
Public
forked from
julien-duponchelle/python-mysql-replication
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-mysql-replication
/
examples
/
rethinkdb_sync.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (52 loc) · 1.52 KB
Breadcrumbs
python-mysql-replication
/
examples
/
rethinkdb_sync.py
Copy path
File metadata and controls
66 lines (52 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Insert a new element in a RethinkDB database
# when an evenement is trigger in MySQL replication log
#
# Please test with MySQL employees DB available here:
# https://launchpad.net/test-db/
#
import
rethinkdb
from
pymysqlreplication
import
BinLogStreamReader
from
pymysqlreplication
.
row_event
import
(
DeleteRowsEvent
,
UpdateRowsEvent
,
WriteRowsEvent
,
)
MYSQL_SETTINGS
=
{
"host"
:
"127.0.0.1"
,
"port"
:
3306
,
"user"
:
"root"
,
"passwd"
:
""
}
def
main
():
# connect rethinkdb
rethinkdb
.
connect
(
"localhost"
,
28015
,
"mysql"
)
try
:
rethinkdb
.
db_drop
(
"mysql"
).
run
()
except
:
pass
rethinkdb
.
db_create
(
"mysql"
).
run
()
tables
=
[
"dept_emp"
,
"dept_manager"
,
"titles"
,
"salaries"
,
"employees"
,
"departments"
]
for
table
in
tables
:
rethinkdb
.
db
(
"mysql"
).
table_create
(
table
).
run
()
stream
=
BinLogStreamReader
(
connection_settings
=
MYSQL_SETTINGS
,
blocking
=
True
,
only_events
=
[
DeleteRowsEvent
,
WriteRowsEvent
,
UpdateRowsEvent
],
)
# process Feed
for
binlogevent
in
stream
:
if
not
isinstance
(
binlogevent
,
WriteRowsEvent
):
continue
for
row
in
binlogevent
.
rows
:
if
not
binlogevent
.
schema
==
"employees"
:
continue
vals
=
{}
vals
=
{
str
(
k
):
str
(
v
)
for
k
,
v
in
row
[
"values"
].
iteritems
()}
rethinkdb
.
table
(
binlogevent
.
table
).
insert
(
vals
).
run
()
stream
.
close
()
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL