Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Sequel::Model and returning * on update on postgres
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robert Sosinski  
View profile  
 More options Nov 6 2012, 11:07 pm
From: Robert Sosinski <rsosin...@ticketevolution.com>
Date: Tue, 6 Nov 2012 20:07:55 -0800 (PST)
Local: Tues, Nov 6 2012 11:07 pm
Subject: Sequel::Model and returning * on update on postgres

Hi,

I am using Sequel with Postgres.  I notice on inserting new records while
using the `save` method, Sequel::Model uses returning *.  However, it does
not use returning * on update.  Is there a way to make it the default on
updating models too?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Nov 7 2012, 1:15 am
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Tue, 6 Nov 2012 22:15:16 -0800 (PST)
Local: Wed, Nov 7 2012 1:15 am
Subject: Re: Sequel::Model and returning * on update on postgres

On Tuesday, November 6, 2012 8:07:55 PM UTC-8, Robert Sosinski wrote:
> Hi,

> I am using Sequel with Postgres.  I notice on inserting new records while
> using the `save` method, Sequel::Model uses returning *.  However, it does
> not use returning * on update.  Is there a way to make it the default on
> updating models too?

Sequel refreshes the model when creating, but not when updating.  There
isn't a simple way for it to using returning * on updates, but if you need
to refresh after updates, you can call refresh in an after_update hook.
 The only real reason to do that is if you have an update trigger or
something else that changes the values stored in the database, and you want
those new values reflected in the model object.

The main reason for this design is that model refreshing is usually
necessary on creation to get values that weren't set in the INSERT call,
while it is only useful during updates in rare cases.

Note that it should be fairly easy to write a plugin that uses RETURNING *
when updating and sets the retrieved values in the model object, if you
don't want the performance hit of another query to refresh.

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Sosinski  
View profile  
 More options Nov 7 2012, 10:21 am
From: Robert Sosinski <rsosin...@ticketevolution.com>
Date: Wed, 7 Nov 2012 07:21:38 -0800 (PST)
Local: Wed, Nov 7 2012 10:21 am
Subject: Re: Sequel::Model and returning * on update on postgres

Hey Jeremy,

With Sequel and Postgres, I can do the following:

    DB[:people].where(:id => 1).returning('*'.lit).update(:first_name =>
'Alice')

This lets me update the record and get back the row from the database after
triggers.  Would it be possible plug the `returning` method into the save
method when using updates?  If it is more complicated then that, could you
let me know why.

Really appreciate the help.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Nov 7 2012, 11:17 am
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Wed, 7 Nov 2012 08:17:31 -0800 (PST)
Local: Wed, Nov 7 2012 11:17 am
Subject: Re: Sequel::Model and returning * on update on postgres

It's not more complicated than that.  You probably want to override
Model#_update_dataset to do super.returning('*'.lit) and
Model#_update_without_checking to do (s = super; set_values(s.first);
s.length).  That's pretty trivial to do using a plugin (or just adding the
instance methods to Sequel::Model), which is the route I suggest you take
if you don't want to have a separate query to refresh.

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »