for update

This commit is contained in:
j 2019-01-15 13:20:11 +05:30
commit 6c7d6bb6b0
3 changed files with 9 additions and 4 deletions

View file

@ -75,10 +75,13 @@ class Item(db.Model):
self.meta = {}
@classmethod
def get(cls, id):
def get(cls, id, for_update=False):
if isinstance(id, list):
id = base64.b32encode(hashlib.sha1(''.join(id)).digest())
return cls.query.filter_by(id=id).first()
qs = cls.query.filter_by(id=id)
if for_update:
qs = qs.with_for_update()
return qs.first()
@classmethod
def get_or_create(cls, id, info=None):