15 May 15:46
Re: Pre-commit hooks
From: Yannick Gingras <ygingras <at> ygingras.net>
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-15 13:46:39 GMT
Subject: Re: Pre-commit hooks
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-15 13:46:39 GMT
Michael Bayer <mike_mp <at> zzzcomputing.com> writes:
> easy enough to build yourself a generic MapperExtension that scans
> incoming objects for a "_pre_commit()" method.
Yeah indeed. I used this:
------------------------------
class HookExtension(MapperExtension):
""" Extention to add pre-commit hooks.
Hooks will be called in Mapped classes if they define any of these
methods:
* _pre_insert()
* _pre_delete()
* _pre_update()
"""
def before_insert(self, mapper, connection, instance):
if getattr(instance, "_pre_insert", None):
instance._pre_insert()
return EXT_CONTINUE
def before_delete(self, mapper, connection, instance):
if getattr(instance, "_pre_delete", None):
instance._pre_delete()
return EXT_CONTINUE
def before_update(self, mapper, connection, instance):
if getattr(instance, "_pre_update", None):
instance._pre_update()
return EXT_CONTINUE
------------------------------
It works great. Thanks for the pointers.
--
--
Yannick Gingras
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
RSS Feed