Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 2, 2021
1 parent 2cba54d commit 1788e7f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions mitama/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ def genUUID():
class Model:
prefix = None
_id = Column(String(64), default=UUID(), primary_key=True, nullable=False)
_event_handlers = {
"create": Event(),
"update": Event(),
"delete": Event()
}
create = Event()
update = Event()
delete = Event()

@classmethod
def attribute_names(cls):
Expand Down Expand Up @@ -80,31 +78,31 @@ def create(self):
self.query.session.add(self)
self.query.session.commit()
try:
self.on("create")(self)
self.on("create")()
except Exception:
pass

def update(self):
self.query.session.commit()
try:
self.on("update")(self)
self.on("update")()
except Exception:
pass

def delete(self):
self.query.session.delete(self)
self.query.session.commit()
try:
self.on("delete")(self)
self.on("delete")()
except Exception:
pass

def on(self, evt):
return self._event_handlers[evt]
return getattr(self, evt)

@classmethod
def listen(self, evt):
self._event_handlers[evt] = Event()
def listen(cls, evt):
setattr(cls, evt, Event())

@classmethod
def list(cls, cond=None):
Expand Down

0 comments on commit 1788e7f

Please sign in to comment.