python - 有没有办法让 SQLAlchemy 不在 BEGIN 和 COMMIT 中包装 SQL 写入?

标签 python sqlalchemy pylons

我在 Pylons 1.0 框架上使用 SQLAlchemy 0.6.4。我已经尝试了将 autoflush 和 autocommit 设置为 True 和 False 的所有排列,但我发现 SQLAlchemy 想要包装所有 SQL session 或使用 BEGIN/COMMIT 进行写入。我在 models/meta.py 中配置了scoped_session,如下所示:

"""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()

最佳答案

如果您的问题是此行为的缓慢,解决方案可能是在您的应用程序中以某种合理的方式显式开始/结束事务。

关于python - 有没有办法让 SQLAlchemy 不在 BEGIN 和 COMMIT 中包装 SQL 写入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4393035/

相关文章:

python - 使用动态表生成完全刷新 SQLAlchemy

Python Flask 未从 SQLAlchemy 数据库中删除正确的 ID

python - SQLAlchemy 在不提交 session 的情况下获取添加对象的 ID

Python:Redis 作为 Beaker 的 session 后端

python - 为什么我收到 "ImportError: No module named pyramid.config"

python - 为什么 Python ggplot 返回名称 'aes' 未定义?

python - 尝试在继承 View Odoo 中添加列时出错

python - 从 FTP 服务器上的 ZIP 存档中读取文件而不下载到本地系统

python - 创建可访问 app_globals 的 Pylons 线程

python - PyPy 可以与 NLTK 一起使用吗?