Re: [web2py] Re: db events trigger

2011-10-12 Thread Vinicius Assef
Massimo, you got the point: event dispatched to each affected line. :-)

I see it working as conventional RDBMS triggers work as well. Not
more, not less.

--
Vinicius Assef.



On Wed, Oct 12, 2011 at 10:24 AM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 So basically  the events are associated to the table and only apply to
 single record event. This reduces the scope and makes things simple.
 But is this what other people are asking?

 On Oct 12, 12:18 am, guruyaya guruy...@gmail.com wrote:
 On Oct 12, 4:18 am, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:

  As I said, the problem is not the names or when they should be called.
  The problem is. What should be input and the output of each of these
  functions?

 Whenever I'm in a problem with a full stack web framework, I think to
 myself what would cakePHP do?
 OK, that's really NOT the way you should think, but they did some job
 on the input and output of some of these functions (they don't have
 migrates, so the migration events I'd like to see, are not there), and
 we should learn from it:

 afterDelete( ) - cake API allows you delete only one row at the time,
 and it's data is part of the object delete is ran upon (like our
 delete_record() method). Retuens a void, but the object stil contain
 the deleted record.
 afterFind( $results, $primary = false ) -  I'm not sure what primary
 means, but the results, contain a list of all results. Returns a list
 of modified results.
 afterSave( $created ) - The created row. This method runs on create
 and on update. When I worked with it, I really wanted 2 seperate
 functions. returns void.
 beforeDelete( $cascade = true ) - Again, has the data of the deleted
 record. The cascade is like  to web2py recursive deletes. Returns a
 boolean that suggests wether delete should continue.
 beforeFind( $queryData ) = That's a bit more problematic for us.
 cakePHP has an array of all the joins and conditions, that can be used
 in $queryData. I'm not sure web2py has one we can create. But... what
 do I know? returns either boolean or modified query.
 beforeSave( $options ) - I have no idea what the options are, and I'm
 not sure I'm keen on exploring it. Returns true if save should
 continue, false if not.
 beforeValidate( $options ) - same as beforeSave

 beforeFilter and afterFilter - Well... I'm not sure how relevant it is
 for our case. This is where you find user auth logic.
 beforeRender() - This function is called, so you can change some vars
 before a view is presented. This one applies on a paticular controller
 (can be applied to all controllers using inharitance, but that's the
 way cake works, not really relevat to web2py).

 The cake API is not 100% relevant to web2py, but we can use it to get
 some idea how others solved it.


Re: [web2py] Re: db events trigger

2011-10-12 Thread Manuele

On 11/10/2011 22:23, Massimo Di Pierro wrote:

form=SQLFORM(...).process(onsuccess=lambda form:...)
not exactly what I was asking for... I thought about a method of the 
table object run in specific situation, example just before or just 
after a new record is inserted and so on... remind that a record can be 
inserted both though a controller function and even by command line...


Manuele


Re: [web2py] Re: db events trigger

2011-10-12 Thread Bruno Rocha
Do not forget the *before render* and *after render* and workflow events.

this is very useful triggers and are not related to database.

maybe it is more easy to implement in template engine.

http://zerp.ly/rochacbruno
Em 12/10/2011 10:24, Massimo Di Pierro massimo.dipie...@gmail.com
escreveu:

 So basically  the events are associated to the table and only apply to
 single record event. This reduces the scope and makes things simple.
 But is this what other people are asking?

 On Oct 12, 12:18 am, guruyaya guruy...@gmail.com wrote:
  On Oct 12, 4:18 am, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:
 
   As I said, the problem is not the names or when they should be called.
   The problem is. What should be input and the output of each of these
   functions?
 
  Whenever I'm in a problem with a full stack web framework, I think to
  myself what would cakePHP do?
  OK, that's really NOT the way you should think, but they did some job
  on the input and output of some of these functions (they don't have
  migrates, so the migration events I'd like to see, are not there), and
  we should learn from it:
 
  afterDelete( ) - cake API allows you delete only one row at the time,
  and it's data is part of the object delete is ran upon (like our
  delete_record() method). Retuens a void, but the object stil contain
  the deleted record.
  afterFind( $results, $primary = false ) -  I'm not sure what primary
  means, but the results, contain a list of all results. Returns a list
  of modified results.
  afterSave( $created ) - The created row. This method runs on create
  and on update. When I worked with it, I really wanted 2 seperate
  functions. returns void.
  beforeDelete( $cascade = true ) - Again, has the data of the deleted
  record. The cascade is like  to web2py recursive deletes. Returns a
  boolean that suggests wether delete should continue.
  beforeFind( $queryData ) = That's a bit more problematic for us.
  cakePHP has an array of all the joins and conditions, that can be used
  in $queryData. I'm not sure web2py has one we can create. But... what
  do I know? returns either boolean or modified query.
  beforeSave( $options ) - I have no idea what the options are, and I'm
  not sure I'm keen on exploring it. Returns true if save should
  continue, false if not.
  beforeValidate( $options ) - same as beforeSave
 
  beforeFilter and afterFilter - Well... I'm not sure how relevant it is
  for our case. This is where you find user auth logic.
  beforeRender() - This function is called, so you can change some vars
  before a view is presented. This one applies on a paticular controller
  (can be applied to all controllers using inharitance, but that's the
  way cake works, not really relevat to web2py).
 
  The cake API is not 100% relevant to web2py, but we can use it to get
  some idea how others solved it.


