On Sunday, March 1, 2015 at 11:33:12 PM UTC-8, Tim Bates wrote:
>
> On Monday, March 2, 2015 at 5:24:12 PM UTC+10:30, Jeremy Evans wrote:
>>
>> I apologize if I seem combative about this. It's just that I have an 
>> accounting and auditing background and the specific example you gave threw 
>> up red flags. :)   It's possible that before_commit could have some useful 
>> applications, though I can't think of a good example off the top of my head.
>>
>
> No problems, I understand the instinct. My specific use case is for Sqlite 
> which does not support deferred constraints (except foreign key 
> constraints) and so I would like to do as much checking in the Model as 
> possible, if only to catch programming errors in testing. You concerns 
> about auditing, while well founded, also don't apply to my specific 
> application. :)
>
> Attached is my first attempt at a before_commit extension, drawing on your 
> suggestions and the implementation of after_commit. I have made it so that 
> before_commit must only be called inside a transaction and will raise an 
> error if it is not, but I could enhance it so that the invoker could choose 
> between this an the run-immediately behaviour of after_commit, although I'm 
> not sure which should be the default. I appreciate your thoughts and 
> feedback.
>

This looks fine.  Note that you shouldn't need to rescue Exception inside 
commit_transaction Sequel should already handle an exception raised in 
commit_transaction by rolling the transaction back.  You can probably get 
away with:

    def commit_transaction(conn, opts=OPTS)
      if (!supports_savepoints? || savepoint_level(conn) == 1) && (ary = 
_trans(conn)[:before_commit])
        ary.each{|b| b.call}
      end
      super
    end

If you want to put this in a gem, please send me a link and I can add it to 
the plugins page on the website.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to