{"action":"created","issue":{"url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/128","labels_url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/128/comments","events_url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/128/events","html_url":"https://github.com/noplay/python-mysql-replication/issues/128","id":100613399,"number":128,"title":"examples/rethinkdb_sync.py not work","user":{"login":"amartinelli","id":3126786,"avatar_url":"https://avatars.githubusercontent.com/u/3126786?v=3","gravatar_id":"","url":"https://api.github.com/users/amartinelli","html_url":"https://github.com/amartinelli","followers_url":"https://api.github.com/users/amartinelli/followers","following_url":"https://api.github.com/users/amartinelli/following{/other_user}","gists_url":"https://api.github.com/users/amartinelli/gists{/gist_id}","starred_url":"https://api.github.com/users/amartinelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amartinelli/subscriptions","organizations_url":"https://api.github.com/users/amartinelli/orgs","repos_url":"https://api.github.com/users/amartinelli/repos","events_url":"https://api.github.com/users/amartinelli/events{/privacy}","received_events_url":"https://api.github.com/users/amartinelli/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-12T19:08:39Z","updated_at":"2015-08-19T19:17:48Z","closed_at":"2015-08-19T19:17:48Z","body":" ./rethinkdb_sync.py \r\nTraceback (most recent call last):\r\n  File \"./rethinkdb_sync.py\", line 65, in <module>\r\n    main()\r\n  File \"./rethinkdb_sync.py\", line 36, in main\r\n    rethinkdb.db_create(\"mysql\").run()\r\n  File \"/usr/lib/python2.6/site-packages/rethinkdb/ast.py\", line 116, in run\r\n    \" a connection to run on.\")\r\nrethinkdb.errors.ReqlDriverError: RqlQuery.run must be given a connection to run on.\r\n\r\n\r\nAnybody help-me ?"},"comment":{"url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/comments/132748002","html_url":"https://github.com/noplay/python-mysql-replication/issues/128#issuecomment-132748002","issue_url":"https://api.github.com/repos/noplay/python-mysql-replication/issues/128","id":132748002,"user":{"login":"amartinelli","id":3126786,"avatar_url":"https://avatars.githubusercontent.com/u/3126786?v=3","gravatar_id":"","url":"https://api.github.com/users/amartinelli","html_url":"https://github.com/amartinelli","followers_url":"https://api.github.com/users/amartinelli/followers","following_url":"https://api.github.com/users/amartinelli/following{/other_user}","gists_url":"https://api.github.com/users/amartinelli/gists{/gist_id}","starred_url":"https://api.github.com/users/amartinelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amartinelli/subscriptions","organizations_url":"https://api.github.com/users/amartinelli/orgs","repos_url":"https://api.github.com/users/amartinelli/repos","events_url":"https://api.github.com/users/amartinelli/events{/privacy}","received_events_url":"https://api.github.com/users/amartinelli/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T19:17:48Z","updated_at":"2015-08-19T19:17:48Z","body":"#!/usr/bin/env python\r\n# -*- coding: utf-8 -*-\r\n\r\n#\r\n# Insert a new element in  a RethinkDB database\r\n# when an evenement is trigger in MySQL replication log\r\n#\r\n# Please test with MySQL employees DB available here:\r\n# https://launchpad.net/test-db/\r\n#\r\n\r\nimport rethinkdb as rdb\r\n\r\nfrom pymysqlreplication import BinLogStreamReader\r\nfrom pymysqlreplication.row_event import (\r\n    DeleteRowsEvent,\r\n    UpdateRowsEvent,\r\n    WriteRowsEvent,\r\n)\r\n\r\nMYSQL_SETTINGS = {\r\n    \"host\": \"192.168.0.10\",\r\n    \"port\": 3306,\r\n    \"user\": \"root\",\r\n    \"passwd\": \"password\"\r\n}\r\n\r\n\r\ndef main():\r\n    # connect rethinkdb\r\n    \r\n    rdb.connect(\"localhost\", 28015, \"mysql\").repl()\r\n    try:\r\n        rdb.db_drop(\"mysql\").run()\r\n    except:\r\n        pass\r\n    rdb.db_create(\"mysql\").run()\r\n\r\n    tables = [\"Experts\"]\r\n    for table in tables:\r\n        rdb.db(\"mysql\").table_create(table).run()\r\n\r\n   stream = BinLogStreamReader(\r\n        connection_settings=MYSQL_SETTINGS,\r\n        server_id=1,\r\n        resume_stream=False,\r\n        blocking=True,\r\n        only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent],\r\n    )\r\n\r\n    # process Feed\r\n    for binlogevent in stream:\r\n        if not isinstance(binlogevent, WriteRowsEvent):\r\n            continue\r\n\r\n        for row in binlogevent.rows:\r\n            if not binlogevent.schema == \"GAQhomologa\":\r\n                continue\r\n\r\n            vals = dict((str(k), str(v)) for k, v in row[\"values\"].iteritems())\r\n            rdb.table(binlogevent.table).insert(vals).run()\r\n\r\n    stream.close()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n"}}