Re: [web2py] Re: db events trigger

2011-10-11 Thread Bruno Rocha
Would be nice to have some global events in web2py workflow. I can imagine
some useful hooks:

workflow global events:

onrequest # before the execution of action/model

prerender # after the execution of action/model but before the view
rendering

onrender # after the view render but before the output

onresponse # after all the request process finished.

DAL global events:

preselect - onselect
preinsert - oninsert
preupdate - onupdate
predelete - ondelete

ASPnet has some usefull event system (oninit, onload, pageload etc..)

I dont even know if it is possible to trigger all of them in web2py and how
can it cost. but would be nice to have it.


http://zerp.ly/rochacbruno
Em 11/10/2011 17:23, Massimo Di Pierro massimo.dipie...@gmail.com
escreveu:

 Not yet at the db level but at the form level:


 form=SQLFORM(...).process(onsuccess=lambda form:...)


 On Oct 11, 3:11 am, Manuele manuele.pese...@gmail.com wrote:
  Hi,
  is there a way to trigger some functions on database eventes, for
  example on new record?
 
  thanks a lot
 
   Manuele


Re: [web2py] Re: db events trigger

2011-10-11 Thread Michele Comitini
I like the idea!
+1

It is common in many frameworks. IMHO seems more common on compiled
languages frameworks for some reason.

mic

2011/10/11 Bruno Rocha rochacbr...@gmail.com:
 Would be nice to have some global events in web2py workflow. I can imagine
 some useful hooks:

 workflow global events:

 onrequest # before the execution of action/model

 prerender # after the execution of action/model but before the view
 rendering

 onrender # after the view render but before the output

 onresponse # after all the request process finished.

 DAL global events:

 preselect - onselect
 preinsert - oninsert
 preupdate - onupdate
 predelete - ondelete

 ASPnet has some usefull event system (oninit, onload, pageload etc..)

 I dont even know if it is possible to trigger all of them in web2py and how
 can it cost. but would be nice to have it.


 http://zerp.ly/rochacbruno

 Em 11/10/2011 17:23, Massimo Di Pierro massimo.dipie...@gmail.com
 escreveu:

 Not yet at the db level but at the form level:


 form=SQLFORM(...).process(onsuccess=lambda form:...)


 On Oct 11, 3:11 am, Manuele manuele.pese...@gmail.com wrote:
  Hi,
  is there a way to trigger some functions on database eventes, for
  example on new record?
 
  thanks a lot
 
       Manuele


Re: [web2py] Re: db events trigger

2011-10-11 Thread Bruno Rocha
may be a dictionary of tablename_event:function

I see that in DAL level this is very complicated.

but what about the resquest-response workflow events. I had cases where I
needed some global  function to trigger before/after the template rendering
and final response.

