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
    ...

おすすめ

転載: www.cnblogs.com/saoqiang/p/12396970.html