博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
django查询数据库数据_Django:通过数据库事务更快地运行多个更新查询
阅读量:2516 次
发布时间:2019-05-11

本文共 1527 字,大约阅读时间需要 5 分钟。

django查询数据库数据

()

( )

Django’s default behaviour is to run autocommit mode. Each query is immediately committed to the database unless a transaction is active.

Django的默认行为是运行自动提交模式。 除非事务处于活动状态,否则每个查询都会立即提交到数据库。

Django provides a single API to control database transactions. atomic allows us to create a block of code or a function within which the atomicity of the database is guaranteed. If the block of code is successfully completed, the changes are committed to the database. If there is an exception, the changes are rolled back. 

Django提供了一个API来控制数据库事务。 atomic使我们可以创建代码块或函数,以保证数据库的原子性。 如果代码块成功完成,则更改将提交给数据库。 如果有异常,则更改将回滚。

atomic can be either used as a decorator or as a context manager.

原子可以用作装饰器或用作上下文管理器。

Here is an example for atomic as a decorator

这是atomic as a decorator的示例

from django.db import transaction @transaction.atomicdef foo():do_more() # Multiple update queries executes inside a transaction

An example for atomic as a context manager

一个atomic as a context manager的示例

from django.db import transaction def foo():do_stuff() # This code executes in Django's default autocommit mode. with transaction.atomic():do_more() # Multiple update queries executes inside a transaction

atomic blocks can be nested. In this case, when an inner block completes successfully, its effects can still be rolled back if an exception is raised in the outer block at a later point.

atomic 块可以嵌套。 在这种情况下,当内部块成功完成时,如果稍后在外部块中引发异常,则仍然可以回滚其效果。

Currently unrated
目前未分级

翻译自:

django查询数据库数据

转载地址:http://ezhwd.baihongyu.com/

你可能感兴趣的文章
[Spfa][bfs] Jzoj P5781 秘密通道
查看>>
企业帐号进行IPA的打包、分发、下载安装的详细流程(转载)
查看>>
《项目架构那点儿事》——快速构建Junit用例
查看>>
{"errmsg":"invalid weapp pagepath hint: [IunP8a07243949]","errcode":40165}微信的坑
查看>>
DB2V9.5数据库使用pdf
查看>>
(Life)转来转去还是卡巴斯基
查看>>
Java Bigdecimal使用
查看>>
轨迹系列10——记某真实项目中轨迹展示查询效率优化方案三(汇总实验)
查看>>
使用selenium.webdriver.common.desired_capabilities获取浏览器日志
查看>>
分享PHP小马一枚,完美绕过安全狗检测。
查看>>
初涉树分块
查看>>
iframs刷新的两种方法
查看>>
RN全局的变量,方法,全局类,全局类方法
查看>>
安装scikit-learn
查看>>
FOJ Problem 2261 浪里个浪
查看>>
Shel脚本学习—反引号、单引号、双引号区别与联系
查看>>
Spring Boot 2 实践记录之 组合注解原理
查看>>
互联网金融爬虫怎么写-第一课 p2p网贷爬虫(XPath入门)
查看>>
语义化的理解?
查看>>
多线程学习(十)
查看>>