在Flask-SQLAlchemy中自动提交 [英] Autocommit in Flask-SQLAlchemy

查看:4074
本文介绍了在Flask-SQLAlchemy中自动提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置初始化我的Flask应用程序以将Flask-SQLAlchemy设置为自动提交模式,除非我明确地 session.begin(),否则不使用事务。

会议尽快开始数据库交易当它开始沟通。这会影响Postgres 比MySQL强吗?

/instagram-engineering.tumblr.com/post/40781627982/handling-growth-with-postgres-5-tips-from-instagram\">Instagram ,


自动提交模式;在这种模式下,Psycopg2不会为
发出BEGIN / COMMIT任何查询;相反,每个查询运行在它自己的单语句
事务中。这对于不需要
事务语义的只读查询特别有用。这很容易做:

connection.autocommit = True

这降低了我们的应用程序服务器和DB之间的聊天
显着,并降低了系统CPU以及在数据库框中。


解决方案

认为你可以在Flask-SQLAlchemy中设置 autocommit 这样做:

  from flask.ext.sqlalchemy import SQLAlchemy 
db = SQLAlchemy(session_options = {'autocommit':True})


How do I set initilize my Flask application to set Flask-SQLAlchemy to autocommit mode, to not use transactions unless I explicitly session.begin()?

The session "begins a database transaction as soon as it starts communicating". Does this affect Postgres harder than MySQL?


By Instagram,

autocommit mode; in this mode, Psycopg2 won’t issue BEGIN/COMMIT for any queries; instead, every query runs in its own single-statement transaction. This is particularly useful for read-only queries where transaction semantics aren’t needed. It’s as easy as doing:

connection.autocommit = True

This lowered chatter between our application servers and DBs significantly, and lowered system CPU as well on the database boxes

解决方案

I think you can set autocommit in Flask-SQLAlchemy doing this:

from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy(session_options={'autocommit': True})

这篇关于在Flask-SQLAlchemy中自动提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