[SQLObject] events module

I'm looking at the events module in the svn code. Looks like some very
useful stuff, but I haven't quite grasped it yet. I'd like to implement
something similar to database triggers (but on the app side) for
capturing record edits with the RowCreateSignal, RowDestroySignal, and
RowUpdateSignal. Will someone give an example of how this might be done?
Thanks.
Randall

Thread view

I'm looking at the events module in the svn code. Looks like some very
useful stuff, but I haven't quite grasped it yet. I'd like to implement
something similar to database triggers (but on the app side) for
capturing record edits with the RowCreateSignal, RowDestroySignal, and
RowUpdateSignal. Will someone give an example of how this might be done?
Thanks.
Randall

Randall Smith wrote:
> I'm looking at the events module in the svn code. Looks like some very
> useful stuff, but I haven't quite grasped it yet. I'd like to implement
> something similar to database triggers (but on the app side) for
> capturing record edits with the RowCreateSignal, RowDestroySignal, and
> RowUpdateSignal. Will someone give an example of how this might be done?
To keep a timestamp updated (untested):
import sqlobject.events
def callback(instance, kwargs):
kwargs.setdefault('updated', datetime.now())
events.listen(callback, SQLObject, events.RowUpdateSignal)
--
Ian Bicking / ianb@... / http://blog.ianbicking.org

Ian Bicking wrote:
> Randall Smith wrote:
>
>> I'm looking at the events module in the svn code. Looks like some
>> very useful stuff, but I haven't quite grasped it yet. I'd like to
>> implement something similar to database triggers (but on the app side)
>> for capturing record edits with the RowCreateSignal, RowDestroySignal,
>> and RowUpdateSignal. Will someone give an example of how this might
>> be done?
>
>
> To keep a timestamp updated (untested):
>
> import sqlobject.events
>
> def callback(instance, kwargs):
> kwargs.setdefault('updated', datetime.now())
>
> events.listen(callback, SQLObject, events.RowUpdateSignal)
>
That's really nice and simple. I just realized this code will not make
it into version 7, so I'll have to find another way to accomplish this
for now, but I look forward to having events in version 8. Thanks for
your hard work Ian. I've enjoyed using SQLObject.
Randall