Is there a way to have SQLAlchemy NOT wrap SQL writes within a BEGIN and COMMIT?

邮差的信 提交于 2019-12-11 03:06:43

问题


I'm using SQLAlchemy 0.6.4 on the Pylons 1.0 framework. I've tried every permutation of setting autoflush and autocommit to True and False, but I've found that SQLAlchemy wants to wrap all SQL sessions or writes with a BEGIN/COMMIT. I've configured the scoped_session in models/meta.py as below:

"""SQLAlchemy Metadata and Session object"""

from sqlalchemy import MetaData

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import scoped_session, sessionmaker

__all__ = ['Base', 'Session']

# SQLAlchemy session manager. Updated by model.init_model()
Session = scoped_session(sessionmaker(autoflush=False, autocommit=True))

# The declarative Base
Base = declarative_base()

metadata = MetaData()

回答1:


If your problem is the slowness of this behaviour, the solution might be to begin/end transactions in some sensible way explicitly in your application.




回答2:


Does not look like it:

While many DBAPIs implement a flag called autocommit, the current SQLAlchemy behavior is such that it implements its own autocommit. This is achieved by detecting statements which represent data-changing operations, i.e. INSERT, UPDATE, DELETE, etc., and then issuing a COMMIT automatically if no transaction is in progress.



来源:https://stackoverflow.com/questions/4393035/is-there-a-way-to-have-sqlalchemy-not-wrap-sql-writes-within-a-begin-and-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!