Hmm that looks cleaner but gives me an error...
I left out the indexing for simplicity...
v= 123
periods= [:day, :week, :month, :year, :alltime]
DB[:stats].update_sql(periods.inject({}){|h, p| h[p] = p + v})
=> NoMethodError: undefined method `[]=' for
#<Sequel::SQL::NumericExpression:0xb7b289c0>
Whereas..
DB[:stats].update_sql(periods.inject({}){|h, p| h.merge(p => p + v)})
=> "UPDATE \"stats\" SET \"month\" = (\"month\" + 123), \"year\" =
(\"year\" + 123), \"week\" = (\"week\" + 123), \"alltime\" = (\"alltime
\" + 123), \"day\" = (\"day\" + 123)"
seems to work.
On Jun 30, 7:49 am, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> On Jun 29, 2:48 pm, Jim Morris <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yep just discovered that empirically, may be nice to add that to the
> > cheat sheet :)
>
> > Also for the second issue this seems to work too...
>
> > Instead of...
>
> > > ds.update do
> > > periods.each do |p| # create updates for all periods
> > > (p|idx) << (p|idx) + v
> > > end
> > > end
>
> > This may work...
>
> > h= periods.inject({}){ |h, p| h.merge((p|idx) => (p|idx) + v }
> > ds.update_sql(h)
>
> > Does that look ok?
>
> > If they are all equivalent I can update.
>
> No point in a pointless merge:
>
> ds.update_sql(periods.inject({}){|h, p| h[p|idx] = (p|idx) + v})
>
> I'm not sure where the idx variable you are using is defined, though.
>
> Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---