是否有任何 MySQL 的异步驱动程序/模块可用于 Tornado 以支持事务?我正在用 MySQL 作为数据库编写 Tornado 应用程序。我用谷歌搜索并找到了 https://github.com/woshifyz/tornado-mysql
https://github.com/hybridlogic/txMySQL
但不支持交易。
是否有任何 MySQL 的异步驱动程序/模块可用于 Tornado 以支持事务?我正在用 MySQL 作为数据库编写 Tornado 应用程序。我用谷歌搜索并找到了 https://github.com/woshifyz/tornado-mysql
https://github.com/hybridlogic/txMySQL
但不支持交易。
Tornado 自己的数据库模块支持事务就好了。
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/', someHandler),
]
tornado.web.Application.__init__(self, handlers)
self.db = tornado.database.Connection(
host=mysql_host, database=mysql_db,
user=mysql_user, password=mysql_password)
# ----------------------
class someHandler(tornado.web.RequestHandler):
def get(self):
# ...
try:
self.application.db.execute('START TRANSACTION')
row = self.application.db.get("SELECT ...", ...)
# ...
self.application.db.execute("INSERT ...", ...)
self.application.db.execute("COMMIT")
except Exception, e:
self.set_status(500)
return
# ...
但是,它不支持异步调用。
更新(2015 年 5 月)
该主题的若干更新。