ORM锁和事务

事务和锁

mysql:  中写法
select * from book where id=1 for update;

begin;  start transaction;
	select * from t1 where id=1 for update;
commit

rollback;


django orm中写法
models.Book.objects.select_for_update().filter(id=1)

事务

from django.db import transaction

@transaction.atomic
def index(request):
	
	...


def index(request):
	...
	with transaction.atomic():
		xxxx
	...

posted @ 2020-03-02 17:46  一起奥利给  阅读(185)  评论(0编辑  收藏  举报