http://zerp.ly/rochacbruno
Em 11/10/2011 19:42, Massimo Di Pierro massimo.dipie...@gmail.com
escreveu:

 the problem with this is not the names. ;-)

 Consider the case of preupdate and onupdate.

   db(db.person.age18).update(can_drink=True)

 What information should be passed to preupdate and update? tablename?
 query? {'can_drink':True}? Number of affected records? Should there be
 one onselect per table? We do not want to call onupdate for every
 table, do we (performance issues)?

 What about?

   db(db.person.id=2).update(can_drink=True)

 What about


 db(db.person).select(left=db.dog.on(db.dog.owner==db.person.id
 ),limitby=(0,1))

 What should we pass to onselect? query? left? limitby? all arguments?
 number of returned records? returned records? In this case we cannot
 pass one table because because more than one table may be involved.

 Every one of those callbacks would need a different signature. It
 would not be obvious and I am not sure people would agree.
 I do not oppose to this. I just want to hear more from you.

 Massimo



 On Oct 11, 4:57 pm, Bruno Rocha rochacbr...@gmail.com wrote:
  Would be nice to have some global events in web2py workflow. I can
 imagine
  some useful hooks:
 
  workflow global events:
 
  onrequest # before the execution of action/model
 
  prerender # after the execution of action/model but before the view
  rendering
 
  onrender # after the view render but before the output
 
  onresponse # after all the request process finished.
 
  DAL global events:
 
  preselect - onselect
  preinsert - oninsert
  preupdate - onupdate
  predelete - ondelete
 
  ASPnet has some usefull event system (oninit, onload, pageload etc..)
 
  I dont even know if it is possible to trigger all of them in web2py and
 how
  can it cost. but would be nice to have it.
 
  http://zerp.ly/rochacbruno
  Em 11/10/2011 17:23, Massimo Di Pierro massimo.dipie...@gmail.com
  escreveu:
 
 
 
 
 
 
 
   Not yet at the db level but at the form level:
 
   form=SQLFORM(...).process(onsuccess=lambda form:...)
 
   On Oct 11, 3:11 am, Manuele manuele.pese...@gmail.com wrote:
Hi,
is there a way to trigger some functions on database eventes, for
example on new record?
 
thanks a lot
 
 Manuele


Re: [web2py] Re: db events trigger

2011-10-11 Thread Vinicius Assef
I suggested it 2 years ago. I'll be happy if it come true someday, in web2py.

I see it as database triggers: before_event  after_event. I.e:
before_insert, after_insert. Event can be: insert, update, delete,
query.

before_insert receives values that will be inserted on database. It
is the last chance to modify, check some value or make run some
routine before register is inserted.
after_insert receives values just stored there.

before_update receives data stored on the database, before the
record is updated. As before_insert, this is a last chance event.
after_update receives data contents after the update took place.

before_delete receives data stored on the database. As
before_update does. Also, it's a last chance event.
after_delete receives same data, but after register was deleted.

before and after query I don't see as important. Web2py already
has virtual and computed fields. But would be nice to log accesses to
some table.

I worked with these triggers on Sybase, many years ago. But I remember
how it was nice to make stored procedures and triggers counting on
these events (except query events. I just saw it on Oracle),
guaranteeing db integrity.

--
Vinicius Assef.



On Tue, Oct 11, 2011 at 7:42 PM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 the problem with this is not the names. ;-)

 Consider the case of preupdate and onupdate.

   db(db.person.age18).update(can_drink=True)

 What information should be passed to preupdate and update? tablename?
 query? {'can_drink':True}? Number of affected records? Should there be
 one onselect per table? We do not want to call onupdate for every
 table, do we (performance issues)?

 What about?

   db(db.person.id=2).update(can_drink=True)

 What about


 db(db.person).select(left=db.dog.on(db.dog.owner==db.person.id),limitby=(0,1))

 What should we pass to onselect? query? left? limitby? all arguments?
 number of returned records? returned records? In this case we cannot
 pass one table because because more than one table may be involved.

 Every one of those callbacks would need a different signature. It
 would not be obvious and I am not sure people would agree.
 I do not oppose to this. I just want to hear more from you.

 Massimo



 On Oct 11, 4:57 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 Would be nice to have some global events in web2py workflow. I can imagine
 some useful hooks:

 workflow global events:

 onrequest # before the execution of action/model

 prerender # after the execution of action/model but before the view
 rendering

 onrender # after the view render but before the output

 onresponse # after all the request process finished.

 DAL global events:

 preselect - onselect
 preinsert - oninsert
 preupdate - onupdate
 predelete - ondelete

 ASPnet has some usefull event system (oninit, onload, pageload etc..)

 I dont even know if it is possible to trigger all of them in web2py and how
 can it cost. but would be nice to have it.

 http://zerp.ly/rochacbruno
 Em 11/10/2011 17:23, Massimo Di Pierro massimo.dipie...@gmail.com
 escreveu:







  Not yet at the db level but at the form level:

  form=SQLFORM(...).process(onsuccess=lambda form:...)

  On Oct 11, 3:11 am, Manuele manuele.pese...@gmail.com wrote:
   Hi,
   is there a way to trigger some functions on database eventes, for
   example on new record?

   thanks a lot

        Manuele