On Jun 10, 1:06 pm, Hiten <[email protected]> wrote:
> Sorry, I will be more clear.
>
> I'm trying to encapsulate an existing database structure with Sequel:
>   A database of jobs is spread across 16 tables (Q00..Q15) and these
> 16 tables are split amongst 4 hosts (Host1..Host4) with Q00..Q03 on
> Host1, Q04..Q07 on Host2, etc. The primary key in each table is an id
> that is only unique to that table, and there is no way to determine
> which table or host a row is on from the row itself.
>
> So this is what I have:
>
> class Job < Sequel::Model(:Q00)
>   plugin :sharding
>
>   def q(num)
>     # TABLES = { '0' => [:Host1, :Q00] ... }
>     shard, table = TABLES[num.to_s]
>     self.from(table).server(shard)
>   end
>
>   def this
>     super
>     # Not sure
>   end
> end
>
> I know that this should be overridden but am unsure how to move
> forward as I'm a bit in over my head.

You need to figure out where the table was retrieved from, and use
that when updating the object:

class Job < Sequel::Model(:Q00)
  plugin :sharding

  def_dataset_method(:from) do |*s|
    ds = super(*s)
    if rp = row_proc
      ds.row_proc = proc{|r| rp.call(r).set_from(s.first)}
    end
    ds
  end

  def set_from(table)
    @table = table
  end

  def this
    ds = super
    ds.from(@table) if @table
    ds
  end
end

It's basically the same idea as the sharding plugin, but for from
instead of server.  You should probably read the code to the sharding
plugin to get an idea of other things that may be useful.

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.

Reply via email to